Skip to content

Commit c4378cf

Browse files
authored
Use 3.0 crates and 2.0 SPL interfaces (#155)
1 parent 1cfdd64 commit c4378cf

File tree

25 files changed

+949
-1421
lines changed

25 files changed

+949
-1421
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ edition = "2021"
2121
version = "0.5.1"
2222

2323
[workspace.dependencies]
24-
agave-feature-set = "2.3"
25-
agave-precompiles = "2.3"
24+
agave-feature-set = "3.0"
25+
agave-precompiles = "3.0"
26+
agave-syscalls = "3.0.0"
2627
bincode = "1.3.3"
2728
bs58 = "0.5.1"
2829
chrono = "0.4.38"
@@ -52,44 +53,46 @@ serde = "1.0.203"
5253
serde_json = "1.0.117"
5354
serde_yaml = "0.9.34"
5455
serial_test = "2.0"
55-
solana-account = "2.2"
56-
solana-account-info = "2.2"
57-
solana-bpf-loader-program = "2.3"
58-
solana-clock = "2.2"
59-
solana-compute-budget = "2.3"
60-
solana-cpi = "2.2"
61-
solana-ed25519-program = "2.2"
62-
solana-epoch-rewards = "2.2"
63-
solana-epoch-schedule = "2.2"
64-
solana-hash = "2.2"
65-
solana-instruction = "2.2"
66-
solana-keccak-hasher = "2.2"
67-
solana-loader-v3-interface = "3.0"
68-
solana-loader-v4-interface = "2.2"
69-
solana-log-collector = "2.3"
70-
solana-logger = "2.3"
71-
solana-native-token = "2.2"
72-
solana-precompile-error = "2.2"
73-
solana-program-entrypoint = "2.2"
74-
solana-program-error = "2.2"
75-
solana-program-runtime = "2.3"
76-
solana-pubkey = "2.2"
77-
solana-rent = "2.2"
78-
solana-sdk-ids = "2.2"
79-
solana-secp256k1-program = "2.2"
80-
solana-secp256r1-program = "2.2"
81-
solana-slot-hashes = "2.2"
82-
solana-stake-interface = "1.0"
83-
solana-stake-program = "2.3"
84-
solana-svm-callback = "2.3"
85-
solana-system-interface = "1.0"
86-
solana-system-program = "2.3"
87-
solana-sysvar = "2.2"
88-
solana-sysvar-id = "2.2"
89-
solana-timings = "2.3"
90-
solana-transaction-context = "2.3"
91-
spl-associated-token-account = "7.0.0"
92-
spl-token = "8.0.0"
56+
solana-account = "3.0"
57+
solana-account-info = "3.0"
58+
solana-bpf-loader-program = "3.0"
59+
solana-clock = "3.0"
60+
solana-compute-budget = "3.0"
61+
solana-cpi = "3.0"
62+
solana-ed25519-program = "3.0"
63+
solana-epoch-rewards = "3.0"
64+
solana-epoch-schedule = "3.0"
65+
solana-hash = "3.0"
66+
solana-instruction = "3.0"
67+
solana-instruction-error = { version = "2.0", features = ["serde"] }
68+
solana-keccak-hasher = { version = "3.0", features = ["sha3"] }
69+
solana-loader-v3-interface = "6.1.0"
70+
solana-loader-v4-interface = "3.1.0"
71+
solana-logger = "3.0"
72+
solana-native-token = "3.0"
73+
solana-precompile-error = "3.0"
74+
solana-program-entrypoint = "3.0"
75+
solana-program-error = "3.0"
76+
solana-program-pack = "3.0"
77+
solana-program-runtime = "3.0"
78+
solana-pubkey = "3.0"
79+
solana-rent = "3.0"
80+
solana-sdk-ids = "3.0"
81+
solana-secp256k1-program = "3.0"
82+
solana-secp256r1-program = "3.0"
83+
solana-slot-hashes = "3.0"
84+
solana-stake-interface = "2.0"
85+
solana-stake-program = "3.0"
86+
solana-svm-callback = "3.0"
87+
solana-svm-log-collector = "3.0"
88+
solana-svm-timings = "3.0"
89+
solana-system-interface = "2.0"
90+
solana-system-program = "3.0"
91+
solana-sysvar = "3.0"
92+
solana-sysvar-id = "3.0"
93+
solana-transaction-context = "3.0"
94+
spl-associated-token-account-interface = "2.0.0"
95+
spl-token-interface = "2.0.0"
9396
thiserror = "1.0.64"
9497
tokio = "1.37.0"
9598
which = "=4.4.0"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := /usr/bin/env bash
22
NIGHTLY_TOOLCHAIN := nightly-2024-11-22
3-
SOLANA_VERSION := 2.3.0
3+
SOLANA_VERSION := 3.0.0
44

55
.PHONY: audit build-test-programs prepublish publish format format-check \
66
clippy test check-features all-checks nightly-version solana-version

fuzz/fixture-fd/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl From<EpochContext> for ProtoEpochContext {
5454
}
5555

5656
/// Instruction context fixture.
57-
#[derive(Clone, Debug, Default, PartialEq)]
57+
#[derive(Clone, Debug, Default)]
5858
pub struct Context {
5959
/// The program ID of the program being invoked.
6060
pub program_id: Pubkey,

fuzz/fixture-fd/src/instr_account.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,16 @@ impl From<ProtoInstrAccount> for InstructionAccount {
1212
is_writable,
1313
is_signer,
1414
} = value;
15-
Self {
16-
index_in_transaction: index as u16,
17-
index_in_caller: index as u16,
18-
index_in_callee: index as u16,
19-
is_signer,
20-
is_writable,
21-
}
15+
Self::new(index as u16, is_signer, is_writable)
2216
}
2317
}
2418

