diff --git a/Cargo.lock b/Cargo.lock index 053c307c..f598f974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7833,6 +7833,7 @@ version = "0.1.0" dependencies = [ "nssa_core", "risc0-zkvm", + "serde", ] [[package]] diff --git a/artifacts/program_methods/amm.bin b/artifacts/program_methods/amm.bin index 46b80717..c2e956d1 100644 Binary files a/artifacts/program_methods/amm.bin and b/artifacts/program_methods/amm.bin differ diff --git a/artifacts/program_methods/associated_token_account.bin b/artifacts/program_methods/associated_token_account.bin index 7c21c460..1277d701 100644 Binary files a/artifacts/program_methods/associated_token_account.bin and b/artifacts/program_methods/associated_token_account.bin differ diff --git a/artifacts/program_methods/authenticated_transfer.bin b/artifacts/program_methods/authenticated_transfer.bin index 203b62a8..14a365cd 100644 Binary files a/artifacts/program_methods/authenticated_transfer.bin and b/artifacts/program_methods/authenticated_transfer.bin differ diff --git a/artifacts/program_methods/pinata.bin b/artifacts/program_methods/pinata.bin index 27a2c0a8..9ec91b35 100644 Binary files a/artifacts/program_methods/pinata.bin and b/artifacts/program_methods/pinata.bin differ diff --git a/artifacts/program_methods/pinata_token.bin b/artifacts/program_methods/pinata_token.bin index af3b566d..98011290 100644 Binary files a/artifacts/program_methods/pinata_token.bin and b/artifacts/program_methods/pinata_token.bin differ diff --git a/artifacts/program_methods/privacy_preserving_circuit.bin b/artifacts/program_methods/privacy_preserving_circuit.bin index 16f7a2af..a01ce602 100644 Binary files a/artifacts/program_methods/privacy_preserving_circuit.bin and b/artifacts/program_methods/privacy_preserving_circuit.bin differ diff --git a/artifacts/program_methods/token.bin b/artifacts/program_methods/token.bin index 328e2518..bdca116f 100644 Binary files a/artifacts/program_methods/token.bin and b/artifacts/program_methods/token.bin differ diff --git a/artifacts/test_program_methods/chain_caller.bin b/artifacts/test_program_methods/chain_caller.bin index 8663b489..010de5f7 100644 Binary files a/artifacts/test_program_methods/chain_caller.bin and b/artifacts/test_program_methods/chain_caller.bin differ diff --git a/artifacts/test_program_methods/changer_claimer.bin b/artifacts/test_program_methods/changer_claimer.bin index 88ae617e..676569a3 100644 Binary files a/artifacts/test_program_methods/changer_claimer.bin and b/artifacts/test_program_methods/changer_claimer.bin differ diff --git a/artifacts/test_program_methods/data_changer.bin b/artifacts/test_program_methods/data_changer.bin index ecb54968..9a55228b 100644 Binary files a/artifacts/test_program_methods/data_changer.bin and b/artifacts/test_program_methods/data_changer.bin differ diff --git a/artifacts/test_program_methods/extra_output.bin b/artifacts/test_program_methods/extra_output.bin index 948253c3..56511798 100644 Binary files a/artifacts/test_program_methods/extra_output.bin and b/artifacts/test_program_methods/extra_output.bin differ diff --git a/artifacts/test_program_methods/flash_swap_callback.bin b/artifacts/test_program_methods/flash_swap_callback.bin index d0ec99ba..ebae1c82 100644 Binary files a/artifacts/test_program_methods/flash_swap_callback.bin and b/artifacts/test_program_methods/flash_swap_callback.bin differ diff --git a/artifacts/test_program_methods/flash_swap_initiator.bin b/artifacts/test_program_methods/flash_swap_initiator.bin index 7b572906..ed2abdba 100644 Binary files a/artifacts/test_program_methods/flash_swap_initiator.bin and b/artifacts/test_program_methods/flash_swap_initiator.bin differ diff --git a/artifacts/test_program_methods/malicious_authorization_changer.bin b/artifacts/test_program_methods/malicious_authorization_changer.bin index c91252b9..6b9bfc63 100644 Binary files a/artifacts/test_program_methods/malicious_authorization_changer.bin and b/artifacts/test_program_methods/malicious_authorization_changer.bin differ diff --git a/artifacts/test_program_methods/minter.bin b/artifacts/test_program_methods/minter.bin index c96d6ebf..2b4871bb 100644 Binary files a/artifacts/test_program_methods/minter.bin and b/artifacts/test_program_methods/minter.bin differ diff --git a/artifacts/test_program_methods/modified_transfer.bin b/artifacts/test_program_methods/modified_transfer.bin index 2dc3fb35..11c061d9 100644 Binary files a/artifacts/test_program_methods/modified_transfer.bin and b/artifacts/test_program_methods/modified_transfer.bin differ diff --git a/artifacts/test_program_methods/noop.bin b/artifacts/test_program_methods/noop.bin index 4e891008..692b1f9b 100644 Binary files a/artifacts/test_program_methods/noop.bin and b/artifacts/test_program_methods/noop.bin differ diff --git a/artifacts/test_program_methods/simple_balance_transfer.bin b/artifacts/test_program_methods/simple_balance_transfer.bin index c3fdfe42..c3a5fb32 100644 Binary files a/artifacts/test_program_methods/simple_balance_transfer.bin and b/artifacts/test_program_methods/simple_balance_transfer.bin differ diff --git a/artifacts/test_program_methods/validity_window.bin b/artifacts/test_program_methods/validity_window.bin index 4009fc4e..8c739c96 100644 Binary files a/artifacts/test_program_methods/validity_window.bin and b/artifacts/test_program_methods/validity_window.bin differ diff --git a/artifacts/test_program_methods/validity_window_chain_caller.bin b/artifacts/test_program_methods/validity_window_chain_caller.bin index 1f42c3c0..ed20bfa6 100644 Binary files a/artifacts/test_program_methods/validity_window_chain_caller.bin and b/artifacts/test_program_methods/validity_window_chain_caller.bin differ diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world.rs b/examples/program_deployment/methods/guest/src/bin/hello_world.rs index 9392128f..caae793d 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world.rs @@ -18,7 +18,9 @@ type Instruction = Vec; fn main() { // Read inputs let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: greeting, }, @@ -50,5 +52,11 @@ fn main() { // with the NSSA program rules. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write(); + ProgramOutput::new( + self_program_id, + instruction_data, + vec![pre_state], + vec![post_state], + ) + .write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs b/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs index 0e1237d8..25825bf5 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs @@ -18,7 +18,9 @@ type Instruction = Vec; fn main() { // Read inputs let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: greeting, }, @@ -57,5 +59,11 @@ fn main() { // with the NSSA program rules. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write(); + ProgramOutput::new( + self_program_id, + instruction_data, + vec![pre_state], + vec![post_state], + ) + .write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs b/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs index 7a01f10b..2adc1ebe 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs @@ -65,7 +65,9 @@ fn move_data(from_pre: AccountWithMetadata, to_pre: AccountWithMetadata) -> Vec< fn main() { // Read input accounts. let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (function_id, data), }, diff --git a/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs b/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs index 09acfae2..6e8ead22 100644 --- a/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs +++ b/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs @@ -26,7 +26,9 @@ fn hello_world_program_id() -> ProgramId { fn main() { // Read inputs let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (), }, @@ -55,7 +57,12 @@ fn main() { // Write the outputs. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]) - .with_chained_calls(vec![chained_call]) - .write(); + ProgramOutput::new( + self_program_id, + instruction_data, + vec![pre_state], + vec![post_state], + ) + .with_chained_calls(vec![chained_call]) + .write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs b/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs index f5d62bc6..85023ffd 100644 --- a/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs +++ b/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs @@ -32,7 +32,9 @@ fn hello_world_program_id() -> ProgramId { fn main() { // Read inputs let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (), }, @@ -68,7 +70,12 @@ fn main() { // Write the outputs. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]) - .with_chained_calls(vec![chained_call]) - .write(); + ProgramOutput::new( + self_program_id, + instruction_data, + vec![pre_state], + vec![post_state], + ) + .with_chained_calls(vec![chained_call]) + .write(); } diff --git a/nssa/src/privacy_preserving_transaction/circuit.rs b/nssa/src/privacy_preserving_transaction/circuit.rs index 3ac5d20e..6c174450 100644 --- a/nssa/src/privacy_preserving_transaction/circuit.rs +++ b/nssa/src/privacy_preserving_transaction/circuit.rs @@ -160,7 +160,13 @@ fn execute_and_prove_program( ) -> Result { // Write inputs to the program let mut env_builder = ExecutorEnv::builder(); - Program::write_inputs(program.id(), caller_program_id, pre_states, instruction_data, &mut env_builder)?; + Program::write_inputs( + program.id(), + caller_program_id, + pre_states, + instruction_data, + &mut env_builder, + )?; let env = env_builder.build().unwrap(); // Prove the program diff --git a/nssa/src/program.rs b/nssa/src/program.rs index 5aa8c483..46740d8f 100644 --- a/nssa/src/program.rs +++ b/nssa/src/program.rs @@ -59,7 +59,13 @@ impl Program { // Write inputs to the program let mut env_builder = ExecutorEnv::builder(); env_builder.session_limit(Some(MAX_NUM_CYCLES_PUBLIC_EXECUTION)); - Self::write_inputs(self.id, caller_program_id, pre_states, instruction_data, &mut env_builder)?; + Self::write_inputs( + self.id, + caller_program_id, + pre_states, + instruction_data, + &mut env_builder, + )?; let env = env_builder.build().unwrap(); // Execute the program (without proving) diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index ad33b2cd..23222a55 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -147,8 +147,11 @@ impl PublicTransaction { "Program {:?} pre_states: {:?}, instruction_data: {:?}", chained_call.program_id, chained_call.pre_states, chained_call.instruction_data ); - let mut program_output = - program.execute(caller_program_id, &chained_call.pre_states, &chained_call.instruction_data)?; + let mut program_output = program.execute( + caller_program_id, + &chained_call.pre_states, + &chained_call.instruction_data, + )?; debug!( "Program {:?} output: {:?}", chained_call.program_id, program_output diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 85d0a053..fdc2e873 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -3523,7 +3523,7 @@ pub mod tests { let message = public_transaction::Message::try_new( initiator.id(), vec![vault_id, receiver_id], - vec![], // no signers — vault is PDA-authorised + vec![], // no signers — vault is PDA-authorised instruction, ) .unwrap(); @@ -3561,18 +3561,33 @@ pub mod tests { // Pre-simulated intermediate states: // After transfer (vault→receiver, amount_out): let vault_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance - amount_out, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance - amount_out, + ..Account::default() + }, + false, + vault_id, ); let receiver_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: amount_out, ..Account::default() }, - false, receiver_id, + Account { + program_owner: token.id(), + balance: amount_out, + ..Account::default() + }, + false, + receiver_id, ); // After callback returns funds (receiver→vault, amount_out): let vault_after_callback = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance, + ..Account::default() + }, + false, + vault_id, ); // Callback instruction: return funds @@ -3581,12 +3596,22 @@ pub mod tests { token_program_id: token.id(), amount: amount_out, vault_after_return: Some(AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance, + ..Account::default() + }, + false, + vault_id, )), receiver_after_return: Some(AccountWithMetadata::new( - Account { program_owner: token.id(), balance: 0, ..Account::default() }, - false, receiver_id, + Account { + program_owner: token.id(), + balance: 0, + ..Account::default() + }, + false, + receiver_id, )), }; let cb_data = Program::serialize_instruction(cb_instruction).unwrap(); @@ -3639,18 +3664,33 @@ pub mod tests { // Pre-simulated intermediate states (same as successful case for steps 1-2): let vault_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance - amount_out, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance - amount_out, + ..Account::default() + }, + false, + vault_id, ); let receiver_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: amount_out, ..Account::default() }, - false, receiver_id, + Account { + program_owner: token.id(), + balance: amount_out, + ..Account::default() + }, + false, + receiver_id, ); // After callback that does NOT return funds — vault stays drained: let vault_after_callback = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance - amount_out, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance - amount_out, + ..Account::default() + }, + false, + vault_id, ); // Callback instruction: do NOT return funds @@ -3677,7 +3717,10 @@ pub mod tests { let result = state.transition_from_public_transaction(&tx, 1, 0); // Invariant check fails → entire tx rolls back - assert!(result.is_err(), "flash swap should fail when callback keeps funds"); + assert!( + result.is_err(), + "flash swap should fail when callback keeps funds" + ); // State unchanged (rollback) assert_eq!(state.get_account_by_id(vault_id).balance, initial_balance); @@ -3714,17 +3757,32 @@ pub mod tests { // Zero-amount transfer: states remain unchanged after transfer let vault_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance, + ..Account::default() + }, + false, + vault_id, ); let receiver_after_transfer = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: 0, ..Account::default() }, - false, receiver_id, + Account { + program_owner: token.id(), + balance: 0, + ..Account::default() + }, + false, + receiver_id, ); // Callback with zero amount, return_funds=true (no-op effectively) let vault_after_callback = AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance, + ..Account::default() + }, + false, + vault_id, ); let cb_instruction = CallbackInstruction { @@ -3732,12 +3790,22 @@ pub mod tests { token_program_id: token.id(), amount: 0, vault_after_return: Some(AccountWithMetadata::new( - Account { program_owner: token.id(), balance: initial_balance, ..Account::default() }, - false, vault_id, + Account { + program_owner: token.id(), + balance: initial_balance, + ..Account::default() + }, + false, + vault_id, )), receiver_after_return: Some(AccountWithMetadata::new( - Account { program_owner: token.id(), balance: 0, ..Account::default() }, - false, receiver_id, + Account { + program_owner: token.id(), + balance: 0, + ..Account::default() + }, + false, + receiver_id, )), }; let cb_data = Program::serialize_instruction(cb_instruction).unwrap(); @@ -3754,7 +3822,10 @@ pub mod tests { let tx = build_flash_swap_tx(&initiator, vault_id, receiver_id, instruction); let result = state.transition_from_public_transaction(&tx, 1, 0); - assert!(result.is_ok(), "zero-amount flash swap should succeed: {result:?}"); + assert!( + result.is_ok(), + "zero-amount flash swap should succeed: {result:?}" + ); } #[test] diff --git a/program_methods/guest/src/bin/amm.rs b/program_methods/guest/src/bin/amm.rs index 292efb67..90f7e06f 100644 --- a/program_methods/guest/src/bin/amm.rs +++ b/program_methods/guest/src/bin/amm.rs @@ -13,7 +13,9 @@ use nssa_core::program::{ProgramInput, ProgramOutput, read_nssa_inputs}; fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction, }, @@ -152,7 +154,12 @@ fn main() { } }; - ProgramOutput::new(self_program_id, instruction_words, pre_states_clone, post_states) - .with_chained_calls(chained_calls) - .write(); + ProgramOutput::new( + self_program_id, + instruction_words, + pre_states_clone, + post_states, + ) + .with_chained_calls(chained_calls) + .write(); } diff --git a/program_methods/guest/src/bin/associated_token_account.rs b/program_methods/guest/src/bin/associated_token_account.rs index 6b22107a..2dd074d9 100644 --- a/program_methods/guest/src/bin/associated_token_account.rs +++ b/program_methods/guest/src/bin/associated_token_account.rs @@ -3,7 +3,9 @@ use nssa_core::program::{ProgramInput, ProgramOutput, read_nssa_inputs}; fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction, }, @@ -56,7 +58,12 @@ fn main() { } }; - ProgramOutput::new(self_program_id, instruction_words, pre_states_clone, post_states) - .with_chained_calls(chained_calls) - .write(); + ProgramOutput::new( + self_program_id, + instruction_words, + pre_states_clone, + post_states, + ) + .with_chained_calls(chained_calls) + .write(); } diff --git a/program_methods/guest/src/bin/authenticated_transfer.rs b/program_methods/guest/src/bin/authenticated_transfer.rs index 6a3cdd51..302c1620 100644 --- a/program_methods/guest/src/bin/authenticated_transfer.rs +++ b/program_methods/guest/src/bin/authenticated_transfer.rs @@ -66,7 +66,9 @@ fn transfer( fn main() { // Read input accounts. let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: balance_to_move, }, diff --git a/program_methods/guest/src/bin/pinata.rs b/program_methods/guest/src/bin/pinata.rs index 3cbfe1cb..1c1e2e94 100644 --- a/program_methods/guest/src/bin/pinata.rs +++ b/program_methods/guest/src/bin/pinata.rs @@ -45,7 +45,9 @@ fn main() { // Read input accounts. // It is expected to receive only two accounts: [pinata_account, winner_account] let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: solution, }, diff --git a/program_methods/guest/src/bin/pinata_token.rs b/program_methods/guest/src/bin/pinata_token.rs index 2b90735c..2e09489c 100644 --- a/program_methods/guest/src/bin/pinata_token.rs +++ b/program_methods/guest/src/bin/pinata_token.rs @@ -51,7 +51,9 @@ fn main() { // It is expected to receive three accounts: [pinata_definition, pinata_token_holding, // winner_token_holding] let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: solution, }, diff --git a/program_methods/guest/src/bin/token.rs b/program_methods/guest/src/bin/token.rs index c62088a4..c3500da6 100644 --- a/program_methods/guest/src/bin/token.rs +++ b/program_methods/guest/src/bin/token.rs @@ -11,7 +11,9 @@ use token_program::core::Instruction; fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction, }, @@ -81,5 +83,11 @@ fn main() { } }; - ProgramOutput::new(self_program_id, instruction_words, pre_states_clone, post_states).write(); + ProgramOutput::new( + self_program_id, + instruction_words, + pre_states_clone, + post_states, + ) + .write(); } diff --git a/test_program_methods/guest/src/bin/burner.rs b/test_program_methods/guest/src/bin/burner.rs index 5c58859a..50d8e0f6 100644 --- a/test_program_methods/guest/src/bin/burner.rs +++ b/test_program_methods/guest/src/bin/burner.rs @@ -4,7 +4,9 @@ type Instruction = u128; fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: balance_to_burn, }, diff --git a/test_program_methods/guest/src/bin/chain_caller.rs b/test_program_methods/guest/src/bin/chain_caller.rs index 3c49ef69..64fb2760 100644 --- a/test_program_methods/guest/src/bin/chain_caller.rs +++ b/test_program_methods/guest/src/bin/chain_caller.rs @@ -12,7 +12,9 @@ type Instruction = (u128, ProgramId, u32, Option); /// program. fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (balance, auth_transfer_id, num_chain_calls, pda_seed), }, diff --git a/test_program_methods/guest/src/bin/changer_claimer.rs b/test_program_methods/guest/src/bin/changer_claimer.rs index 6e10b36b..ea42ff7c 100644 --- a/test_program_methods/guest/src/bin/changer_claimer.rs +++ b/test_program_methods/guest/src/bin/changer_claimer.rs @@ -5,7 +5,9 @@ type Instruction = (Option>, bool); /// A program that optionally modifies the account data and optionally claims it. fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (data_opt, should_claim), }, @@ -33,5 +35,11 @@ fn main() { AccountPostState::new(account_post) }; - ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![post_state]).write(); + ProgramOutput::new( + self_program_id, + instruction_words, + vec![pre], + vec![post_state], + ) + .write(); } diff --git a/test_program_methods/guest/src/bin/claimer.rs b/test_program_methods/guest/src/bin/claimer.rs index b0e0602f..a0e1f9e8 100644 --- a/test_program_methods/guest/src/bin/claimer.rs +++ b/test_program_methods/guest/src/bin/claimer.rs @@ -4,7 +4,9 @@ type Instruction = (); fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (), }, @@ -17,5 +19,11 @@ fn main() { let account_post = AccountPostState::new_claimed(pre.account.clone(), Claim::Authorized); - ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![account_post]).write(); + ProgramOutput::new( + self_program_id, + instruction_words, + vec![pre], + vec![account_post], + ) + .write(); } diff --git a/test_program_methods/guest/src/bin/data_changer.rs b/test_program_methods/guest/src/bin/data_changer.rs index 4ff214be..760db001 100644 --- a/test_program_methods/guest/src/bin/data_changer.rs +++ b/test_program_methods/guest/src/bin/data_changer.rs @@ -5,7 +5,9 @@ type Instruction = Vec; /// A program that modifies the account data by setting bytes sent in instruction. fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: data, }, diff --git a/test_program_methods/guest/src/bin/extra_output.rs b/test_program_methods/guest/src/bin/extra_output.rs index 86ddb85d..9b3ece3b 100644 --- a/test_program_methods/guest/src/bin/extra_output.rs +++ b/test_program_methods/guest/src/bin/extra_output.rs @@ -6,7 +6,15 @@ use nssa_core::{ type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; diff --git a/test_program_methods/guest/src/bin/flash_swap_callback.rs b/test_program_methods/guest/src/bin/flash_swap_callback.rs index 0a61165d..3ecd0445 100644 --- a/test_program_methods/guest/src/bin/flash_swap_callback.rs +++ b/test_program_methods/guest/src/bin/flash_swap_callback.rs @@ -10,12 +10,12 @@ //! In a real flash swap, this would contain the user's arbitrage or other logic. //! In this test program, it is controlled by `return_funds`: //! -//! - `return_funds = true`: emits a token transfer (receiver → vault) to return the funds. -//! The invariant check will pass and the transaction will succeed. +//! - `return_funds = true`: emits a token transfer (receiver → vault) to return the funds. The +//! invariant check will pass and the transaction will succeed. //! -//! - `return_funds = false`: emits no transfers. Funds stay with the receiver. -//! The invariant check will fail (vault balance < initial), causing full atomic rollback. -//! This simulates a malicious or buggy callback that does not repay the flash loan. +//! - `return_funds = false`: emits no transfers. Funds stay with the receiver. The invariant check +//! will fail (vault balance < initial), causing full atomic rollback. This simulates a malicious +//! or buggy callback that does not repay the flash loan. //! //! # Note on caller_program_id //! diff --git a/test_program_methods/guest/src/bin/flash_swap_initiator.rs b/test_program_methods/guest/src/bin/flash_swap_initiator.rs index f90d3759..0cf067ec 100644 --- a/test_program_methods/guest/src/bin/flash_swap_initiator.rs +++ b/test_program_methods/guest/src/bin/flash_swap_initiator.rs @@ -16,18 +16,18 @@ //! 2. User callback (arbitrary logic, e.g. arbitrage) //! 3. Self-call to `InvariantCheck` (using `self_program_id` to reference itself) //! -//! - `InvariantCheck` (internal): enforces that the vault balance was restored after -//! the callback. Uses `caller_program_id == Some(self_program_id)` to prevent standalone -//! calls (this is the visibility enforcement mechanism). +//! - `InvariantCheck` (internal): enforces that the vault balance was restored after the callback. +//! Uses `caller_program_id == Some(self_program_id)` to prevent standalone calls (this is the +//! visibility enforcement mechanism). //! //! # What this demonstrates //! //! - `self_program_id`: enables a program to chain back to itself (step 3 above) //! - `caller_program_id`: enables a program to restrict which callers can invoke an instruction -//! - Pre-simulated intermediate states: the initiator must compute expected intermediate -//! account states and embed them in the instruction. The node validates them deterministically. -//! - Atomic rollback: if the callback doesn't return funds, the invariant check fails, -//! and all state changes from steps 1 and 2 are rolled back automatically. +//! - Pre-simulated intermediate states: the initiator must compute expected intermediate account +//! states and embed them in the instruction. The node validates them deterministically. +//! - Atomic rollback: if the callback doesn't return funds, the invariant check fails, and all +//! state changes from steps 1 and 2 are rolled back automatically. //! //! # Tests //! @@ -132,8 +132,9 @@ fn main() { // Chained call 3: Self-call to enforce the invariant. // Uses `self_program_id` to reference this program, the key feature that enables // the "prep → callback → assert" pattern without a separate checker program. - // If the callback did not return funds, vault_after_callback.balance < min_vault_balance - // and this call will panic, rolling back the entire transaction. + // If the callback did not return funds, vault_after_callback.balance < + // min_vault_balance and this call will panic, rolling back the entire + // transaction. let invariant_instruction = risc0_zkvm::serde::to_vec(&FlashSwapInstruction::InvariantCheck { min_vault_balance, diff --git a/test_program_methods/guest/src/bin/malicious_authorization_changer.rs b/test_program_methods/guest/src/bin/malicious_authorization_changer.rs index ca80043a..cfa2845c 100644 --- a/test_program_methods/guest/src/bin/malicious_authorization_changer.rs +++ b/test_program_methods/guest/src/bin/malicious_authorization_changer.rs @@ -13,7 +13,9 @@ type Instruction = (u128, ProgramId); /// but sets the `is_authorized` field of the first account to true. fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (balance, transfer_program_id), }, diff --git a/test_program_methods/guest/src/bin/minter.rs b/test_program_methods/guest/src/bin/minter.rs index 81960fd2..fd36c890 100644 --- a/test_program_methods/guest/src/bin/minter.rs +++ b/test_program_methods/guest/src/bin/minter.rs @@ -3,7 +3,15 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; diff --git a/test_program_methods/guest/src/bin/missing_output.rs b/test_program_methods/guest/src/bin/missing_output.rs index e5a38eb7..a454a59e 100644 --- a/test_program_methods/guest/src/bin/missing_output.rs +++ b/test_program_methods/guest/src/bin/missing_output.rs @@ -3,7 +3,15 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let Ok([pre1, pre2]) = <[_; 2]>::try_from(pre_states) else { return; diff --git a/test_program_methods/guest/src/bin/modified_transfer.rs b/test_program_methods/guest/src/bin/modified_transfer.rs index 7344d125..bbc0a6f3 100644 --- a/test_program_methods/guest/src/bin/modified_transfer.rs +++ b/test_program_methods/guest/src/bin/modified_transfer.rs @@ -63,7 +63,9 @@ fn transfer( fn main() { // Read input accounts. let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: balance_to_move, }, diff --git a/test_program_methods/guest/src/bin/nonce_changer.rs b/test_program_methods/guest/src/bin/nonce_changer.rs index 634b653e..d76a3812 100644 --- a/test_program_methods/guest/src/bin/nonce_changer.rs +++ b/test_program_methods/guest/src/bin/nonce_changer.rs @@ -3,7 +3,15 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; diff --git a/test_program_methods/guest/src/bin/noop.rs b/test_program_methods/guest/src/bin/noop.rs index 0179543d..777c7923 100644 --- a/test_program_methods/guest/src/bin/noop.rs +++ b/test_program_methods/guest/src/bin/noop.rs @@ -3,7 +3,15 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let post_states = pre_states .iter() diff --git a/test_program_methods/guest/src/bin/program_owner_changer.rs b/test_program_methods/guest/src/bin/program_owner_changer.rs index 7353a8f1..3cd5dead 100644 --- a/test_program_methods/guest/src/bin/program_owner_changer.rs +++ b/test_program_methods/guest/src/bin/program_owner_changer.rs @@ -3,7 +3,15 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { self_program_id, caller_program_id: _, pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let ( + ProgramInput { + self_program_id, + caller_program_id: _, + pre_states, + .. + }, + instruction_words, + ) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; diff --git a/test_program_methods/guest/src/bin/simple_balance_transfer.rs b/test_program_methods/guest/src/bin/simple_balance_transfer.rs index 98feb53b..0fea0d3f 100644 --- a/test_program_methods/guest/src/bin/simple_balance_transfer.rs +++ b/test_program_methods/guest/src/bin/simple_balance_transfer.rs @@ -4,7 +4,9 @@ type Instruction = u128; fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: balance, }, diff --git a/test_program_methods/guest/src/bin/validity_window.rs b/test_program_methods/guest/src/bin/validity_window.rs index 746eb041..8ff586b8 100644 --- a/test_program_methods/guest/src/bin/validity_window.rs +++ b/test_program_methods/guest/src/bin/validity_window.rs @@ -7,7 +7,9 @@ type Instruction = (BlockValidityWindow, TimestampValidityWindow); fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (block_validity_window, timestamp_validity_window), }, diff --git a/test_program_methods/guest/src/bin/validity_window_chain_caller.rs b/test_program_methods/guest/src/bin/validity_window_chain_caller.rs index dc04a071..97f22f61 100644 --- a/test_program_methods/guest/src/bin/validity_window_chain_caller.rs +++ b/test_program_methods/guest/src/bin/validity_window_chain_caller.rs @@ -15,7 +15,9 @@ type Instruction = (BlockValidityWindow, ProgramId, BlockValidityWindow); fn main() { let ( - ProgramInput { self_program_id, caller_program_id: _, + ProgramInput { + self_program_id, + caller_program_id: _, pre_states, instruction: (block_validity_window, chained_program_id, chained_block_validity_window), },