Skip to content

Commit b2a1301

Browse files
committed
one pda per authority
1 parent 326065d commit b2a1301

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

interface/src/instruction.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use {
77
#[repr(u8)]
88
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
99
pub enum NonceInstruction {
10-
/// Creates a nonce account at the PDA derived from a caller-chosen 32-byte `nonce_id`.
11-
///
12-
/// Instruction data: [`InitializeData`].
10+
/// Creates the nonce state PDA for an authority.
1311
///
1412
/// On success, the program:
1513
/// 1. Allocates and assigns the PDA via System program CPI. Caller must pre-fund it with
@@ -48,25 +46,12 @@ pub enum NonceInstruction {
4846
/// flags matching the wrapped message.
4947
Submit,
5048

51-
/// Rotates the authority controlling this nonce account.
52-
///
53-
/// Instruction data: [`SetAuthorityData`].
54-
///
55-
/// Runs only as an inner instruction of a wrapped transaction submitted through `Submit`.
56-
/// Inherits the authorization from the outer `Submit`. A direct outer call cannot succeed,
57-
/// because nothing outside this program can sign for `NonceAuthorityPda`.
58-
///
59-
/// Accounts required:
60-
/// - `[signer]` `NonceAuthorityPda`
61-
/// - `[writable]` `NonceStatePda`
62-
SetAuthority,
63-
6449
/// Closes a nonce account and refunds its lamports.
6550
///
6651
/// Instruction data: [`CloseData`].
6752
///
68-
/// Runs only as an inner instruction of a wrapped transaction submitted through `Submit`
69-
/// for the same reason as `SetAuthority`.
53+
/// Runs only as an inner instruction of a wrapped transaction submitted through `Submit`,
54+
/// because nothing outside this program can sign for `NonceAuthorityPda`.
7055
///
7156
/// Accounts required:
7257
/// - `[signer]` `NonceAuthorityPda`
@@ -106,8 +91,7 @@ impl TryFrom<u8> for NonceInstruction {
10691
match value {
10792
0 => Ok(Self::Initialize),
10893
1 => Ok(Self::Submit),
109-
2 => Ok(Self::SetAuthority),
110-
3 => Ok(Self::Close),
94+
2 => Ok(Self::Close),
11195
_ => Err(()),
11296
}
11397
}
@@ -127,8 +111,7 @@ mod tests {
127111
fn discriminants_match() {
128112
assert_eq!(u8::from(NonceInstruction::Initialize), 0);
129113
assert_eq!(u8::from(NonceInstruction::Submit), 1);
130-
assert_eq!(u8::from(NonceInstruction::SetAuthority), 2);
131-
assert_eq!(u8::from(NonceInstruction::Close), 3);
114+
assert_eq!(u8::from(NonceInstruction::Close), 2);
132115
}
133116

134117
#[test]

interface/src/pda.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
//! PDA derivation helpers for the SPL Nonce program.
22
//!
33
//! A nonce account has two stable identities:
4-
//! - [`NonceStatePda`], derived from an initialization nonce id
4+
//! - [`NonceStatePda`], derived from the authority address
55
//! - [`NonceAuthorityPda`], derived from the nonce state address
66
77
use solana_address::Address;
88

99
/// Nonce state account PDA. Stores the replay-protection nonce and authority.
1010
///
11-
/// Seeds: `["nonce-state", nonce_id, bump]`
11+
/// Seeds: `["nonce-state", authority, bump]`
1212
pub struct NonceStatePda;
1313

1414
impl NonceStatePda {
1515
pub const SEED_PREFIX: &[u8] = b"nonce-state";
1616

1717
#[inline(always)]
18-
pub fn derive_address_and_bump(program_id: &Address, nonce_id: &[u8; 32]) -> (Address, u8) {
19-
Address::derive_program_address(&[Self::SEED_PREFIX, nonce_id], program_id)
20-
.expect("failed to derive NonceStatePda from nonce id")
18+
pub fn derive_address_and_bump(program_id: &Address, authority: &Address) -> (Address, u8) {
19+
Address::derive_program_address(&[Self::SEED_PREFIX, authority.as_ref()], program_id)
20+
.expect("failed to derive NonceStatePda from authority")
2121
}
2222

2323
#[inline(always)]
24-
pub fn derive_address(program_id: &Address, nonce_id: &[u8; 32]) -> Address {
25-
let (address, _bump) = Self::derive_address_and_bump(program_id, nonce_id);
24+
pub fn derive_address(program_id: &Address, authority: &Address) -> Address {
25+
let (address, _bump) = Self::derive_address_and_bump(program_id, authority);
2626
address
2727
}
2828
}

0 commit comments

Comments
 (0)