Skip to content

Commit 82224ae

Browse files
committed
do it
1 parent a9a8e5d commit 82224ae

File tree

9 files changed

+2354
-1097
lines changed

9 files changed

+2354
-1097
lines changed

governance/remote_executor/Cargo.lock

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

governance/remote_executor/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ remote-executor = {path = "../programs/remote-executor/"}
99
solana-program = "1.10.31"
1010
solana-client = "1.10.31"
1111
solana-sdk = "1.10.31"
12-
anchor-client = "0.25.0"
12+
anchor-client = "0.30.1"
1313
shellexpand = "2.1.2"
1414
anyhow = "1.0.65"
1515
base64 = "0.13.0"

governance/remote_executor/cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn get_execute_instruction(
286286
) -> Result<Instruction> {
287287
let anchor_vaa =
288288
AnchorVaa::try_deserialize(&mut rpc_client.get_account_data(posted_vaa_key)?.as_slice())?;
289-
let emitter = Pubkey::new(&anchor_vaa.emitter_address);
289+
let emitter = Pubkey::from(anchor_vaa.emitter_address);
290290

291291
// First accounts from the anchor context
292292
let mut account_metas = ExecutePostedVaa::populate(&ID, payer_pubkey, &emitter, posted_vaa_key)

governance/remote_executor/programs/remote-executor/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ sonic_mainnet = []
3333

3434

3535
[dependencies]
36-
anchor-lang = {version = "0.25.0", features = ["init-if-needed"]}
36+
anchor-lang = {version = "0.30.1", features = ["init-if-needed"]}
3737
wormhole-solana = { git = "https://github.com/guibescos/wormhole-solana", rev="f14b3b54c1e37e1aaf8c2ac2a5e236832ffdb3c2"}
3838
wormhole-sdk = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }
3939
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1"}
4040
boolinator = "2.4.0"
4141

4242
[dev-dependencies]
4343

44-
solana-program-test = "=1.10.31"
44+
solana-program-test = "1.10.31"
4545
tokio = "1.14.1"
46-
solana-sdk = "=1.10.31"
46+
solana-sdk = "1.10.31"
4747
bincode = "1.3.3"
4848
rand = "0.8.5"
49+
borsh = "0.9.3"

governance/remote_executor/programs/remote-executor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::result_large_err)]
44