2519
impl From<InstructionAccount> for ProtoInstrAccount {
2620
fn from(value: InstructionAccount) -> Self {
27-
let InstructionAccount {
28-
index_in_transaction,
29-
is_signer,
30-
is_writable,
31-
..
32-
} = value;
3321
Self {
34-
index: index_in_transaction as u32,
35-
is_signer,
36-
is_writable,
22+
index: value.index_in_transaction as u32,
23+
is_signer: value.is_signer(),
24+
is_writable: value.is_writable(),
3725
}
3826
}
3927
}

fuzz/fixture-fd/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use {
2929

3030
/// A fixture for invoking a single instruction against a simulated SVM
3131
/// program runtime environment, for a given program.
32-
#[derive(Clone, Debug, Default, PartialEq)]
32+
#[derive(Clone, Debug, Default)]
3333
pub struct Fixture {
3434
/// The fixture metadata.
3535
pub metadata: Option<Metadata>,
@@ -154,13 +154,7 @@ mod tests {
154154
let instruction_accounts = accounts
155155
.iter()
156156
.enumerate()
157-
.map(|(i, _)| InstructionAccount {
158-
index_in_transaction: i as u16,
159-
index_in_caller: i as u16,
160-
index_in_callee: i as u16,
161-
is_signer: false,
162-
is_writable: true,
163-
})
157+
.map(|(i, _)| InstructionAccount::new(i as u16, false, true))
164158
.collect::<Vec<_>>();
165159
let instruction_data = vec![4; 24];
166160
let slot_context = SlotContext { slot: 42 };

fuzz/fixture/proto/compute_budget.proto

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,36 @@ message ComputeBudget {
1515
uint64 max_call_depth = 10;
1616
uint64 stack_frame_size = 11;
1717
uint64 log_pubkey_units = 12;
18-
uint64 max_cpi_instruction_size = 13;
19-
uint64 cpi_bytes_per_unit = 14;
20-
uint64 sysvar_base_cost = 15;
21-
uint64 secp256k1_recover_cost = 16;
22-
uint64 syscall_base_cost = 17;
23-
uint64 curve25519_edwards_validate_point_cost = 18;
24-
uint64 curve25519_edwards_add_cost = 19;
25-
uint64 curve25519_edwards_subtract_cost = 20;
26-
uint64 curve25519_edwards_multiply_cost = 21;
27-
uint64 curve25519_edwards_msm_base_cost = 22;
28-
uint64 curve25519_edwards_msm_incremental_cost = 23;
29-
uint64 curve25519_ristretto_validate_point_cost = 24;
30-
uint64 curve25519_ristretto_add_cost = 25;
31-
uint64 curve25519_ristretto_subtract_cost = 26;
32-
uint64 curve25519_ristretto_multiply_cost = 27;
33-
uint64 curve25519_ristretto_msm_base_cost = 28;
34-
uint64 curve25519_ristretto_msm_incremental_cost = 29;
35-
uint32 heap_size = 30;
36-
uint64 heap_cost = 31;
37-
uint64 mem_op_base_cost = 32;
38-
uint64 alt_bn128_addition_cost = 33;
39-
uint64 alt_bn128_multiplication_cost = 34;
40-
uint64 alt_bn128_pairing_one_pair_cost_first = 35;
41-
uint64 alt_bn128_pairing_one_pair_cost_other = 36;
42-
uint64 big_modular_exponentiation_base_cost = 37;
43-
uint64 big_modular_exponentiation_cost_divisor = 38;
44-
uint64 poseidon_cost_coefficient_a = 39;
45-
uint64 poseidon_cost_coefficient_c = 40;
46-
uint64 get_remaining_compute_units_cost = 41;
47-
uint64 alt_bn128_g1_compress = 42;
48-
uint64 alt_bn128_g1_decompress = 43;
49-
uint64 alt_bn128_g2_compress = 44;
50-
uint64 alt_bn128_g2_decompress = 45;
18+
uint64 cpi_bytes_per_unit = 13;
19+
uint64 sysvar_base_cost = 14;
20+
uint64 secp256k1_recover_cost = 15;
21+
uint64 syscall_base_cost = 16;
22+
uint64 curve25519_edwards_validate_point_cost = 17;
23+
uint64 curve25519_edwards_add_cost = 18;
24+
uint64 curve25519_edwards_subtract_cost = 19;
25+
uint64 curve25519_edwards_multiply_cost = 20;
26+
uint64 curve25519_edwards_msm_base_cost = 21;
27+
uint64 curve25519_edwards_msm_incremental_cost = 22;
28+
uint64 curve25519_ristretto_validate_point_cost = 23;
29+
uint64 curve25519_ristretto_add_cost = 24;
30+
uint64 curve25519_ristretto_subtract_cost = 25;
31+
uint64 curve25519_ristretto_multiply_cost = 26;
32+
uint64 curve25519_ristretto_msm_base_cost = 27;
33+
uint64 curve25519_ristretto_msm_incremental_cost = 28;
34+
uint32 heap_size = 29;
35+
uint64 heap_cost = 30;
36+
uint64 mem_op_base_cost = 31;
37+
uint64 alt_bn128_addition_cost = 32;
38+
uint64 alt_bn128_multiplication_cost = 33;
39+
uint64 alt_bn128_pairing_one_pair_cost_first = 34;
40+
uint64 alt_bn128_pairing_one_pair_cost_other = 35;
41+
uint64 big_modular_exponentiation_base_cost = 36;
42+
uint64 big_modular_exponentiation_cost_divisor = 37;
43+
uint64 poseidon_cost_coefficient_a = 38;
44+
uint64 poseidon_cost_coefficient_c = 39;
45+
uint64 get_remaining_compute_units_cost = 40;
46+
uint64 alt_bn128_g1_compress = 41;
47+
uint64 alt_bn128_g1_decompress = 42;
48+
uint64 alt_bn128_g2_compress = 43;
49+
uint64 alt_bn128_g2_decompress = 44;
5150
}

fuzz/fixture/src/compute_budget.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ impl From<ProtoComputeBudget> for ComputeBudget {
2020
max_call_depth,
2121
stack_frame_size,
2222
log_pubkey_units,
23-
max_cpi_instruction_size,
2423
cpi_bytes_per_unit,
2524
sysvar_base_cost,
2625
secp256k1_recover_cost,
@@ -68,7 +67,6 @@ impl From<ProtoComputeBudget> for ComputeBudget {
6867
max_call_depth: max_call_depth as usize,
6968
stack_frame_size: stack_frame_size as usize,
7069
log_pubkey_units,
71-
max_cpi_instruction_size: max_cpi_instruction_size as usize,
7270
cpi_bytes_per_unit,
7371
sysvar_base_cost,
7472
secp256k1_recover_cost,
@@ -120,7 +118,6 @@ impl From<ComputeBudget> for ProtoComputeBudget {
120118
max_call_depth,
121119
stack_frame_size,
122120
log_pubkey_units,
123-
max_cpi_instruction_size,
124121
cpi_bytes_per_unit,
125122
sysvar_base_cost,
126123
secp256k1_recover_cost,
@@ -168,7 +165,6 @@ impl From<ComputeBudget> for ProtoComputeBudget {
168165
max_call_depth: max_call_depth as u64,
169166
stack_frame_size: stack_frame_size as u64,
170167
log_pubkey_units,
171-
max_cpi_instruction_size: max_cpi_instruction_size as u64,
172168
cpi_bytes_per_unit,
173169
sysvar_base_cost,
174170
secp256k1_recover_cost,
@@ -218,7 +214,6 @@ pub(crate) fn hash_proto_compute_budget(hasher: &mut Hasher, compute_budget: &Pr
218214
hasher.hash(&compute_budget.max_call_depth.to_le_bytes());
219215
hasher.hash(&compute_budget.stack_frame_size.to_le_bytes());
220216
hasher.hash(&compute_budget.log_pubkey_units.to_le_bytes());
221-
hasher.hash(&compute_budget.max_cpi_instruction_size.to_le_bytes());
222217
hasher.hash(&compute_budget.cpi_bytes_per_unit.to_le_bytes());
223218
hasher.hash(&compute_budget.sysvar_base_cost.to_le_bytes());
224219
hasher.hash(&compute_budget.secp256k1_recover_cost.to_le_bytes());

fuzz/fixture/src/context.rs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use {
1414
};
1515

1616
/// Instruction context fixture.
17-
#[derive(Clone, Debug, Default, PartialEq)]
17+
#[derive(Clone, Debug, PartialEq)]
1818
pub struct Context {
1919
/// The compute budget to use for the simulation.
2020
pub compute_budget: ComputeBudget,
@@ -63,9 +63,18 @@ impl From<ProtoContext> for Context {
6363
)
6464
.collect();
6565

66+
let feature_set: FeatureSet = value.feature_set.map(Into::into).unwrap_or_default();
67+
let simd_0268_active =
68+
feature_set.is_active(&agave_feature_set::raise_cpi_nesting_limit_to_8::id());
69+
70+
let compute_budget = value
71+
.compute_budget
72+
.map(Into::into)
73+
.unwrap_or_else(|| ComputeBudget::new_with_defaults(simd_0268_active));
74+
6675
Self {
67-
compute_budget: value.compute_budget.map(Into::into).unwrap_or_default(),
68-
feature_set: value.feature_set.map(Into::into).unwrap_or_default(),
76+
compute_budget,
77+
feature_set,
6978
sysvars: value.sysvars.map(Into::into).unwrap_or_default(),
7079
program_id,
7180
instruction_accounts,
@@ -133,3 +142,71 @@ pub(crate) fn hash_proto_context(hasher: &mut Hasher, context: &ProtoContext) {
133142
hasher.hash(&context.data);
134143
crate::account::hash_proto_accounts(hasher, &context.accounts);
135144
}
145+
146+
#[cfg(test)]
147+
mod tests {
148+
use {
149+
super::*,
150+
crate::proto::{
151+
ComputeBudget as ProtoComputeBudget, FeatureSet as ProtoFeatureSet,
152+
InstrContext as ProtoContext,
153+
},
154+
};
155+
156+
fn proto_feature_set_with(feature_id: solana_pubkey::Pubkey) -> ProtoFeatureSet {
157+
let discr = u64::from_le_bytes(feature_id.to_bytes()[0..8].try_into().unwrap());
158+
ProtoFeatureSet {
159+
features: vec![discr],
160+
}
161+
}
162+
163+
fn empty_proto_context() -> ProtoContext {
164+
ProtoContext {
165+
compute_budget: None,
166+
feature_set: None,
167+
sysvars: None,
168+
program_id: vec![0u8; 32],
169+
instr_accounts: vec![],
170+
data: vec![],
171+
accounts: vec![],
172+
}
173+
}
174+
175+
#[test]
176+
fn test_defaults_use_feature_flag_when_active() {
177+
let mut proto = empty_proto_context();
178+
proto.feature_set = Some(proto_feature_set_with(
179+
agave_feature_set::raise_cpi_nesting_limit_to_8::id(),
180+
));
181+
182+
let ctx: Context = proto.into();
183+
let expected = ComputeBudget::new_with_defaults(true);
184+
assert_eq!(ctx.compute_budget, expected);
185+
}
186+
187+
#[test]
188+
fn test_defaults_use_feature_flag_when_inactive() {
189+
let proto = empty_proto_context();
190+
let ctx: Context = proto.into();
191+
let expected = ComputeBudget::new_with_defaults(false);
192+
assert_eq!(ctx.compute_budget, expected);
193+
}
194+
195+
#[test]
196+
fn test_present_compute_budget_is_passthrough() {
197+
let mut proto = empty_proto_context();
198+
let cb = ProtoComputeBudget {
199+
compute_unit_limit: 12345,
200+
..Default::default()
201+
};
202+
proto.compute_budget = Some(cb);
203+
204+
// Whether the feature is present or not should not affect passthrough
205+
proto.feature_set = Some(proto_feature_set_with(
206+
agave_feature_set::raise_cpi_nesting_limit_to_8::id(),
207+
));
208+
209+
let ctx: Context = proto.into();
210+
assert_eq!(ctx.compute_budget.compute_unit_limit, 12345);
211+
}
212+
}

0 commit comments

Comments
 (0)