Skip to content

Commit ebaca9c

Browse files
authored
solana: mcm / timelock cu overhead analysis, capacity tests isolation (#683)
* chore: capacity test separation * feat: additional test instructions * chore: mcm/timelock cu overhead analysis * fix: lint * chore: omit variable ix count * chore: clean up * chore: remove unnecessary test cases
1 parent c7a8d6a commit ebaca9c

File tree

10 files changed

+1905
-841
lines changed

10 files changed

+1905
-841
lines changed

chains/solana/contracts/programs/external-program-cpi-stub/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Used to test CPIs made by other programs (with actual business logic).
44
*/
55
use anchor_lang::prelude::*;
6+
use anchor_lang::solana_program::keccak;
67

78
declare_id!("2zZwzyptLqwFJFEFxjPvrdhiGpH9pJ3MfrrmZX6NTKxm");
89

@@ -55,6 +56,28 @@ pub mod external_program_cpi_stub {
5556
);
5657
Ok(())
5758
}
59+
60+
/// no-op instruction that does nothing, also can be used to test maximum account references(remaining_accounts)
61+
pub fn no_op(_ctx: Context<Empty>) -> Result<()> {
62+
Ok(())
63+
}
64+
65+
pub fn compute_heavy(_ctx: Context<Empty>, iterations: u32) -> Result<()> {
66+
let mut hash = [0u8; 32];
67+
68+
// Initialize with some data
69+
hash.iter_mut().enumerate().for_each(|(i, byte)| {
70+
*byte = i as u8;
71+
});
72+
73+
// Perform multiple hash operations
74+
for _ in 0..iterations {
75+
hash = keccak::hash(&hash).to_bytes();
76+
}
77+
78+
// Don't log with msg!() to avoid variable CU consumption
79+
Ok(())
80+
}
5881
}
5982

6083
const VALUE_SEED: &[u8] = b"u8_value";

chains/solana/contracts/target/idl/external_program_cpi_stub.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@
9494
"type": "bytes"
9595
}
9696
]
97+
},
98+
{
99+
"name": "noOp",
100+
"docs": [
101+
"no-op instruction that does nothing, also can be used to test maximum account references(remaining_accounts)"
102+
],
103+
"accounts": [],
104+
"args": []
105+
},
106+
{
107+
"name": "computeHeavy",
108+
"accounts": [],
109+
"args": [
110+
{
111+
"name": "iterations",
112+
"type": "u32"
113+
}
114+
]
97115
}
98116
],
99117
"accounts": [

chains/solana/contracts/target/types/external_program_cpi_stub.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ export type ExternalProgramCpiStub = {
9494
"type": "bytes"
9595
}
9696
]
97+
},
98+
{
99+
"name": "noOp",
100+
"docs": [
101+
"no-op instruction that does nothing, also can be used to test maximum account references(remaining_accounts)"
102+
],
103+
"accounts": [],
104+
"args": []
105+
},
106+
{
107+
"name": "computeHeavy",
108+
"accounts": [],
109+
"args": [
110+
{
111+
"name": "iterations",
112+
"type": "u32"
113+
}
114+
]
97115
}
98116
],
99117
"accounts": [
@@ -208,6 +226,24 @@ export const IDL: ExternalProgramCpiStub = {
208226
"type": "bytes"
209227
}
210228
]
229+
},
230+
{
231+
"name": "noOp",
232+
"docs": [
233+
"no-op instruction that does nothing, also can be used to test maximum account references(remaining_accounts)"
234+
],
235+
"accounts": [],
236+
"args": []
237+
},
238+
{
239+
"name": "computeHeavy",
240+
"accounts": [],
241+
"args": [
242+
{
243+
"name": "iterations",
244+
"type": "u32"
245+
}
246+
]
211247
}
212248
],
213249
"accounts": [

0 commit comments

Comments
 (0)