55
use {
6-
anchor_lang::{prelude::*, solana_program::borsh::get_packed_len, system_program},
6+
anchor_lang::{prelude::*, system_program},
77
error::ExecutorError,
88
state::{claim_record::ClaimRecord, posted_vaa::AnchorVaa},
99
wormhole_sdk::Chain::{self, Solana},
@@ -65,7 +65,7 @@ pub struct ExecutePostedVaa<'info> {
6565
#[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 )]
6666
pub posted_vaa: Account<'info, AnchorVaa>,
6767
/// 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
68-
#[account(init_if_needed, space = 8 + get_packed_len::<ClaimRecord>(), payer=payer, seeds = [CLAIM_RECORD_SEED.as_bytes(), &posted_vaa.emitter_address], bump)]
68+
#[account(init_if_needed, space = 8 + ClaimRecord::LEN, payer=payer, seeds = [CLAIM_RECORD_SEED.as_bytes(), &posted_vaa.emitter_address], bump)]
6969
pub claim_record: Account<'info, ClaimRecord>,
7070
pub system_program: Program<'info, System>,
7171
// Additional accounts passed to the instruction will be passed down to the CPIs. Very importantly executor_key needs to be passed as it will be the signer of the CPIs.

governance/remote_executor/programs/remote-executor/src/state/claim_record.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ use anchor_lang::{
99
pub struct ClaimRecord {
1010
pub sequence: u64,
1111
}
12+
13+
impl ClaimRecord {
14+
pub const LEN: usize = 8;
15+
}

governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ use {
1818
read_file, BanksClient, BanksClientError, ProgramTest, ProgramTestBanksClientExt,
1919
},
2020
solana_sdk::{
21-
account::Account,
22-
bpf_loader_upgradeable,
23-
instruction::{Instruction, InstructionError},
24-
signature::Keypair,
25-
signer::Signer,
26-
stake_history::Epoch,
27-
system_instruction,
28-
transaction::{Transaction, TransactionError},
21+
account::Account, bpf_loader, bpf_loader_upgradeable, instruction::{Instruction, InstructionError}, signature::Keypair, signer::Signer, stake_history::Epoch, system_instruction, transaction::{Transaction, TransactionError}
2922
},
3023
std::{collections::HashMap, path::Path},
3124
wormhole_sdk::Chain,
@@ -62,42 +55,16 @@ impl ExecutorBench {
6255

6356
let mut program_test = ProgramTest::default();
6457
let program_key = crate::id();
65-
let programdata_key = Pubkey::new_unique();
66-
67-
let upgrade_authority_keypair = Keypair::new();
68-
69-
let program_deserialized = UpgradeableLoaderState::Program {
70-
programdata_address: programdata_key,
71-
};
72-
let programdata_deserialized = UpgradeableLoaderState::ProgramData {
73-
slot: 1,
74-
upgrade_authority_address: Some(upgrade_authority_keypair.pubkey()),
75-
};
76-
77-
// Program contains a pointer to progradata
78-
let program_vec = bincode::serialize(&program_deserialized).unwrap();
79-
// Programdata contains a header and the binary of the program
80-
let mut programdata_vec = bincode::serialize(&programdata_deserialized).unwrap();
81-
programdata_vec.append(&mut bpf_data);
8258

8359
let program_account = Account {
84-
lamports: Rent::default().minimum_balance(program_vec.len()),
85-
data: program_vec,
86-
owner: bpf_loader_upgradeable::ID,
60+
lamports: Rent::default().minimum_balance(bpf_data.len()),
61+
data: bpf_data,
62+
owner: bpf_loader::ID,
8763
executable: true,
8864
rent_epoch: Epoch::default(),
8965
};
90-
let programdata_account = Account {
91-
lamports: Rent::default().minimum_balance(programdata_vec.len()),
92-
data: programdata_vec,
93-
owner: bpf_loader_upgradeable::ID,
94-
executable: false,
95-
rent_epoch: Epoch::default(),
96-
};
9766

98-
// Add both accounts to program test, now the program is deployed as upgradable
9967
program_test.add_account(program_key, program_account);
100-
program_test.add_account(programdata_key, programdata_account);
10168

10269
ExecutorBench {
10370
program_test,
@@ -260,16 +227,12 @@ impl ExecutorSimulator {
260227
signers: &Vec<&Keypair>,
261228
executor_attack: ExecutorAttack,
262229
) -> Result<(), BanksClientError> {
263-
let posted_vaa_data: AnchorVaa = self
264-
.banks_client
265-
.get_account_data_with_borsh(*posted_vaa_address)
266-
.await
267-
.unwrap();
230+
let posted_vaa_data: AnchorVaa = AnchorVaa::try_from_slice(&self.banks_client.get_account(*posted_vaa_address).await.unwrap().unwrap().data[..]).unwrap();
268231

269232
let mut account_metas = crate::accounts::ExecutePostedVaa::populate(
270233
&self.program_id,
271234
&self.payer.pubkey(),
272-
&Pubkey::new(&posted_vaa_data.emitter_address),
235+
&Pubkey::from(posted_vaa_data.emitter_address),
273236
posted_vaa_address,
274237
)
275238
.to_account_metas(None);

governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async fn test_adversarial() {
135135
.await
136136
.unwrap_err()
137137
.unwrap(),
138-
InstructionError::PrivilegeEscalation.into_transation_error()
138+
ErrorCode::ConstraintSeeds.into_transation_error()
139139
);
140140

141141
// Claim record does not correspond to the emitter's claim record, but this time it is initialized
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.66.1"
2+
channel = "1.71.1"

0 commit comments

Comments
 (0)