Skip to content

Commit 834e045

Browse files
authored
Fix AnchorVaa struct (#308)
* Deployment address and fix deser bug * Format
1 parent 4cec02d commit 834e045

File tree

7 files changed

+51
-21
lines changed

7 files changed

+51
-21
lines changed

pythnet/remote-executor/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pythnet/remote-executor/programs/remote-executor/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ overflow-checks = true
2020

2121
[dependencies]
2222
anchor-lang = {version = "0.25.0", features = ["init-if-needed"]}
23-
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "gbescos/sdk-solana"}
24-
wormhole-core = { git = "https://github.com/guibescos/wormhole", branch = "gbescos/sdk-solana"}
23+
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
24+
wormhole-core = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
2525
boolinator = "2.4.0"
2626

2727
[dev-dependencies]

pythnet/remote-executor/programs/remote-executor/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pub enum ExecutorError {
88
GovernanceHeaderInvalidModule,
99
GovernanceHeaderInvalidAction,
1010
GovernanceHeaderInvalidReceiverChain,
11+
PostedVaaHeaderWrongMagicNumber,
1112
}

pythnet/remote-executor/programs/remote-executor/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use wormhole::Chain::{
1717
};
1818

1919
mod error;
20-
mod state;
20+
pub mod state;
2121

2222
#[cfg(test)]
2323
mod tests;
2424

2525
//Anchor requires the program to declare its own id
26-
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
26+
declare_id!("exe6S3AxPVNmy46L4Nj6HrnnAVQUhwyYzMSNcnRn3qq");
2727

2828
#[program]
2929
pub mod remote_executor {
@@ -65,14 +65,14 @@ pub mod remote_executor {
6565
}
6666
}
6767

68-
const EXECUTOR_KEY_SEED: &str = "EXECUTOR_KEY";
69-
const CLAIM_RECORD_SEED: &str = "CLAIM_RECORD";
68+
pub const EXECUTOR_KEY_SEED: &str = "EXECUTOR_KEY";
69+
pub const CLAIM_RECORD_SEED: &str = "CLAIM_RECORD";
7070

7171
#[derive(Accounts)]
7272
pub struct ExecutePostedVaa<'info> {
7373
#[account(mut)]
7474
pub payer: Signer<'info>,
75-
#[account(constraint = Chain::from(posted_vaa.emitter_chain) == Solana @ ExecutorError::EmitterChainNotSolana, constraint = posted_vaa.sequence > claim_record.sequence @ExecutorError::NonIncreasingSequence )]
75+
#[account(constraint = Chain::from(posted_vaa.emitter_chain) == Solana @ ExecutorError::EmitterChainNotSolana, constraint = posted_vaa.sequence > claim_record.sequence @ExecutorError::NonIncreasingSequence, constraint = (&posted_vaa.magic == b"vaa" || &posted_vaa.magic == b"msg" || &posted_vaa.magic == b"msu") @ExecutorError::PostedVaaHeaderWrongMagicNumber )]
7676
pub posted_vaa: Account<'info, AnchorVaa>,
7777
/// The reason claim_record has different seeds than executor_key is that executor key might need to pay in the CPI, so we want it to be a native wallet
7878
#[account(init_if_needed, space = 8 + get_packed_len::<ClaimRecord>(), payer=payer, seeds = [CLAIM_RECORD_SEED.as_bytes(), &posted_vaa.emitter_address], bump)]

pythnet/remote-executor/programs/remote-executor/src/state/posted_vaa.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ impl Deref for AnchorVaa {
4949

5050
#[derive(Clone, AnchorDeserialize, AnchorSerialize)]
5151
pub struct AnchorVaa {
52+
pub magic: [u8; 3],
5253
pub vaa: VAA,
5354
}

pythnet/remote-executor/programs/remote-executor/src/tests/executor_simulator.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub enum VaaAttack {
7474
WrongOwner,
7575
WrongData,
7676
WrongEmitterChain,
77+
WrongVaaMagic,
7778
}
7879

7980
impl ExecutorBench {
@@ -154,6 +155,11 @@ impl ExecutorBench {
154155
_ => Chain::Solana.into(),
155156
};
156157

158+
let vaa_magic = match validity {
159+
VaaAttack::WrongVaaMagic => b"xxx",
160+
_ => b"vaa",
161+
};
162+
157163
let owner: Pubkey = match validity {
158164
VaaAttack::WrongOwner => Pubkey::new_unique(),
159165
_ => AnchorVaa::owner(),
@@ -169,17 +175,20 @@ impl ExecutorBench {
169175

170176
let payload_bytes = payload.try_to_vec().unwrap();
171177

172-
let vaa = VAA {
173-
vaa_version: 0,
174-
consistency_level: 0,
175-
vaa_time: 0,
176-
vaa_signature_account: Pubkey::new_unique(),
177-
submission_time: 0,
178-
nonce: 0,
179-
sequence: self.seqno.get(&emitter).unwrap_or(&0) + 1,
180-
emitter_chain,
181-
emitter_address: emitter.to_bytes(),
182-
payload: payload_bytes,
178+
let vaa = AnchorVaa {
179+
magic: *vaa_magic,
180+
vaa: VAA {
181+
vaa_version: 0,
182+
consistency_level: 0,
183+
vaa_time: 0,
184+
vaa_signature_account: Pubkey::new_unique(),
185+
submission_time: 0,
186+
nonce: 0,
187+
sequence: self.seqno.get(&emitter).unwrap_or(&0) + 1,
188+
emitter_chain,
189+
emitter_address: emitter.to_bytes(),
190+
payload: payload_bytes,
191+
},
183192
};
184193

185194
*self.seqno.entry(*emitter).or_insert(0) += 1;
@@ -278,7 +287,7 @@ impl ExecutorSimulator {
278287
signers: &Vec<&Keypair>,
279288
executor_attack: ExecutorAttack,
280289
) -> Result<(), BanksClientError> {
281-
let posted_vaa_data: VAA = self
290+
let posted_vaa_data: AnchorVaa = self
282291
.banks_client
283292
.get_account_data_with_borsh(*posted_vaa_address)
284293
.await

pythnet/remote-executor/programs/remote-executor/src/tests/test_adversarial.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ async fn test_adversarial() {
7373
VaaAttack::WrongEmitterChain,
7474
);
7575

76+
let vaa_account_wrong_vaa_magic = bench.add_vaa_account(
77+
&emitter,
78+
&vec![transfer(
79+
&executor_key,
80+
&&receiver,
81+
Rent::default().minimum_balance(0),
82+
)],
83+
VaaAttack::WrongVaaMagic,
84+
);
85+
7686
// The goal of this account is creating a claim_record that the attacker is going to try to use to impersonate
7787
// the right claim_record
7888
let vaa_account_valid_2 = bench.add_vaa_account(&emitter_2, &vec![], VaaAttack::None);
@@ -115,6 +125,15 @@ async fn test_adversarial() {
115125
ExecutorError::EmitterChainNotSolana.into()
116126
);
117127

128+
// VAA has wrong magic number
129+
assert_eq!(
130+
sim.execute_posted_vaa(&vaa_account_wrong_vaa_magic, &vec![], ExecutorAttack::None)
131+
.await
132+
.unwrap_err()
133+
.unwrap(),
134+
ExecutorError::PostedVaaHeaderWrongMagicNumber.into()
135+
);
136+
118137
// Claim record does not correspond to the emitter's claim record
119138
// Next error is privilege scalation because anchor tries to create the account at wrong address but signing with the right seeds
120139
assert_eq!(

0 commit comments

Comments
 (0)