From b9152f58c01d050c77b64eaf07af363d593af59e Mon Sep 17 00:00:00 2001 From: Marvin Jones Date: Fri, 14 Aug 2026 15:54:50 -0400 Subject: [PATCH] refactor(lee): migrate ChainedCall/Message program reference from ProgramId to AccountId Chained-call and public-transaction dispatch now address the target program directly by AccountId instead of routing through ProgramId and converting internally, closing the gap that blocked PDA-addressed program invocation. The field is named program_account_id (not account_id) to stay unambiguous next to the account_ids list it sits beside in the same structs. Execution/PDA-derivation logic that fundamentally needs the RISC0 image id (self_program_id, caller_program_id, env::verify, PDA seed derivation) stays ProgramId-typed, recovering it from the dispatched AccountId via the existing bijection where needed. --- .../methods/guest/src/bin/simple_tail_call.rs | 2 +- .../guest/src/bin/tail_call_with_pda.rs | 2 +- .../src/bin/run_hello_world.rs | 3 +- .../bin/run_hello_world_through_tail_call.rs | 9 +++- .../bin/run_hello_world_with_authorization.rs | 3 +- ...uthorization_through_tail_call_with_pda.rs | 3 +- .../bin/run_hello_world_with_move_function.rs | 4 +- .../tests/auth_transfer/public.rs | 6 +-- integration_tests/tests/bridge.rs | 4 +- integration_tests/tests/cross_zone_bridge.rs | 2 +- .../tests/cross_zone_ingress_guard.rs | 2 +- integration_tests/tests/cross_zone_ping.rs | 2 +- .../tests/cross_zone_state_machine.rs | 28 +++++------ .../tests/cross_zone_verified.rs | 2 +- .../tests/cross_zone_watcher_restart.rs | 4 +- integration_tests/tests/program_deployment.rs | 8 ++- integration_tests/tests/tps.rs | 4 +- .../src/execution_state.rs | 24 +++++---- lee/state_machine/core/src/program/mod.rs | 28 +++++------ lee/state_machine/src/error.rs | 4 +- .../circuit/mod.rs | 15 ++++-- .../src/public_transaction/message.rs | 43 +++++----------- .../src/public_transaction/transaction.rs | 14 +++--- .../src/public_transaction/witness_set.rs | 3 +- lee/state_machine/src/state/mod.rs | 14 +++--- .../src/state/tests/changer_claimer.rs | 24 ++++++--- lee/state_machine/src/state/tests/claiming.rs | 19 +++---- .../src/state/tests/flash_swap.rs | 16 ++++-- lee/state_machine/src/state/tests/mod.rs | 5 +- .../src/state/tests/public_program_rules.rs | 45 ++++++++++------- .../src/state/tests/validity_window.rs | 20 +++++--- .../src/validated_state_diff/mod.rs | 37 ++++++++------ .../src/validated_state_diff/tests.rs | 11 ++-- .../guest/src/bin/chain_caller.rs | 2 +- .../guest/src/bin/flash_swap_callback.rs | 2 +- .../guest/src/bin/flash_swap_initiator.rs | 6 +-- .../bin/malicious_authorization_changer.rs | 2 +- .../guest/src/bin/malicious_injector.rs | 2 +- .../guest/src/bin/malicious_launderer.rs | 2 +- .../guest/src/bin/pda_spend_proxy.rs | 2 +- .../guest/src/bin/private_pda_delegator.rs | 2 +- .../guest/src/bin/simple_transfer_proxy.rs | 4 +- .../src/bin/validity_window_chain_caller.rs | 2 +- lez/common/src/test_utils.rs | 4 +- lez/common/src/transaction.rs | 2 +- lez/cross_zone/src/lib.rs | 12 +++-- .../src/components/transaction_details.rs | 4 +- lez/indexer/core/src/cross_zone_verifier.rs | 9 ++-- lez/indexer/ffi/indexer_ffi.h | 9 +--- lez/indexer/ffi/src/api/types/transaction.rs | 15 +++--- lez/indexer/service/protocol/src/convert.rs | 8 +-- lez/indexer/service/protocol/src/lib.rs | 2 +- lez/indexer/service/src/mock_service.rs | 6 +-- lez/programs/amm/src/add.rs | 6 +-- lez/programs/amm/src/new_definition.rs | 6 +-- lez/programs/amm/src/remove.rs | 6 +-- lez/programs/amm/src/swap.rs | 8 +-- lez/programs/amm/src/tests.rs | 50 +++++++++---------- .../associated_token_account/src/burn.rs | 2 +- .../associated_token_account/src/create.rs | 2 +- .../associated_token_account/src/tests.rs | 2 +- .../associated_token_account/src/transfer.rs | 2 +- lez/programs/bridge/src/main.rs | 2 +- lez/programs/bridge_lock/src/main.rs | 2 +- lez/programs/cross_zone_inbox/src/main.rs | 2 +- lez/programs/faucet/src/main.rs | 4 +- lez/programs/pinata_token/src/main.rs | 2 +- lez/programs/ping_sender/src/main.rs | 2 +- lez/programs/vault/src/main.rs | 4 +- lez/sequencer/actors/executor/src/tests.rs | 2 +- .../actors/rpc_server/src/actor/service.rs | 4 +- lez/sequencer/core/src/cross_zone_watcher.rs | 5 +- lez/sequencer/core/src/lib.rs | 14 +++--- lez/sequencer/core/src/tests.rs | 14 +++--- lez/wallet/src/lib.rs | 2 +- test_programs/guest/src/bin/chain_caller.rs | 2 +- .../guest/src/bin/clock_chain_caller.rs | 2 +- .../guest/src/bin/faucet_chain_caller.rs | 2 +- .../guest/src/bin/pda_spend_proxy.rs | 2 +- tools/cross_zone_chat/src/main.rs | 8 +-- 80 files changed, 355 insertions(+), 311 deletions(-) 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 8f7edcab8..d076192e5 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 @@ -48,7 +48,7 @@ fn main() { let chained_call_greeting: Vec = b"Hello from tail call".to_vec(); let chained_call_instruction_data = risc0_zkvm::serde::to_vec(&chained_call_greeting).unwrap(); let chained_call = ChainedCall { - program_id: hello_world_program_id(), + program_account_id: hello_world_program_id().into(), instruction_data: chained_call_instruction_data, pre_states, pda_seeds: vec![], 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 c4b2cd11d..1d6cad3b2 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 @@ -60,7 +60,7 @@ fn main() { this }; let chained_call = ChainedCall { - program_id: hello_world_program_id(), + program_account_id: hello_world_program_id().into(), instruction_data: chained_call_instruction_data, pre_states: vec![pre_state_for_chained_call], pda_seeds: vec![PDA_SEED], diff --git a/examples/program_deployment/src/bin/run_hello_world.rs b/examples/program_deployment/src/bin/run_hello_world.rs index f58f2ec0e..da7ede3c5 100644 --- a/examples/program_deployment/src/bin/run_hello_world.rs +++ b/examples/program_deployment/src/bin/run_hello_world.rs @@ -53,7 +53,8 @@ async fn main() { // `run_hello_world_with_authorization` on how to use them. let nonces = vec![]; let signing_keys = []; - let message = Message::try_new(program.id(), vec![account_id], nonces, greeting).unwrap(); + let message = + Message::try_new(program.id().into(), vec![account_id], nonces, greeting).unwrap(); let witness_set = WitnessSet::for_message(&message, &signing_keys); let tx = PublicTransaction::new(message, witness_set); diff --git a/examples/program_deployment/src/bin/run_hello_world_through_tail_call.rs b/examples/program_deployment/src/bin/run_hello_world_through_tail_call.rs index 00254bfdc..a7f0eb128 100644 --- a/examples/program_deployment/src/bin/run_hello_world_through_tail_call.rs +++ b/examples/program_deployment/src/bin/run_hello_world_through_tail_call.rs @@ -48,8 +48,13 @@ async fn main() { let instruction_data = (); let nonces = vec![]; let signing_keys = []; - let message = - Message::try_new(program.id(), vec![account_id], nonces, instruction_data).unwrap(); + let message = Message::try_new( + program.id().into(), + vec![account_id], + nonces, + instruction_data, + ) + .unwrap(); let witness_set = WitnessSet::for_message(&message, &signing_keys); let tx = PublicTransaction::new(message, witness_set); diff --git a/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs b/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs index f7ad36b12..f843c6e85 100644 --- a/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs +++ b/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs @@ -65,7 +65,8 @@ async fn main() { .await .expect("Node should be reachable to query account data"); let signing_keys = [&signing_key]; - let message = Message::try_new(program.id(), vec![account_id], nonces, greeting).unwrap(); + let message = + Message::try_new(program.id().into(), vec![account_id], nonces, greeting).unwrap(); // Pass the signing key to sign the message. This will be used by the node // to flag the pre_state as `is_authorized` when executing the program let witness_set = WitnessSet::for_message(&message, &signing_keys); diff --git a/examples/program_deployment/src/bin/run_hello_world_with_authorization_through_tail_call_with_pda.rs b/examples/program_deployment/src/bin/run_hello_world_with_authorization_through_tail_call_with_pda.rs index a29bd2638..85b44f627 100644 --- a/examples/program_deployment/src/bin/run_hello_world_with_authorization_through_tail_call_with_pda.rs +++ b/examples/program_deployment/src/bin/run_hello_world_with_authorization_through_tail_call_with_pda.rs @@ -51,7 +51,8 @@ async fn main() { let instruction_data = (); let nonces = vec![]; let signing_keys = []; - let message = Message::try_new(program.id(), account_ids, nonces, instruction_data).unwrap(); + let message = + Message::try_new(program.id().into(), account_ids, nonces, instruction_data).unwrap(); let witness_set = WitnessSet::for_message(&message, &signing_keys); let tx = PublicTransaction::new(message, witness_set); diff --git a/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs b/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs index c03563ad4..d5f160088 100644 --- a/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs +++ b/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs @@ -77,7 +77,7 @@ async fn main() { let account_id = account_id.parse().unwrap(); let nonces = vec![]; let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![account_id], nonces, instruction, @@ -116,7 +116,7 @@ async fn main() { let to = to.parse().unwrap(); let nonces = vec![]; let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![from, to], nonces, instruction, diff --git a/integration_tests/tests/auth_transfer/public.rs b/integration_tests/tests/auth_transfer/public.rs index d9d28c7d1..2a99e8bd7 100644 --- a/integration_tests/tests/auth_transfer/public.rs +++ b/integration_tests/tests/auth_transfer/public.rs @@ -311,7 +311,7 @@ async fn cannot_transfer_funds_from_system_faucet_account() -> Result<()> { let amount = 1_u128; let message = public_transaction::Message::try_new( - programs::authenticated_transfer().id(), + programs::authenticated_transfer().id().into(), vec![faucet_account_id, recipient], vec![], authenticated_transfer_core::Instruction::Transfer { amount }, @@ -353,7 +353,7 @@ async fn cannot_execute_faucet_program() -> Result<()> { let amount = 1_u128; let message = public_transaction::Message::try_new( - programs::faucet().id(), + programs::faucet().id().into(), vec![faucet_account_id, recipient_vault_id], vec![], faucet_core::Instruction::GenesisTransferVault { @@ -406,7 +406,7 @@ async fn user_tx_that_chain_calls_faucet_is_dropped() -> Result<()> { let amount: u128 = 1; let message = public_transaction::Message::try_new( - faucet_chain_caller.id(), + faucet_chain_caller.id().into(), vec![faucet_account_id, attacker_vault_id], vec![], (faucet_program_id, vault_program_id, attacker, amount), diff --git a/integration_tests/tests/bridge.rs b/integration_tests/tests/bridge.rs index 6fc48c6a8..8f73cfacc 100644 --- a/integration_tests/tests/bridge.rs +++ b/integration_tests/tests/bridge.rs @@ -30,7 +30,7 @@ async fn public_bridge_deposit_invocation_is_dropped() -> anyhow::Result<()> { let receipt_id = bridge_core::deposit_receipt_account_id(programs::bridge().id(), [0_u8; 32]); let message = public_transaction::Message::try_new( - programs::bridge().id(), + programs::bridge().id().into(), vec![bridge_account_id, recipient_vault_id, receipt_id], vec![], bridge_core::Instruction::Deposit { @@ -79,7 +79,7 @@ async fn public_bridge_deposit_with_zero_amount_is_rejected() -> anyhow::Result< let receipt_id = bridge_core::deposit_receipt_account_id(programs::bridge().id(), [0_u8; 32]); let message = public_transaction::Message::try_new( - programs::bridge().id(), + programs::bridge().id().into(), vec![bridge_account_id, recipient_vault_id, receipt_id], vec![], bridge_core::Instruction::Deposit { diff --git a/integration_tests/tests/cross_zone_bridge.rs b/integration_tests/tests/cross_zone_bridge.rs index 2279069bb..1767c67c0 100644 --- a/integration_tests/tests/cross_zone_bridge.rs +++ b/integration_tests/tests/cross_zone_bridge.rs @@ -173,7 +173,7 @@ fn build_lock_tx( outbox_pda(outbox_id, bridge_lock_id, &target_zone, ordinal), ]; // One nonce per signature: the holder signs, at its genesis nonce 0. - let message = Message::try_new(bridge_lock_id, accounts, vec![0_u128.into()], lock) + let message = Message::try_new(bridge_lock_id.into(), accounts, vec![0_u128.into()], lock) .expect("build lock message"); let witness = WitnessSet::for_message(&message, &[holder_key]); LeeTransaction::Public(PublicTransaction::new(message, witness)) diff --git a/integration_tests/tests/cross_zone_ingress_guard.rs b/integration_tests/tests/cross_zone_ingress_guard.rs index af8b4cbf9..0af05ff9b 100644 --- a/integration_tests/tests/cross_zone_ingress_guard.rs +++ b/integration_tests/tests/cross_zone_ingress_guard.rs @@ -57,7 +57,7 @@ async fn user_origin_inbox_call_rejected() -> Result<()> { }; let seen_id = inbox_seen_shard_account_id(inbox_id, &msg.src_zone, msg.src_block_id); let message = Message::try_new( - inbox_id, + inbox_id.into(), vec![inbox_config_account_id(inbox_id), seen_id], vec![], Instruction::Dispatch(msg), diff --git a/integration_tests/tests/cross_zone_ping.rs b/integration_tests/tests/cross_zone_ping.rs index d7eae3497..0287b40b5 100644 --- a/integration_tests/tests/cross_zone_ping.rs +++ b/integration_tests/tests/cross_zone_ping.rs @@ -137,7 +137,7 @@ fn build_ping_tx(target_zone: [u8; 32], receiver_id: ProgramId) -> LeeTransactio let sender_id = programs::ping_sender().id(); let outbox_account = outbox_pda(outbox_id, sender_id, &target_zone, ordinal); let message = Message::try_new( - sender_id, + sender_id.into(), vec![sender_config_account_id(sender_id), outbox_account], vec![], send, diff --git a/integration_tests/tests/cross_zone_state_machine.rs b/integration_tests/tests/cross_zone_state_machine.rs index 30725c680..559775070 100644 --- a/integration_tests/tests/cross_zone_state_machine.rs +++ b/integration_tests/tests/cross_zone_state_machine.rs @@ -291,7 +291,7 @@ fn send_tx(accounts: Vec, target_zone: [u8; 32], ordinal: u32) -> Pub payload: words.iter().flat_map(|word| word.to_le_bytes()).collect(), ordinal, }; - let message = Message::try_new(programs::ping_sender().id(), accounts, vec![], send) + let message = Message::try_new(programs::ping_sender().id().into(), accounts, vec![], send) .expect("build ping_sender message"); PublicTransaction::new(message, WitnessSet::from_raw_parts(vec![])) } @@ -335,7 +335,7 @@ fn dispatch_mint(amount: u128) -> Result LeeTransactio let sender_id = programs::ping_sender().id(); let outbox_account = outbox_pda(outbox_id, sender_id, &target_zone, ordinal); let message = Message::try_new( - sender_id, + sender_id.into(), vec![sender_config_account_id(sender_id), outbox_account], vec![], send, diff --git a/integration_tests/tests/cross_zone_watcher_restart.rs b/integration_tests/tests/cross_zone_watcher_restart.rs index f60f7a588..53f438e22 100644 --- a/integration_tests/tests/cross_zone_watcher_restart.rs +++ b/integration_tests/tests/cross_zone_watcher_restart.rs @@ -153,7 +153,7 @@ async fn count_inbox_transactions(client: &SequencerClient, from: u64, to: u64) }; for tx in &block.body.transactions { if let LeeTransaction::Public(public_tx) = tx - && public_tx.message().program_id == inbox_id + && public_tx.message().program_account_id == inbox_id.into() { count = count.saturating_add(1); } @@ -208,7 +208,7 @@ fn build_ping_tx(target_zone: [u8; 32], receiver_id: ProgramId) -> LeeTransactio let sender_id = programs::ping_sender().id(); let outbox_account = outbox_pda(outbox_id, sender_id, &target_zone, ordinal); let message = Message::try_new( - sender_id, + sender_id.into(), vec![sender_config_account_id(sender_id), outbox_account], vec![], send, diff --git a/integration_tests/tests/program_deployment.rs b/integration_tests/tests/program_deployment.rs index c501752f0..1e52d2841 100644 --- a/integration_tests/tests/program_deployment.rs +++ b/integration_tests/tests/program_deployment.rs @@ -38,8 +38,12 @@ async fn deploy_and_execute_program() -> Result<()> { .wallet() .get_account_public_signing_key(account_id) .unwrap(); - let message = - lee::public_transaction::Message::try_new(claimer.id(), vec![account_id], nonces, ())?; + let message = lee::public_transaction::Message::try_new( + claimer.id().into(), + vec![account_id], + nonces, + (), + )?; let witness_set = lee::public_transaction::WitnessSet::for_message(&message, &[private_key]); let transaction = lee::PublicTransaction::new(message, witness_set); let _response = ctx diff --git a/integration_tests/tests/tps.rs b/integration_tests/tests/tps.rs index f4f6145cc..a7a6cba00 100644 --- a/integration_tests/tests/tps.rs +++ b/integration_tests/tests/tps.rs @@ -85,7 +85,7 @@ impl TpsTestManager { let owner_vault_id = vault_core::compute_vault_account_id(vault_program_id, *account_id); let message = putx::Message::try_new( - vault_program_id, + vault_program_id.into(), vec![*account_id, owner_vault_id], vec![Nonce(0_u128)], vault_core::Instruction::Claim { amount: 10 }, @@ -135,7 +135,7 @@ impl TpsTestManager { .map(|pair| { let amount: u128 = 1; let message = putx::Message::try_new( - program.id(), + program.id().into(), [pair[0].1, pair[1].1].to_vec(), [Nonce(1_u128)].to_vec(), authenticated_transfer_core::Instruction::Transfer { amount }, diff --git a/lee/privacy_preserving_circuit/src/execution_state.rs b/lee/privacy_preserving_circuit/src/execution_state.rs index d3eac1db5..d492ee3fe 100644 --- a/lee/privacy_preserving_circuit/src/execution_state.rs +++ b/lee/privacy_preserving_circuit/src/execution_state.rs @@ -122,7 +122,7 @@ impl ExecutionState { }; let initial_call = ChainedCall { - program_id, + program_account_id: AccountId::from(program_id), instruction_data: first_output.instruction_data.clone(), pre_states: first_output.pre_states.clone(), pda_seeds: Vec::new(), @@ -147,6 +147,13 @@ impl ExecutionState { panic!("Insufficient program outputs for chained calls"); }; + // Recover the real `ProgramId` (RISC0 image id) from the account's address: on this + // branch every program account lives at the direct `AccountId::from(program_id)` + // bijection, so this round-trip is exact. Needed wherever proof verification/PDA + // derivation requires the underlying image id rather than the dispatch-facing + // `AccountId`. + let current_program_id = ProgramId::from(chained_call.program_account_id); + // Check that instruction data in chained call is the instruction data in program output assert_eq!( chained_call.instruction_data, program_output.instruction_data, @@ -157,14 +164,14 @@ impl ExecutionState { // program. let program_output_words = &to_vec(&program_output).expect("program_output must be serializable"); - env::verify(chained_call.program_id, program_output_words).unwrap_or_else( + env::verify(current_program_id, program_output_words).unwrap_or_else( |_: Infallible| unreachable!("Infallible error is never constructed"), ); // Verify that the program output's self_program_id matches the expected program ID. // This ensures the proof commits to which program produced the output. assert_eq!( - program_output.self_program_id, chained_call.program_id, + program_output.self_program_id, current_program_id, "Program output self_program_id does not match chained call program_id" ); @@ -182,18 +189,15 @@ impl ExecutionState { let validated_execution = validate_execution( &program_output.pre_states, &program_output.post_states, - chained_call.program_id, + chained_call.program_account_id, ); if let Err(err) = validated_execution { - panic!( - "Invalid program behavior in program {:?}: {err}", - chained_call.program_id - ); + panic!("Invalid program behavior in program {current_program_id:?}: {err}"); } let authorized_accounts = execution_state.validate_and_sync_states( account_identities, - chained_call.program_id, + current_program_id, caller_data, &chained_call.pda_seeds, program_output.pre_states, @@ -205,7 +209,7 @@ impl ExecutionState { chained_calls.push_front(( next_call, CallerData { - program_id: Some(chained_call.program_id), + program_id: Some(current_program_id), authorized_accounts: authorized_accounts.clone(), }, )); diff --git a/lee/state_machine/core/src/program/mod.rs b/lee/state_machine/core/src/program/mod.rs index 0a63b129d..68a77d1ee 100644 --- a/lee/state_machine/core/src/program/mod.rs +++ b/lee/state_machine/core/src/program/mod.rs @@ -244,8 +244,8 @@ pub struct CallerData { #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct ChainedCall { - /// The program ID of the program to execute. - pub program_id: ProgramId, + /// The `AccountId` of the program to execute. + pub program_account_id: AccountId, pub pre_states: Vec, /// The instruction data to pass. pub instruction_data: InstructionData, @@ -258,12 +258,12 @@ pub struct ChainedCall { impl ChainedCall { /// Creates a new chained call serializing the given instruction. pub fn new( - program_id: ProgramId, + program_account_id: AccountId, pre_states: Vec, instruction: &I, ) -> Self { Self { - program_id, + program_account_id, pre_states, instruction_data: risc0_zkvm::serde::to_vec(instruction) .expect("Serialization to Vec should not fail"), @@ -633,20 +633,20 @@ pub enum ExecutionValidationError { ModifiedProgramOwner { account_id: AccountId }, #[error( - "Trying to decrease balance of account {account_id} owned by {owner_account_id:?} in a program {executing_program_id:?} which is not the owner" + "Trying to decrease balance of account {account_id} owned by {owner_account_id:?} in a program {executing_account_id:?} which is not the owner" )] UnauthorizedBalanceDecrease { account_id: AccountId, owner_account_id: AccountId, - executing_program_id: ProgramId, + executing_account_id: AccountId, }, #[error( - "Unauthorized modification of data for account {account_id} which is not default and not owned by executing program {executing_program_id:?}" + "Unauthorized modification of data for account {account_id} which is not default and not owned by executing program {executing_account_id:?}" )] UnauthorizedDataModification { account_id: AccountId, - executing_program_id: ProgramId, + executing_account_id: AccountId, }, #[error( @@ -710,16 +710,12 @@ pub fn read_lee_inputs() -> (ProgramInput, InstructionDa /// # Parameters /// - `pre_states`: The list of input accounts, each annotated with authorization metadata. /// - `post_states`: The list of resulting accounts after executing the program logic. -/// - `executing_program_id`: The identifier of the program that was executed. +/// - `executing_account_id`: The `AccountId` of the program that was executed. pub fn validate_execution( pre_states: &[AccountWithMetadata], post_states: &[AccountPostState], - executing_program_id: ProgramId, + executing_account_id: AccountId, ) -> Result<(), ExecutionValidationError> { - // `program_owner` is `AccountId`-typed; convert once up front rather than at each - // comparison below (see `From for AccountId`'s doc comment). - let executing_account_id = AccountId::from(executing_program_id); - // 1. Check account ids are all different if !validate_uniqueness_of_account_ids(pre_states) { return Err(ExecutionValidationError::PreStateAccountIdsNotUnique); @@ -759,7 +755,7 @@ pub fn validate_execution( return Err(ExecutionValidationError::UnauthorizedBalanceDecrease { account_id: pre.account_id, owner_account_id: account_program_owner, - executing_program_id, + executing_account_id, }); } @@ -771,7 +767,7 @@ pub fn validate_execution( { return Err(ExecutionValidationError::UnauthorizedDataModification { account_id: pre.account_id, - executing_program_id, + executing_account_id, }); } diff --git a/lee/state_machine/src/error.rs b/lee/state_machine/src/error.rs index 94e66e8b8..c87940a46 100644 --- a/lee/state_machine/src/error.rs +++ b/lee/state_machine/src/error.rs @@ -101,8 +101,8 @@ pub enum InvalidProgramBehaviorError { #[error("Program ID mismatch: expected {expected:?}, actual {actual:?}")] MismatchedProgramId { - expected: ProgramId, - actual: ProgramId, + expected: AccountId, + actual: AccountId, }, #[error("Caller program ID mismatch: expected {expected:?}, actual {actual:?}")] diff --git a/lee/state_machine/src/privacy_preserving_transaction/circuit/mod.rs b/lee/state_machine/src/privacy_preserving_transaction/circuit/mod.rs index d907a1e8f..42b6903a5 100644 --- a/lee/state_machine/src/privacy_preserving_transaction/circuit/mod.rs +++ b/lee/state_machine/src/privacy_preserving_transaction/circuit/mod.rs @@ -4,7 +4,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use lee_core::{ DummyInput, InputAccountIdentity, PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput, - account::AccountWithMetadata, + account::{AccountId, AccountWithMetadata}, program::{ChainedCall, InstructionData, ProgramId, ProgramOutput}, }; use risc0_zkvm::{ExecutorEnv, InnerReceipt, ProverOpts, Receipt, default_prover}; @@ -95,7 +95,7 @@ pub fn execute_and_prove_with_padded_inputs( let mut program_outputs = Vec::new(); let initial_call = ChainedCall { - program_id: initial_program.id(), + program_account_id: AccountId::from(initial_program.id()), instruction_data, pre_states, pda_seeds: vec![], @@ -127,12 +127,17 @@ pub fn execute_and_prove_with_padded_inputs( env_builder.add_assumption(inner_receipt); for new_call in program_output.chained_calls.into_iter().rev() { - let next_program = dependencies.get(&new_call.program_id).ok_or( + let new_call_program_id = ProgramId::from(new_call.program_account_id); + let next_program = dependencies.get(&new_call_program_id).ok_or( InvalidProgramBehaviorError::UndeclaredProgramDependency { - program_id: new_call.program_id, + program_id: new_call_program_id, }, )?; - chained_calls.push_front((new_call, next_program, Some(chained_call.program_id))); + chained_calls.push_front(( + new_call, + next_program, + Some(ProgramId::from(chained_call.program_account_id)), + )); } chain_calls_counter = chain_calls_counter diff --git a/lee/state_machine/src/public_transaction/message.rs b/lee/state_machine/src/public_transaction/message.rs index feafc5391..1384086cd 100644 --- a/lee/state_machine/src/public_transaction/message.rs +++ b/lee/state_machine/src/public_transaction/message.rs @@ -1,8 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use lee_core::{ - account::Nonce, - program::{InstructionData, ProgramId}, -}; +use lee_core::{account::Nonce, program::InstructionData}; use serde::Serialize; use sha2::{Digest as _, Sha256}; @@ -10,34 +7,17 @@ use crate::{AccountId, error::LeeError, program::Program}; const PREFIX: &[u8; 32] = b"/LEE/v0.3/Message/Public/\x00\x00\x00\x00\x00\x00\x00"; -#[derive(Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] +#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] pub struct Message { - pub program_id: ProgramId, + pub program_account_id: AccountId, pub account_ids: Vec, pub nonces: Vec, pub instruction_data: InstructionData, } -impl std::fmt::Debug for Message { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let program_id_hex = hex::encode( - self.program_id - .iter() - .flat_map(|n| n.to_le_bytes()) - .collect::>(), - ); - f.debug_struct("Message") - .field("program_id", &program_id_hex) - .field("account_ids", &self.account_ids) - .field("nonces", &self.nonces) - .field("instruction_data", &self.instruction_data) - .finish() - } -} - impl Message { pub fn try_new( - program_id: ProgramId, + program_account_id: AccountId, account_ids: Vec, nonces: Vec, instruction: T, @@ -45,7 +25,7 @@ impl Message { let instruction_data = Program::serialize_instruction(instruction)?; Ok(Self { - program_id, + program_account_id, account_ids, nonces, instruction_data, @@ -54,13 +34,13 @@ impl Message { #[must_use] pub const fn new_preserialized( - program_id: ProgramId, + program_account_id: AccountId, account_ids: Vec, nonces: Vec, instruction_data: InstructionData, ) -> Self { Self { - program_id, + program_account_id, account_ids, nonces, instruction_data, @@ -92,14 +72,15 @@ mod tests { #[test] fn hash_public_pinned() { let msg = Message::new_preserialized( - [1_u32; 8], + AccountId::from([1_u32; 8]), vec![AccountId::new([42_u8; 32])], vec![Nonce(5)], vec![], ); - // program_id: [1_u32; 8], each word as LE u32 - let program_id_bytes: &[u8] = &[ + // program_account_id: AccountId::from([1_u32; 8]) is the LE-word-flattened bytes of the + // array + let account_id_bytes: &[u8] = &[ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, ]; @@ -110,7 +91,7 @@ mod tests { let instruction_data_bytes: &[u8] = &[0_u8; 4]; let expected_borsh_vec: Vec = [ - program_id_bytes, + account_id_bytes, &[1_u8, 0, 0, 0], // account_ids len=1 account_ids_bytes, nonces_bytes, diff --git a/lee/state_machine/src/public_transaction/transaction.rs b/lee/state_machine/src/public_transaction/transaction.rs index e0d1fe1be..6304799d1 100644 --- a/lee/state_machine/src/public_transaction/transaction.rs +++ b/lee/state_machine/src/public_transaction/transaction.rs @@ -91,7 +91,7 @@ pub mod tests { let nonces = vec![0_u128.into(), 0_u128.into()]; let instruction = 1337; let message = Message::try_new( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![addr1, addr2], nonces, instruction, @@ -169,7 +169,7 @@ pub mod tests { let nonces = vec![0_u128.into(), 0_u128.into()]; let instruction = 1337; let message = Message::try_new( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![addr1, addr1], nonces, instruction, @@ -189,7 +189,7 @@ pub mod tests { let nonces = vec![0_u128.into()]; let instruction = 1337; let message = Message::try_new( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![addr1, addr2], nonces, instruction, @@ -209,7 +209,7 @@ pub mod tests { let nonces = vec![0_u128.into(), 0_u128.into()]; let instruction = 1337; let message = Message::try_new( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![addr1, addr2], nonces, instruction, @@ -230,7 +230,7 @@ pub mod tests { let nonces = vec![0_u128.into(), 1_u128.into()]; let instruction = 1337; let message = Message::try_new( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![addr1, addr2], nonces, instruction, @@ -247,7 +247,7 @@ pub mod tests { fn empty_transaction_is_rejected() { let state = state_for_tests(); let message = Message::new_preserialized( - crate::test_methods::simple_balance_transfer().id(), + crate::test_methods::simple_balance_transfer().id().into(), vec![], vec![], vec![0; 4], @@ -264,7 +264,7 @@ pub mod tests { let state = state_for_tests(); let nonces = vec![0_u128.into(), 0_u128.into()]; let instruction = 1337; - let unknown_program_id = [0xdead_beef; 8]; + let unknown_program_id: AccountId = [0xdead_beef_u32; 8].into(); let message = Message::try_new(unknown_program_id, vec![addr1, addr2], nonces, instruction).unwrap(); diff --git a/lee/state_machine/src/public_transaction/witness_set.rs b/lee/state_machine/src/public_transaction/witness_set.rs index 1605f488a..cb6d61779 100644 --- a/lee/state_machine/src/public_transaction/witness_set.rs +++ b/lee/state_machine/src/public_transaction/witness_set.rs @@ -69,7 +69,8 @@ mod tests { let addr2 = AccountId::from(&pubkey2); let nonces = vec![1_u128.into(), 2_u128.into()]; let instruction = vec![1, 2, 3, 4]; - let message = Message::try_new([0; 8], vec![addr1, addr2], nonces, instruction).unwrap(); + let message = + Message::try_new([0; 8].into(), vec![addr1, addr2], nonces, instruction).unwrap(); let witness_set = WitnessSet::for_message(&message, &[&key1, &key2]); diff --git a/lee/state_machine/src/state/mod.rs b/lee/state_machine/src/state/mod.rs index 79e7d2c0c..74790d46c 100644 --- a/lee/state_machine/src/state/mod.rs +++ b/lee/state_machine/src/state/mod.rs @@ -5,7 +5,7 @@ use lee_core::{ BlockId, Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, MembershipProof, Nullifier, Timestamp, account::{Account, AccountId, Data}, - program::{PROGRAM_STORAGE_OWNER, ProgramId}, + program::PROGRAM_STORAGE_OWNER, }; use crate::{ @@ -281,15 +281,15 @@ impl V03State { self.public_state.get(&account_id) } - /// Looks up a deployed program's storage account by its `ProgramId`, verifying it is + /// Looks up a deployed program's storage account by its `AccountId`, verifying it is /// actually owned by [`PROGRAM_STORAGE_OWNER`]. /// - /// An account at `AccountId::from(program_id)` that lacks this ownership isn't a deployed - /// program, whatever its contents — this is the single place that distinction is enforced, - /// so callers never have to remember to re-check it themselves. + /// An account that lacks this ownership isn't a deployed program, whatever its contents — + /// this is the single place that distinction is enforced, so callers never have to remember + /// to re-check it themselves. #[must_use] - pub fn get_program(&self, program_id: ProgramId) -> Option<&Account> { - let account = self.get_account_by_id_ref(AccountId::from(program_id))?; + pub fn get_program(&self, program_account_id: AccountId) -> Option<&Account> { + let account = self.get_account_by_id_ref(program_account_id)?; (account.program_owner == PROGRAM_STORAGE_OWNER).then_some(account) } diff --git a/lee/state_machine/src/state/tests/changer_claimer.rs b/lee/state_machine/src/state/tests/changer_claimer.rs index b422d1199..fc46fd785 100644 --- a/lee/state_machine/src/state/tests/changer_claimer.rs +++ b/lee/state_machine/src/state/tests/changer_claimer.rs @@ -7,13 +7,17 @@ fn public_changer_claimer_no_data_change_no_claim_succeeds() { .with_public_accounts(public_state_from_balances(&initial_data)) .with_test_programs(); let account_id = AccountId::new([1; 32]); - let program_id = crate::test_methods::changer_claimer().id(); + let account_id_for_message: AccountId = crate::test_methods::changer_claimer().id().into(); // Don't change data (None) and don't claim (false) let instruction: (Option>, bool) = (None, false); - let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], instruction) - .unwrap(); + let message = public_transaction::Message::try_new( + account_id_for_message, + vec![account_id], + vec![], + instruction, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -32,14 +36,18 @@ fn public_changer_claimer_data_change_no_claim_fails() { .with_public_accounts(public_state_from_balances(&initial_data)) .with_test_programs(); let account_id = AccountId::new([1; 32]); - let program_id = crate::test_methods::changer_claimer().id(); + let account_id_for_message: AccountId = crate::test_methods::changer_claimer().id().into(); // Change data but don't claim (false) - should fail let new_data = vec![1, 2, 3, 4, 5]; let instruction: (Option>, bool) = (Some(new_data), false); - let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], instruction) - .unwrap(); + let message = public_transaction::Message::try_new( + account_id_for_message, + vec![account_id], + vec![], + instruction, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); diff --git a/lee/state_machine/src/state/tests/claiming.rs b/lee/state_machine/src/state/tests/claiming.rs index cb6e0cc47..ef8c762f1 100644 --- a/lee/state_machine/src/state/tests/claiming.rs +++ b/lee/state_machine/src/state/tests/claiming.rs @@ -25,7 +25,7 @@ fn claiming_mechanism() { }; let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![from, to], vec![Nonce(0), Nonce(0)], amount, @@ -51,7 +51,7 @@ fn unauthorized_public_account_claiming_fails() { assert_eq!(state.get_account_by_id(account_id), Account::default()); let message = - public_transaction::Message::try_new(program.id(), vec![account_id], vec![], 0_u128) + public_transaction::Message::try_new(program.id().into(), vec![account_id], vec![], 0_u128) .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -72,7 +72,7 @@ fn authorized_public_account_claiming_succeeds() { assert_eq!(state.get_account_by_id(account_id), Account::default()); let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![account_id], vec![Nonce(0)], 0_u128, @@ -120,7 +120,7 @@ fn public_chained_call() { }; let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![to, from], // The chain_caller program permutes the account order in the chain // call vec![Nonce(0)], @@ -160,7 +160,7 @@ fn execution_fails_if_chained_calls_exceeds_depth() { ); let message = public_transaction::Message::try_new( - program.id(), + program.id().into(), vec![to, from], // The chain_caller program permutes the account order in the chain // call vec![Nonce(0)], @@ -202,7 +202,7 @@ fn execution_that_requires_authentication_of_a_program_derived_account_id_succee ..Account::default() }; let message = public_transaction::Message::try_new( - chain_caller.id(), + chain_caller.id().into(), vec![to, from], // The chain_caller program permutes the account order in the chain // call vec![], @@ -259,7 +259,7 @@ fn claiming_mechanism_within_chain_call() { None, ); let message = public_transaction::Message::try_new( - chain_caller.id(), + chain_caller.id().into(), vec![to, from], // The chain_caller program permutes the account order in the chain // call vec![Nonce(0), Nonce(0)], @@ -516,7 +516,8 @@ fn claiming_mechanism_cannot_claim_initialied_accounts() { ); let message = - public_transaction::Message::try_new(claimer.id(), vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(claimer.id().into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -575,7 +576,7 @@ fn malicious_program_cannot_break_balance_validation_if_not_in_genesis() { AccountWithMetadata::new(state.get_account_by_id(recipient_id), false, sender_id); let message = public_transaction::Message::try_new( - modified_transfer_id, + modified_transfer_id.into(), vec![sender_id, recipient_id], vec![sender_nonce], balance_to_move, diff --git a/lee/state_machine/src/state/tests/flash_swap.rs b/lee/state_machine/src/state/tests/flash_swap.rs index 54765a488..bd8700964 100644 --- a/lee/state_machine/src/state/tests/flash_swap.rs +++ b/lee/state_machine/src/state/tests/flash_swap.rs @@ -179,9 +179,13 @@ fn flash_swap_standalone_invariant_check_rejected() { min_vault_balance: 1000, }; - let message = - public_transaction::Message::try_new(initiator.id(), vec![vault_id], vec![], instruction) - .unwrap(); + let message = public_transaction::Message::try_new( + initiator.id().into(), + vec![vault_id], + vec![], + instruction, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -202,7 +206,8 @@ fn malicious_self_program_id_rejected_in_public_execution() { state.force_insert_account(acc_id, account); let message = - public_transaction::Message::try_new(program.id(), vec![acc_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program.id().into(), vec![acc_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -223,7 +228,8 @@ fn malicious_caller_program_id_rejected_in_public_execution() { state.force_insert_account(acc_id, account); let message = - public_transaction::Message::try_new(program.id(), vec![acc_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program.id().into(), vec![acc_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); diff --git a/lee/state_machine/src/state/tests/mod.rs b/lee/state_machine/src/state/tests/mod.rs index 1f657c14b..3c33d4961 100644 --- a/lee/state_machine/src/state/tests/mod.rs +++ b/lee/state_machine/src/state/tests/mod.rs @@ -209,7 +209,8 @@ fn transfer_transaction( let nonces = vec![Nonce(from_nonce), Nonce(to_nonce)]; let program_id = crate::test_methods::simple_balance_transfer().id(); let message = - public_transaction::Message::try_new(program_id, account_ids, nonces, balance).unwrap(); + public_transaction::Message::try_new(program_id.into(), account_ids, nonces, balance) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[from_key, to_key]); PublicTransaction::new(message, witness_set) } @@ -221,7 +222,7 @@ fn build_flash_swap_tx( instruction: FlashSwapInstruction, ) -> PublicTransaction { let message = public_transaction::Message::try_new( - initiator.id(), + initiator.id().into(), vec![vault_id, receiver_id], vec![], // no signers — vault is PDA-authorised instruction, diff --git a/lee/state_machine/src/state/tests/public_program_rules.rs b/lee/state_machine/src/state/tests/public_program_rules.rs index 405013357..40844c264 100644 --- a/lee/state_machine/src/state/tests/public_program_rules.rs +++ b/lee/state_machine/src/state/tests/public_program_rules.rs @@ -9,7 +9,7 @@ fn program_should_fail_if_modifies_nonces() { let account_ids = vec![account_id]; let program_id = crate::test_methods::nonce_changer().id(); let message = - public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), account_ids, vec![], ()).unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -33,7 +33,7 @@ fn program_should_fail_if_output_accounts_exceed_inputs() { let account_ids = vec![AccountId::new([1; 32])]; let program_id = crate::test_methods::extra_output().id(); let message = - public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), account_ids, vec![], ()).unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -60,7 +60,7 @@ fn program_should_fail_with_missing_output_accounts() { let account_ids = vec![AccountId::new([1; 32]), AccountId::new([2; 32])]; let program_id = crate::test_methods::missing_output().id(); let message = - public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), account_ids, vec![], ()).unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -114,7 +114,7 @@ fn program_should_fail_if_it_drops_a_declared_account() { let account_ids = vec![AccountId::new([1; 32]), AccountId::new([2; 32])]; let program_id = crate::test_methods::dropped_account().id(); let message = - public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), account_ids, vec![], ()).unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -153,7 +153,8 @@ fn program_should_fail_if_modifies_program_owner_with_only_non_default_program_o assert_eq!(account.data, Account::default().data); let program_id = crate::test_methods::program_owner_changer().id(); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -183,7 +184,8 @@ fn program_should_fail_if_modifies_program_owner_with_only_non_default_balance() assert_eq!(account.data, Account::default().data); let program_id = crate::test_methods::program_owner_changer().id(); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -213,7 +215,8 @@ fn program_should_fail_if_modifies_program_owner_with_only_non_default_nonce() { assert_eq!(account.data, Account::default().data); let program_id = crate::test_methods::program_owner_changer().id(); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -243,7 +246,8 @@ fn program_should_fail_if_modifies_program_owner_with_only_non_default_data() { assert_ne!(account.data, Account::default().data); let program_id = crate::test_methods::program_owner_changer().id(); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -271,7 +275,7 @@ fn program_should_fail_if_transfers_balance_from_non_owned_account() { program_id.into() ); let message = public_transaction::Message::try_new( - program_id, + program_id.into(), vec![sender_account_id, receiver_account_id], vec![], balance_to_move, @@ -285,8 +289,8 @@ fn program_should_fail_if_transfers_balance_from_non_owned_account() { assert!(matches!( result, Err(LeeError::InvalidProgramBehavior(InvalidProgramBehaviorError::ExecutionValidationFailed( - ExecutionValidationError::UnauthorizedBalanceDecrease { account_id: err_account_id, owner_account_id, executing_program_id } - ))) if err_account_id == sender_account_id && owner_account_id != program_id.into() && executing_program_id == program_id + ExecutionValidationError::UnauthorizedBalanceDecrease { account_id: err_account_id, owner_account_id, executing_account_id } + ))) if err_account_id == sender_account_id && owner_account_id != program_id.into() && executing_account_id == program_id.into() )); } @@ -306,7 +310,7 @@ fn program_should_fail_if_modifies_data_of_non_owned_account() { program_id.into() ); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], vec![0]) + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], vec![0]) .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -316,8 +320,8 @@ fn program_should_fail_if_modifies_data_of_non_owned_account() { assert!(matches!( result, Err(LeeError::InvalidProgramBehavior(InvalidProgramBehaviorError::ExecutionValidationFailed( - ExecutionValidationError::UnauthorizedDataModification { account_id: err_account_id, executing_program_id } - ))) if err_account_id == account_id && executing_program_id == program_id + ExecutionValidationError::UnauthorizedDataModification { account_id: err_account_id, executing_account_id } + ))) if err_account_id == account_id && executing_account_id == program_id.into() )); } @@ -331,7 +335,8 @@ fn program_should_fail_if_does_not_preserve_total_balance_by_minting() { let program_id = crate::test_methods::minter().id(); let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap(); + public_transaction::Message::try_new(program_id.into(), vec![account_id], vec![], ()) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -361,9 +366,13 @@ fn program_should_fail_if_does_not_preserve_total_balance_by_burning() { let balance_to_burn: u128 = 1; assert!(state.get_account_by_id(account_id).balance > balance_to_burn); - let message = - public_transaction::Message::try_new(program_id, vec![account_id], vec![], balance_to_burn) - .unwrap(); + let message = public_transaction::Message::try_new( + program_id.into(), + vec![account_id], + vec![], + balance_to_burn, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); let result = state.transition_from_public_transaction(&tx, 2, 0); diff --git a/lee/state_machine/src/state/tests/validity_window.rs b/lee/state_machine/src/state/tests/validity_window.rs index 7953c671a..359b89e97 100644 --- a/lee/state_machine/src/state/tests/validity_window.rs +++ b/lee/state_machine/src/state/tests/validity_window.rs @@ -30,9 +30,13 @@ fn validity_window_works_in_public_transactions( block_validity_window, TimestampValidityWindow::new_unbounded(), ); - let message = - public_transaction::Message::try_new(program_id, account_ids, nonces, instruction) - .unwrap(); + let message = public_transaction::Message::try_new( + program_id.into(), + account_ids, + nonces, + instruction, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); PublicTransaction::new(message, witness_set) }; @@ -81,9 +85,13 @@ fn timestamp_validity_window_works_in_public_transactions( BlockValidityWindow::new_unbounded(), timestamp_validity_window, ); - let message = - public_transaction::Message::try_new(program_id, account_ids, nonces, instruction) - .unwrap(); + let message = public_transaction::Message::try_new( + program_id.into(), + account_ids, + nonces, + instruction, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); PublicTransaction::new(message, witness_set) }; diff --git a/lee/state_machine/src/validated_state_diff/mod.rs b/lee/state_machine/src/validated_state_diff/mod.rs index 6feb89cb4..92875e8a1 100644 --- a/lee/state_machine/src/validated_state_diff/mod.rs +++ b/lee/state_machine/src/validated_state_diff/mod.rs @@ -91,7 +91,7 @@ impl ValidatedStateDiff { let mut state_diff: HashMap = HashMap::new(); let initial_call = ChainedCall { - program_id: message.program_id, + program_account_id: message.program_account_id, instruction_data: message.instruction_data.clone(), pre_states: input_pre_states, pda_seeds: vec![], @@ -112,17 +112,22 @@ impl ValidatedStateDiff { LeeError::MaxChainedCallsDepthExceeded ); - let Some(program_account) = state.get_program(chained_call.program_id) else { + let Some(program_account) = state.get_program(chained_call.program_account_id) else { return Err(LeeError::InvalidInput("Unknown program".into())); }; - let program = Program::new_unchecked( - chained_call.program_id, - Cow::Owned(program_account.data.to_vec()), - ); + // Recover the real `ProgramId` (RISC0 image id) from the account's address: on this + // branch every program account lives at the direct `AccountId::from(program_id)` + // bijection, so this round-trip is exact. Needed wherever execution/PDA derivation + // requires the underlying image id rather than the dispatch-facing `AccountId`. + let program_id = ProgramId::from(chained_call.program_account_id); + let program = + Program::new_unchecked(program_id, Cow::Owned(program_account.data.to_vec())); debug!( "Program {:?} pre_states: {:?}, instruction_data: {:?}", - chained_call.program_id, chained_call.pre_states, chained_call.instruction_data + chained_call.program_account_id, + chained_call.pre_states, + chained_call.instruction_data ); let mut program_output = program.execute( caller_data.program_id, @@ -131,7 +136,7 @@ impl ValidatedStateDiff { )?; debug!( "Program {:?} output: {:?}", - chained_call.program_id, program_output + chained_call.program_account_id, program_output ); let authorized_pdas = @@ -178,10 +183,10 @@ impl ValidatedStateDiff { // Verify that the program output's self_program_id matches the expected program ID. ensure!( - program_output.self_program_id == chained_call.program_id, + AccountId::from(program_output.self_program_id) == chained_call.program_account_id, InvalidProgramBehaviorError::MismatchedProgramId { - expected: chained_call.program_id, - actual: program_output.self_program_id + expected: chained_call.program_account_id, + actual: AccountId::from(program_output.self_program_id) } ); @@ -199,7 +204,7 @@ impl ValidatedStateDiff { validate_execution( &program_output.pre_states, &program_output.post_states, - chained_call.program_id, + chained_call.program_account_id, ) .map_err(InvalidProgramBehaviorError::ExecutionValidationFailed)?; @@ -237,7 +242,7 @@ impl ValidatedStateDiff { // The program can only claim accounts that correspond to the PDAs it is // authorized to claim. The public-execution path only sees public // accounts, so the public-PDA derivation is the correct formula here. - let pda = AccountId::for_public_pda(&chained_call.program_id, &seed); + let pda = AccountId::for_public_pda(&program_id, &seed); ensure!( account_id == pda, InvalidProgramBehaviorError::MismatchedPdaClaim { @@ -248,7 +253,7 @@ impl ValidatedStateDiff { } } - post.account_mut().program_owner = AccountId::from(chained_call.program_id); + post.account_mut().program_owner = chained_call.program_account_id; } // Update the state diff @@ -280,7 +285,7 @@ impl ValidatedStateDiff { chained_calls.push_front(( new_call, CallerData { - program_id: Some(chained_call.program_id), + program_id: Some(program_id), authorized_accounts: authorized_accounts.clone(), }, )); @@ -445,7 +450,7 @@ impl ValidatedStateDiff { ) -> Result { // TODO: remove clone let program = Program::new(tx.message.bytecode.clone().into())?; - if state.get_program(program.id()).is_some() { + if state.get_program(AccountId::from(program.id())).is_some() { return Err(LeeError::ProgramAlreadyExists); } Ok(Self(StateDiff { diff --git a/lee/state_machine/src/validated_state_diff/tests.rs b/lee/state_machine/src/validated_state_diff/tests.rs index 0f274aaaf..dd113545d 100644 --- a/lee/state_machine/src/validated_state_diff/tests.rs +++ b/lee/state_machine/src/validated_state_diff/tests.rs @@ -43,8 +43,13 @@ fn public_diff_reflects_a_successful_transfer() { crate::test_methods::simple_balance_transfer(), )); let program_id = crate::test_methods::simple_balance_transfer().id(); - let message = - Message::try_new(program_id, vec![from, to], vec![Nonce(0), Nonce(0)], 5_u128).unwrap(); + let message = Message::try_new( + program_id.into(), + vec![from, to], + vec![Nonce(0), Nonce(0)], + 5_u128, + ) + .unwrap(); let witness_set = WitnessSet::for_message(&message, &[&from_key, &to_key]); let tx = crate::PublicTransaction::new(message, witness_set); @@ -445,7 +450,7 @@ fn malicious_programs_cannot_drain_victim_without_signature() { ); let message = Message::try_new( - crate::test_methods::malicious_injector().id(), + crate::test_methods::malicious_injector().id().into(), vec![attacker_id], vec![Nonce(0)], instruction, diff --git a/lee/state_machine/test_methods/guest/src/bin/chain_caller.rs b/lee/state_machine/test_methods/guest/src/bin/chain_caller.rs index b812fc9e7..7227d905b 100644 --- a/lee/state_machine/test_methods/guest/src/bin/chain_caller.rs +++ b/lee/state_machine/test_methods/guest/src/bin/chain_caller.rs @@ -36,7 +36,7 @@ fn main() { let mut chained_calls = Vec::new(); for _i in 0..num_chain_calls { let new_chained_call = ChainedCall { - program_id: simple_transfer_id, + program_account_id: simple_transfer_id.into(), instruction_data: instruction_data.clone(), pre_states: vec![running_sender_pre.clone(), running_recipient_pre.clone()], /* <- Account order permutation here */ pda_seeds: pda_seed.iter().copied().collect(), diff --git a/lee/state_machine/test_methods/guest/src/bin/flash_swap_callback.rs b/lee/state_machine/test_methods/guest/src/bin/flash_swap_callback.rs index 28f6509f1..78c75d3c7 100644 --- a/lee/state_machine/test_methods/guest/src/bin/flash_swap_callback.rs +++ b/lee/state_machine/test_methods/guest/src/bin/flash_swap_callback.rs @@ -66,7 +66,7 @@ fn main() { .expect("transfer instruction serialization"); chained_calls.push(ChainedCall { - program_id: instruction.token_program_id, + program_account_id: instruction.token_program_id.into(), pre_states: vec![receiver_authorized, vault_pre.clone()], instruction_data: transfer_instruction, pda_seeds: vec![PdaSeed::new([1_u8; 32])], diff --git a/lee/state_machine/test_methods/guest/src/bin/flash_swap_initiator.rs b/lee/state_machine/test_methods/guest/src/bin/flash_swap_initiator.rs index 699d7c579..03910ec82 100644 --- a/lee/state_machine/test_methods/guest/src/bin/flash_swap_initiator.rs +++ b/lee/state_machine/test_methods/guest/src/bin/flash_swap_initiator.rs @@ -124,7 +124,7 @@ fn main() { let transfer_instruction = risc0_zkvm::serde::to_vec(&amount_out).expect("transfer instruction serialization"); let call_1 = ChainedCall { - program_id: token_program_id, + program_account_id: token_program_id.into(), pre_states: vec![vault_authorized, receiver_pre.clone()], instruction_data: transfer_instruction, pda_seeds: vec![PdaSeed::new([0_u8; 32])], @@ -134,7 +134,7 @@ fn main() { // Receives the post-transfer states as its pre_states. The callback may run // arbitrary logic (arbitrage, etc.) and is expected to return funds to the vault. let call_2 = ChainedCall { - program_id: callback_program_id, + program_account_id: callback_program_id.into(), pre_states: vec![vault_after_transfer, receiver_after_transfer], instruction_data: callback_instruction_data, pda_seeds: vec![], @@ -152,7 +152,7 @@ fn main() { }) .expect("invariant instruction serialization"); let call_3 = ChainedCall { - program_id: self_program_id, // self-referential chained call + program_account_id: self_program_id.into(), // self-referential chained call pre_states: vec![vault_after_callback], instruction_data: invariant_instruction, pda_seeds: vec![], diff --git a/lee/state_machine/test_methods/guest/src/bin/malicious_authorization_changer.rs b/lee/state_machine/test_methods/guest/src/bin/malicious_authorization_changer.rs index 80bd8aaa7..19e7362cb 100644 --- a/lee/state_machine/test_methods/guest/src/bin/malicious_authorization_changer.rs +++ b/lee/state_machine/test_methods/guest/src/bin/malicious_authorization_changer.rs @@ -35,7 +35,7 @@ fn main() { let instruction_data = to_vec(&balance).unwrap(); let chained_call = ChainedCall { - program_id: transfer_program_id, + program_account_id: transfer_program_id.into(), instruction_data, pre_states: vec![authorised_sender, receiver.clone()], pda_seeds: vec![], diff --git a/lee/state_machine/test_methods/guest/src/bin/malicious_injector.rs b/lee/state_machine/test_methods/guest/src/bin/malicious_injector.rs index c5b367fc9..a83752fd0 100644 --- a/lee/state_machine/test_methods/guest/src/bin/malicious_injector.rs +++ b/lee/state_machine/test_methods/guest/src/bin/malicious_injector.rs @@ -96,7 +96,7 @@ fn main() { post_states, ) .with_chained_calls(vec![ChainedCall { - program_id: p2_id, + program_account_id: p2_id.into(), pre_states: vec![victim, recipient], instruction_data: p2_instruction, pda_seeds: vec![], diff --git a/lee/state_machine/test_methods/guest/src/bin/malicious_launderer.rs b/lee/state_machine/test_methods/guest/src/bin/malicious_launderer.rs index 5ec7989d2..cc1fdd7d8 100644 --- a/lee/state_machine/test_methods/guest/src/bin/malicious_launderer.rs +++ b/lee/state_machine/test_methods/guest/src/bin/malicious_launderer.rs @@ -33,7 +33,7 @@ fn main() { vec![], ) .with_chained_calls(vec![ChainedCall { - program_id: simple_transfer_id, + program_account_id: simple_transfer_id.into(), pre_states, instruction_data: auth_transfer_instruction, pda_seeds: vec![], diff --git a/lee/state_machine/test_methods/guest/src/bin/pda_spend_proxy.rs b/lee/state_machine/test_methods/guest/src/bin/pda_spend_proxy.rs index 86ef73b4a..497119cc1 100644 --- a/lee/state_machine/test_methods/guest/src/bin/pda_spend_proxy.rs +++ b/lee/state_machine/test_methods/guest/src/bin/pda_spend_proxy.rs @@ -31,7 +31,7 @@ fn main() { first_for_callee.is_authorized = true; let chained_call = ChainedCall { - program_id: simple_transfer_id, + program_account_id: simple_transfer_id.into(), instruction_data: to_vec(&amount).unwrap(), pre_states: vec![first_for_callee, second.clone()], pda_seeds: vec![seed], diff --git a/lee/state_machine/test_methods/guest/src/bin/private_pda_delegator.rs b/lee/state_machine/test_methods/guest/src/bin/private_pda_delegator.rs index 3b891e9af..20fea644e 100644 --- a/lee/state_machine/test_methods/guest/src/bin/private_pda_delegator.rs +++ b/lee/state_machine/test_methods/guest/src/bin/private_pda_delegator.rs @@ -33,7 +33,7 @@ fn main() { pre_for_callee.account.program_owner = self_program_id.into(); let chained_call = ChainedCall { - program_id: callee_program_id, + program_account_id: callee_program_id.into(), instruction_data: to_vec(&()).unwrap(), pre_states: vec![pre_for_callee], pda_seeds: vec![delegated_seed], diff --git a/lee/state_machine/test_methods/guest/src/bin/simple_transfer_proxy.rs b/lee/state_machine/test_methods/guest/src/bin/simple_transfer_proxy.rs index c6789161e..ce6b11d17 100644 --- a/lee/state_machine/test_methods/guest/src/bin/simple_transfer_proxy.rs +++ b/lee/state_machine/test_methods/guest/src/bin/simple_transfer_proxy.rs @@ -56,7 +56,7 @@ fn main() { let mut auth_pda_pre = pda_pre; auth_pda_pre.is_authorized = true; let auth_call = ChainedCall::new( - simple_transfer_id, + simple_transfer_id.into(), vec![auth_pda_pre, recipient_pre], &amount, ) @@ -83,7 +83,7 @@ fn main() { // to authorize the PDA. simple_transfer will claim it with Claim::Authorized. let mut auth_pda_pre = pda_pre; auth_pda_pre.is_authorized = true; - let auth_call = ChainedCall::new(simple_transfer_id, vec![auth_pda_pre], &amount) + let auth_call = ChainedCall::new(simple_transfer_id.into(), vec![auth_pda_pre], &amount) .with_pda_seeds(vec![pda_seed]); ProgramOutput::new( diff --git a/lee/state_machine/test_methods/guest/src/bin/validity_window_chain_caller.rs b/lee/state_machine/test_methods/guest/src/bin/validity_window_chain_caller.rs index 91b2deada..63c131797 100644 --- a/lee/state_machine/test_methods/guest/src/bin/validity_window_chain_caller.rs +++ b/lee/state_machine/test_methods/guest/src/bin/validity_window_chain_caller.rs @@ -33,7 +33,7 @@ fn main() { )) .unwrap(); let chained_call = ChainedCall { - program_id: chained_program_id, + program_account_id: chained_program_id.into(), instruction_data: chained_instruction, pre_states, pda_seeds: vec![], diff --git a/lez/common/src/test_utils.rs b/lez/common/src/test_utils.rs index 4a9ab9929..f29e62fcd 100644 --- a/lez/common/src/test_utils.rs +++ b/lez/common/src/test_utils.rs @@ -83,7 +83,7 @@ pub fn produce_dummy_empty_transaction() -> LeeTransaction { let account_ids = vec![]; let nonces = vec![]; let message = lee::public_transaction::Message::try_new( - program_id, + program_id.into(), account_ids, nonces, authenticated_transfer_core::Instruction::Initialize, @@ -109,7 +109,7 @@ pub fn create_transaction_native_token_transfer( let nonces = vec![nonce.into()]; let program_id = programs::authenticated_transfer().id(); let message = lee::public_transaction::Message::try_new( - program_id, + program_id.into(), account_ids, nonces, authenticated_transfer_core::Instruction::Transfer { diff --git a/lez/common/src/transaction.rs b/lez/common/src/transaction.rs index 9970bf7d7..8a8bd02a7 100644 --- a/lez/common/src/transaction.rs +++ b/lez/common/src/transaction.rs @@ -232,7 +232,7 @@ pub enum TransactionMalformationError { #[must_use] pub fn clock_invocation(timestamp: clock_core::Instruction) -> lee::PublicTransaction { let message = lee::public_transaction::Message::try_new( - programs::clock().id(), + programs::clock().id().into(), clock_core::CLOCK_PROGRAM_ACCOUNT_IDS.to_vec(), vec![], timestamp, diff --git a/lez/cross_zone/src/lib.rs b/lez/cross_zone/src/lib.rs index 681b2a6aa..d765cc165 100644 --- a/lez/cross_zone/src/lib.rs +++ b/lez/cross_zone/src/lib.rs @@ -136,7 +136,7 @@ fn build_inbox_dispatch_tx( account_ids.extend(target_account_ids); let message = lee::public_transaction::Message::try_new( - inbox_id, + inbox_id.into(), account_ids, vec![], Instruction::Dispatch(msg.clone()), @@ -335,9 +335,13 @@ fn genesis_public_tx( account_ids: Vec, instruction: I, ) -> lee::PublicTransaction { - let message = - lee::public_transaction::Message::try_new(program_id, account_ids, vec![], instruction) - .expect("genesis instruction must serialize"); + let message = lee::public_transaction::Message::try_new( + program_id.into(), + account_ids, + vec![], + instruction, + ) + .expect("genesis instruction must serialize"); lee::PublicTransaction::new( message, lee::public_transaction::WitnessSet::from_raw_parts(vec![]), diff --git a/lez/explorer_service/src/components/transaction_details.rs b/lez/explorer_service/src/components/transaction_details.rs index 01e5bc485..3fe780967 100644 --- a/lez/explorer_service/src/components/transaction_details.rs +++ b/lez/explorer_service/src/components/transaction_details.rs @@ -15,7 +15,7 @@ pub fn PublicTxDetails(tx: PublicTransaction) -> impl IntoView { witness_set, } = tx; let PublicMessage { - program_id, + program_account_id, account_ids, nonces, instruction_data, @@ -25,7 +25,7 @@ pub fn PublicTxDetails(tx: PublicTransaction) -> impl IntoView { proof, } = witness_set; - let program_id_str = program_id.to_string(); + let program_id_str = program_account_id.to_string(); let proof_len = proof.map_or(0, |p| p.0.len()); let signatures_count = signatures_and_public_keys.len(); diff --git a/lez/indexer/core/src/cross_zone_verifier.rs b/lez/indexer/core/src/cross_zone_verifier.rs index f22f45713..0e2a39f43 100644 --- a/lez/indexer/core/src/cross_zone_verifier.rs +++ b/lez/indexer/core/src/cross_zone_verifier.rs @@ -24,7 +24,7 @@ use cross_zone_inbox_core::{ CrossZoneMessage, Instruction as InboxInstruction, MessageKey, ZoneId, message_key, }; use futures::{Stream, StreamExt as _}; -use lee::{GENESIS_BLOCK_ID, PublicKey}; +use lee::{GENESIS_BLOCK_ID, ProgramId, PublicKey}; use log::{debug, error, warn}; use logos_blockchain_core::mantle::ops::channel::ChannelId; use logos_blockchain_zone_sdk::{ @@ -799,7 +799,7 @@ impl CrossZoneVerifier { let LeeTransaction::Public(public_tx) = tx else { return None; }; - if public_tx.message().program_id != programs::cross_zone_inbox().id() { + if public_tx.message().program_account_id != programs::cross_zone_inbox().id().into() { return None; } match risc0_zkvm::serde::from_slice::( @@ -855,8 +855,9 @@ impl CrossZoneVerifier { )); }; let message = emission_tx.message(); + let message_program_id = ProgramId::from(message.program_account_id); let emission = - extract_emission(message.program_id, &message.instruction_data).ok_or_else(|| { + extract_emission(message_program_id, &message.instruction_data).ok_or_else(|| { forged( msg, "peer transaction at src_tx_index is not a recognized emitter".to_owned(), @@ -882,7 +883,7 @@ impl CrossZoneVerifier { src_block_id: msg.src_block_id, src_block_hash: peer_block.recompute_hash().0, src_tx_index: msg.src_tx_index, - src_program_id: message.program_id, + src_program_id: message_program_id, }, emission.target_program_id, &emission.target_accounts, diff --git a/lez/indexer/ffi/indexer_ffi.h b/lez/indexer/ffi/indexer_ffi.h index 561c5e5f2..417ca73cf 100644 --- a/lez/indexer/ffi/indexer_ffi.h +++ b/lez/indexer/ffi/indexer_ffi.h @@ -125,13 +125,6 @@ typedef struct FfiBlockHeader { FfiSignature signature; } FfiBlockHeader; -/** - * Program ID - 8 u32 values (32 bytes total). - */ -typedef struct FfiProgramId { - uint32_t data[8]; -} FfiProgramId; - typedef struct FfiBytes32 FfiAccountId; typedef struct FfiVec_FfiAccountId { @@ -168,7 +161,7 @@ typedef struct FfiVec_u32 { typedef struct FfiVec_u32 FfiInstructionDataList; typedef struct FfiPublicMessage { - struct FfiProgramId program_id; + struct FfiBytes32 program_account_id; FfiAccountIdList account_ids; FfiNonceList nonces; FfiInstructionDataList instruction_data; diff --git a/lez/indexer/ffi/src/api/types/transaction.rs b/lez/indexer/ffi/src/api/types/transaction.rs index 83f50ede5..1dcf826bd 100644 --- a/lez/indexer/ffi/src/api/types/transaction.rs +++ b/lez/indexer/ffi/src/api/types/transaction.rs @@ -2,13 +2,12 @@ use indexer_service_protocol::{ AccountId, Ciphertext, Commitment, CommitmentSetDigest, EncryptedAccountData, EphemeralPublicKey, HashType, Nullifier, PrivacyPreservingMessage, PrivacyPreservingTransaction, PrivateAction, ProgramDeploymentMessage, - ProgramDeploymentTransaction, ProgramId, Proof, PublicActionWithID, PublicKey, PublicMessage, + ProgramDeploymentTransaction, Proof, PublicActionWithID, PublicKey, PublicMessage, PublicTransaction, Signature, Transaction, ValidityWindow, WitnessSet, }; use crate::api::types::{ - FfiAccountId, FfiBytes32, FfiHashType, FfiOption, FfiProgramId, FfiPublicKey, FfiSignature, - FfiVec, + FfiAccountId, FfiBytes32, FfiHashType, FfiOption, FfiPublicKey, FfiSignature, FfiVec, account::FfiAccount, vectors::{ FfiAccountIdList, FfiInstructionDataList, FfiNonceList, FfiPrivateActionList, @@ -50,7 +49,9 @@ impl From> for PublicTransaction { Self { hash: HashType(value.hash.data), message: PublicMessage { - program_id: ProgramId(value.message.program_id.data), + program_account_id: AccountId { + value: value.message.program_account_id.data, + }, account_ids: { let std_vec: Vec<_> = value.message.account_ids.into(); std_vec @@ -87,7 +88,7 @@ impl From> for PublicTransaction { #[repr(C)] pub struct FfiPublicMessage { - pub program_id: FfiProgramId, + pub program_account_id: FfiBytes32, pub account_ids: FfiAccountIdList, pub nonces: FfiNonceList, pub instruction_data: FfiInstructionDataList, @@ -96,14 +97,14 @@ pub struct FfiPublicMessage { impl From for FfiPublicMessage { fn from(value: PublicMessage) -> Self { let PublicMessage { - program_id, + program_account_id, account_ids, nonces, instruction_data, } = value; Self { - program_id: program_id.into(), + program_account_id: program_account_id.into(), account_ids: account_ids .into_iter() .map(Into::into) diff --git a/lez/indexer/service/protocol/src/convert.rs b/lez/indexer/service/protocol/src/convert.rs index c77c93d52..c4a3674f1 100644 --- a/lez/indexer/service/protocol/src/convert.rs +++ b/lez/indexer/service/protocol/src/convert.rs @@ -246,13 +246,13 @@ impl From impl From for PublicMessage { fn from(value: lee::public_transaction::Message) -> Self { let lee::public_transaction::Message { - program_id, + program_account_id, account_ids, nonces, instruction_data, } = value; Self { - program_id: program_id.into(), + program_account_id: program_account_id.into(), account_ids: account_ids.into_iter().map(Into::into).collect(), nonces: nonces.iter().map(|x| x.0).collect(), instruction_data, @@ -263,13 +263,13 @@ impl From for PublicMessage { impl From for lee::public_transaction::Message { fn from(value: PublicMessage) -> Self { let PublicMessage { - program_id, + program_account_id, account_ids, nonces, instruction_data, } = value; Self::new_preserialized( - program_id.into(), + program_account_id.into(), account_ids.into_iter().map(Into::into).collect(), nonces .iter() diff --git a/lez/indexer/service/protocol/src/lib.rs b/lez/indexer/service/protocol/src/lib.rs index 6f5df0461..28bc84051 100644 --- a/lez/indexer/service/protocol/src/lib.rs +++ b/lez/indexer/service/protocol/src/lib.rs @@ -218,7 +218,7 @@ pub struct PrivacyPreservingTransaction { #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)] pub struct PublicMessage { - pub program_id: ProgramId, + pub program_account_id: AccountId, pub account_ids: Vec, pub nonces: Vec, pub instruction_data: InstructionData, diff --git a/lez/indexer/service/src/mock_service.rs b/lez/indexer/service/src/mock_service.rs index e810e9a9d..9f24599e1 100644 --- a/lez/indexer/service/src/mock_service.rs +++ b/lez/indexer/service/src/mock_service.rs @@ -12,8 +12,8 @@ use indexer_service_protocol::{ Account, AccountId, BedrockStatus, Block, BlockBody, BlockHeader, BlockId, Commitment, CommitmentSetDigest, Data, EncryptedAccountData, HashType, IndexerStatus, IndexerSyncState, PrivacyPreservingMessage, PrivacyPreservingTransaction, PrivateAction, - ProgramDeploymentMessage, ProgramDeploymentTransaction, ProgramId, PublicActionWithID, - PublicMessage, PublicTransaction, Signature, Transaction, ValidityWindow, WitnessSet, + ProgramDeploymentMessage, ProgramDeploymentTransaction, PublicActionWithID, PublicMessage, + PublicTransaction, Signature, Transaction, ValidityWindow, WitnessSet, }; use jsonrpsee::{ core::{SubscriptionResult, async_trait}, @@ -363,7 +363,7 @@ fn mock_public_tx( Transaction::Public(PublicTransaction { hash: tx_hash, message: PublicMessage { - program_id: ProgramId([1_u32; 8]), + program_account_id: AccountId { value: [1_u8; 32] }, account_ids: vec![ account_ids[tx_idx as usize % account_ids.len()], account_ids[(tx_idx as usize + 1) % account_ids.len()], diff --git a/lez/programs/amm/src/add.rs b/lez/programs/amm/src/add.rs index f3f76f8d6..4d4d3f740 100644 --- a/lez/programs/amm/src/add.rs +++ b/lez/programs/amm/src/add.rs @@ -138,7 +138,7 @@ pub fn add_liquidity( // Chain call for Token A (UserHoldingA -> Vault_A) let call_token_a = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_holding_a.clone(), vault_a.clone()], &token_core::Instruction::Transfer { amount_to_transfer: actual_amount_a, @@ -146,7 +146,7 @@ pub fn add_liquidity( ); // Chain call for Token B (UserHoldingB -> Vault_B) let call_token_b = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_holding_b.clone(), vault_b.clone()], &token_core::Instruction::Transfer { amount_to_transfer: actual_amount_b, @@ -156,7 +156,7 @@ pub fn add_liquidity( let mut pool_definition_lp_auth = pool_definition_lp.clone(); pool_definition_lp_auth.is_authorized = true; let call_token_lp = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![pool_definition_lp_auth, user_holding_lp.clone()], &token_core::Instruction::Mint { amount_to_mint: delta_lp, diff --git a/lez/programs/amm/src/new_definition.rs b/lez/programs/amm/src/new_definition.rs index 37099adbe..ab9210575 100644 --- a/lez/programs/amm/src/new_definition.rs +++ b/lez/programs/amm/src/new_definition.rs @@ -121,7 +121,7 @@ pub fn new_definition( ..vault_a.clone() }; let call_token_a = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_holding_a.clone(), vault_a_authorized], &token_core::Instruction::Transfer { amount_to_transfer: token_a_amount.into(), @@ -136,7 +136,7 @@ pub fn new_definition( ..vault_b.clone() }; let call_token_b = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_holding_b.clone(), vault_b_authorized], &token_core::Instruction::Transfer { amount_to_transfer: token_b_amount.into(), @@ -150,7 +150,7 @@ pub fn new_definition( ..pool_definition_lp.clone() }; let call_token_lp = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![pool_lp_authorized, user_holding_lp.clone()], &instruction, ) diff --git a/lez/programs/amm/src/remove.rs b/lez/programs/amm/src/remove.rs index 18d60d140..fbf1733f8 100644 --- a/lez/programs/amm/src/remove.rs +++ b/lez/programs/amm/src/remove.rs @@ -118,7 +118,7 @@ pub fn remove_liquidity( // Chaincall for Token A withdraw let call_token_a = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![running_vault_a, user_holding_a.clone()], &token_core::Instruction::Transfer { amount_to_transfer: withdraw_amount_a, @@ -130,7 +130,7 @@ pub fn remove_liquidity( )]); // Chaincall for Token B withdraw let call_token_b = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![running_vault_b, user_holding_b.clone()], &token_core::Instruction::Transfer { amount_to_transfer: withdraw_amount_b, @@ -144,7 +144,7 @@ pub fn remove_liquidity( let mut pool_definition_lp_auth = pool_definition_lp.clone(); pool_definition_lp_auth.is_authorized = true; let call_token_lp = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![pool_definition_lp_auth, user_holding_lp.clone()], &token_core::Instruction::Burn { amount_to_burn: delta_lp, diff --git a/lez/programs/amm/src/swap.rs b/lez/programs/amm/src/swap.rs index 42bc451ae..c232f1a74 100644 --- a/lez/programs/amm/src/swap.rs +++ b/lez/programs/amm/src/swap.rs @@ -186,7 +186,7 @@ fn swap_logic( let mut chained_calls = Vec::new(); chained_calls.push(ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_deposit, vault_deposit], &token_core::Instruction::Transfer { amount_to_transfer: swap_amount_in, @@ -205,7 +205,7 @@ fn swap_logic( chained_calls.push( ChainedCall::new( - token_program_id, + token_program_id.into(), vec![vault_withdraw, user_withdraw], &token_core::Instruction::Transfer { amount_to_transfer: withdraw_amount, @@ -318,7 +318,7 @@ fn exact_output_swap_logic( let mut chained_calls = Vec::new(); chained_calls.push(ChainedCall::new( - token_program_id, + token_program_id.into(), vec![user_deposit, vault_deposit], &token_core::Instruction::Transfer { amount_to_transfer: deposit_amount, @@ -337,7 +337,7 @@ fn exact_output_swap_logic( chained_calls.push( ChainedCall::new( - token_program_id, + token_program_id.into(), vec![vault_withdraw, user_withdraw], &token_core::Instruction::Transfer { amount_to_transfer: exact_amount_out, diff --git a/lez/programs/amm/src/tests.rs b/lez/programs/amm/src/tests.rs index 7f0b98b1f..a6c658628 100644 --- a/lez/programs/amm/src/tests.rs +++ b/lez/programs/amm/src/tests.rs @@ -186,7 +186,7 @@ impl BalanceForTests { impl ChainedCallForTests { fn cc_swap_token_a_test_1() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_a(), AccountWithMetadataForTests::vault_a_init(), @@ -204,7 +204,7 @@ impl ChainedCallForTests { vault_b_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_b_auth, AccountWithMetadataForTests::user_holding_b()], &token_core::Instruction::Transfer { amount_to_transfer: swap_amount, @@ -223,7 +223,7 @@ impl ChainedCallForTests { vault_a_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_a_auth, AccountWithMetadataForTests::user_holding_a()], &token_core::Instruction::Transfer { amount_to_transfer: swap_amount, @@ -237,7 +237,7 @@ impl ChainedCallForTests { fn cc_swap_token_b_test_2() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_b(), AccountWithMetadataForTests::vault_b_init(), @@ -252,7 +252,7 @@ impl ChainedCallForTests { let swap_amount: u128 = 498; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_a(), AccountWithMetadataForTests::vault_a_init(), @@ -270,7 +270,7 @@ impl ChainedCallForTests { vault_b_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_b_auth, AccountWithMetadataForTests::user_holding_b()], &token_core::Instruction::Transfer { amount_to_transfer: swap_amount, @@ -289,7 +289,7 @@ impl ChainedCallForTests { vault_a_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_a_auth, AccountWithMetadataForTests::user_holding_a()], &token_core::Instruction::Transfer { amount_to_transfer: swap_amount, @@ -305,7 +305,7 @@ impl ChainedCallForTests { let swap_amount: u128 = 200; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_b(), AccountWithMetadataForTests::vault_b_init(), @@ -318,7 +318,7 @@ impl ChainedCallForTests { fn cc_add_token_a() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_a(), AccountWithMetadataForTests::vault_a_init(), @@ -331,7 +331,7 @@ impl ChainedCallForTests { fn cc_add_token_b() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_b(), AccountWithMetadataForTests::vault_b_init(), @@ -347,7 +347,7 @@ impl ChainedCallForTests { pool_lp_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ pool_lp_auth, AccountWithMetadataForTests::user_holding_lp_init(), @@ -366,7 +366,7 @@ impl ChainedCallForTests { vault_a_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_a_auth, AccountWithMetadataForTests::user_holding_a()], &token_core::Instruction::Transfer { amount_to_transfer: BalanceForTests::remove_actual_a_successful(), @@ -383,7 +383,7 @@ impl ChainedCallForTests { vault_b_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![vault_b_auth, AccountWithMetadataForTests::user_holding_b()], &token_core::Instruction::Transfer { amount_to_transfer: 70, @@ -400,7 +400,7 @@ impl ChainedCallForTests { pool_lp_auth.is_authorized = true; ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ pool_lp_auth, AccountWithMetadataForTests::user_holding_lp_init(), @@ -416,7 +416,7 @@ impl ChainedCallForTests { fn cc_new_definition_token_a() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_a(), AccountWithMetadataForTests::vault_a_init(), @@ -429,7 +429,7 @@ impl ChainedCallForTests { fn cc_new_definition_token_b() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::user_holding_b(), AccountWithMetadataForTests::vault_b_init(), @@ -442,7 +442,7 @@ impl ChainedCallForTests { fn cc_new_definition_token_lp() -> ChainedCall { ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::pool_lp_init(), AccountWithMetadataForTests::user_holding_lp_uninit(), @@ -3016,7 +3016,7 @@ fn new_definition_lp_symmetric_amounts() { let chained_call_lp = chained_calls[0].clone(); let expected_lp_call = ChainedCall::new( - TOKEN_PROGRAM_ID, + TOKEN_PROGRAM_ID.into(), vec![ AccountWithMetadataForTests::pool_lp_init(), AccountWithMetadataForTests::user_holding_lp_uninit(), @@ -3113,7 +3113,7 @@ fn simple_amm_remove() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3190,7 +3190,7 @@ fn simple_amm_new_definition_inactive_initialized_pool_and_uninit_user_lp() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3275,7 +3275,7 @@ fn simple_amm_new_definition_inactive_initialized_pool_init_user_lp() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3347,7 +3347,7 @@ fn simple_amm_new_definition_uninitialized_pool() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3410,7 +3410,7 @@ fn simple_amm_add() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3472,7 +3472,7 @@ fn simple_amm_swap_1() { }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), @@ -3522,7 +3522,7 @@ fn simple_amm_swap_2() { token_definition_id_in: IdForExeTests::token_a_definition_id(), }; let message = public_transaction::Message::try_new( - programs::amm().id(), + programs::amm().id().into(), vec![ IdForExeTests::pool_definition_id(), IdForExeTests::vault_a_id(), diff --git a/lez/programs/associated_token_account/src/burn.rs b/lez/programs/associated_token_account/src/burn.rs index 3102e29f9..27cb572ff 100644 --- a/lez/programs/associated_token_account/src/burn.rs +++ b/lez/programs/associated_token_account/src/burn.rs @@ -32,7 +32,7 @@ pub fn burn_from_associated_token_account( holder_ata_auth.is_authorized = true; let chained_call = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![token_definition.clone(), holder_ata_auth], &token_core::Instruction::Burn { amount_to_burn: amount, diff --git a/lez/programs/associated_token_account/src/create.rs b/lez/programs/associated_token_account/src/create.rs index e19fc3198..5077c720b 100644 --- a/lez/programs/associated_token_account/src/create.rs +++ b/lez/programs/associated_token_account/src/create.rs @@ -41,7 +41,7 @@ pub fn create_associated_token_account( ..ata_account.clone() }; let chained_call = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![token_definition.clone(), ata_account_auth], &token_core::Instruction::InitializeAccount, ) diff --git a/lez/programs/associated_token_account/src/tests.rs b/lez/programs/associated_token_account/src/tests.rs index 46e1afa80..749cff417 100644 --- a/lez/programs/associated_token_account/src/tests.rs +++ b/lez/programs/associated_token_account/src/tests.rs @@ -82,7 +82,7 @@ fn create_emits_chained_call_for_uninitialized_ata() { assert_eq!(post_states.len(), 3); assert_eq!(chained_calls.len(), 1); - assert_eq!(chained_calls[0].program_id, TOKEN_PROGRAM_ID); + assert_eq!(chained_calls[0].program_account_id, TOKEN_PROGRAM_ID.into()); } #[test] diff --git a/lez/programs/associated_token_account/src/transfer.rs b/lez/programs/associated_token_account/src/transfer.rs index ecdfeae93..dc87d3329 100644 --- a/lez/programs/associated_token_account/src/transfer.rs +++ b/lez/programs/associated_token_account/src/transfer.rs @@ -32,7 +32,7 @@ pub fn transfer_from_associated_token_account( sender_ata_auth.is_authorized = true; let chained_call = ChainedCall::new( - token_program_id, + token_program_id.into(), vec![sender_ata_auth, recipient.clone()], &token_core::Instruction::Transfer { amount_to_transfer: amount, diff --git a/lez/programs/bridge/src/main.rs b/lez/programs/bridge/src/main.rs index 1fd3333a0..1c8f3ca2f 100644 --- a/lez/programs/bridge/src/main.rs +++ b/lez/programs/bridge/src/main.rs @@ -91,7 +91,7 @@ fn main() { bridge_for_vault.is_authorized = true; let chained_calls = vec![ ChainedCall::new( - vault_program_id, + vault_program_id.into(), vec![bridge_for_vault, recipient_vault], &vault_core::Instruction::Transfer { recipient_id, diff --git a/lez/programs/bridge_lock/src/main.rs b/lez/programs/bridge_lock/src/main.rs index 5e0e9e24c..4e6e7b7b9 100644 --- a/lez/programs/bridge_lock/src/main.rs +++ b/lez/programs/bridge_lock/src/main.rs @@ -165,7 +165,7 @@ fn lock( AccountPostState::new_claimed_if_default(escrow_account, Claim::Pda(escrow_seed())); let call = ChainedCall::new( - outbox_program_id, + outbox_program_id.into(), vec![outbox.clone()], &OutboxInstruction::Emit { target_zone, diff --git a/lez/programs/cross_zone_inbox/src/main.rs b/lez/programs/cross_zone_inbox/src/main.rs index 638ad75f3..feba302bd 100644 --- a/lez/programs/cross_zone_inbox/src/main.rs +++ b/lez/programs/cross_zone_inbox/src/main.rs @@ -155,7 +155,7 @@ fn dispatch( let mut call_pre_states = vec![marker.clone()]; call_pre_states.extend(target_accounts.clone()); let call = ChainedCall { - program_id: msg.target_program_id, + program_account_id: msg.target_program_id.into(), pre_states: call_pre_states, instruction_data, pda_seeds: vec![], diff --git a/lez/programs/faucet/src/main.rs b/lez/programs/faucet/src/main.rs index 3646382d1..11bbbce74 100644 --- a/lez/programs/faucet/src/main.rs +++ b/lez/programs/faucet/src/main.rs @@ -52,7 +52,7 @@ fn main() { vec![ ChainedCall::new( - vault_program_id, + vault_program_id.into(), vec![faucet_for_vault, recipient_vault], &vault_core::Instruction::Transfer { recipient_id, @@ -78,7 +78,7 @@ fn main() { vec![ ChainedCall::new( - faucet_for_transfer.account.program_owner.into(), + faucet_for_transfer.account.program_owner, vec![faucet_for_transfer, recipient], &authenticated_transfer_core::Instruction::Transfer { amount }, ) diff --git a/lez/programs/pinata_token/src/main.rs b/lez/programs/pinata_token/src/main.rs index 7e7fd97d6..784112cb8 100644 --- a/lez/programs/pinata_token/src/main.rs +++ b/lez/programs/pinata_token/src/main.rs @@ -87,7 +87,7 @@ fn main() { pinata_token_holding_for_chain_call.is_authorized = true; let chained_call = ChainedCall::new( - pinata_token_holding_post.program_owner.into(), + pinata_token_holding_post.program_owner, vec![ pinata_token_holding_for_chain_call, winner_token_holding.clone(), diff --git a/lez/programs/ping_sender/src/main.rs b/lez/programs/ping_sender/src/main.rs index d2b1baedb..f9682745b 100644 --- a/lez/programs/ping_sender/src/main.rs +++ b/lez/programs/ping_sender/src/main.rs @@ -85,7 +85,7 @@ fn send( read_outbox(&config.account.data).expect("config account holds an outbox program id"); let call = ChainedCall::new( - outbox_program_id, + outbox_program_id.into(), vec![outbox.clone()], &OutboxInstruction::Emit { target_zone, diff --git a/lez/programs/vault/src/main.rs b/lez/programs/vault/src/main.rs index 89bde3638..929248665 100644 --- a/lez/programs/vault/src/main.rs +++ b/lez/programs/vault/src/main.rs @@ -49,7 +49,7 @@ fn main() { vec![ ChainedCall::new( - sender.account.program_owner.into(), + sender.account.program_owner, vec![sender, recipient_vault_for_callee], &AuthTransferInstruction::Transfer { amount }, ) @@ -73,7 +73,7 @@ fn main() { vec![ ChainedCall::new( - owner_vault_for_callee.account.program_owner.into(), + owner_vault_for_callee.account.program_owner, vec![owner_vault_for_callee, owner], &AuthTransferInstruction::Transfer { amount }, ) diff --git a/lez/sequencer/actors/executor/src/tests.rs b/lez/sequencer/actors/executor/src/tests.rs index ec72c28aa..26d55e7a3 100644 --- a/lez/sequencer/actors/executor/src/tests.rs +++ b/lez/sequencer/actors/executor/src/tests.rs @@ -59,7 +59,7 @@ fn test_transaction() -> LeeTransaction { let nonces = vec![0_u128.into(), 0_u128.into()]; let instruction = 1337; let message = Message::try_new( - test_programs::simple_balance_transfer().id(), + test_programs::simple_balance_transfer().id().into(), vec![acc1, acc2], nonces, instruction, diff --git a/lez/sequencer/actors/rpc_server/src/actor/service.rs b/lez/sequencer/actors/rpc_server/src/actor/service.rs index d423d40ab..6c3afc892 100644 --- a/lez/sequencer/actors/rpc_server/src/actor/service.rs +++ b/lez/sequencer/actors/rpc_server/src/actor/service.rs @@ -83,7 +83,9 @@ impl sequencer_service_rpc::Rpc // an inbound cross-zone delivery. Chained user calls are already rejected // by the inbox guest's caller-is-none assertion. if let LeeTransaction::Public(public_tx) = &authenticated_tx - && sequencer_core::is_sequencer_only_program(public_tx.message().program_id) + && sequencer_core::is_sequencer_only_program(lee::ProgramId::from( + public_tx.message().program_account_id, + )) { return Err(ErrorObjectOwned::owned( ErrorCode::InvalidParams.code(), diff --git a/lez/sequencer/core/src/cross_zone_watcher.rs b/lez/sequencer/core/src/cross_zone_watcher.rs index c03cbf789..112e08146 100644 --- a/lez/sequencer/core/src/cross_zone_watcher.rs +++ b/lez/sequencer/core/src/cross_zone_watcher.rs @@ -534,7 +534,8 @@ async fn record_block_deliveries( continue; }; let message = public_tx.message(); - let Some(emission) = extract_emission(message.program_id, &message.instruction_data) else { + let message_program_id = lee_core::program::ProgramId::from(message.program_account_id); + let Some(emission) = extract_emission(message_program_id, &message.instruction_data) else { continue; }; @@ -562,7 +563,7 @@ async fn record_block_deliveries( src_block_id: block.header.block_id, src_block_hash: block_hash.0, src_tx_index, - src_program_id: message.program_id, + src_program_id: message_program_id, }, emission.target_program_id, &emission.target_accounts, diff --git a/lez/sequencer/core/src/lib.rs b/lez/sequencer/core/src/lib.rs index 7b7b7db85..5d7115054 100644 --- a/lez/sequencer/core/src/lib.rs +++ b/lez/sequencer/core/src/lib.rs @@ -2085,7 +2085,7 @@ fn build_supply_account_genesis_transaction( let recipient_vault_id = vault_core::compute_vault_account_id(vault_program_id, *account_id); let message = Message::try_new( - faucet_program_id, + faucet_program_id.into(), vec![system_accounts::faucet_account_id(), recipient_vault_id], Vec::new(), faucet_core::Instruction::GenesisTransferVault { @@ -2105,7 +2105,7 @@ fn build_supply_bridge_account_genesis_transaction(balance: u128) -> PublicTrans let bridge_account_id = system_accounts::bridge_account_id(); let message = Message::try_new( - faucet_program_id, + faucet_program_id.into(), vec![system_accounts::faucet_account_id(), bridge_account_id], Vec::new(), faucet_core::Instruction::GenesisTransferDirect { amount: balance }, @@ -2139,7 +2139,7 @@ fn build_bridge_deposit_tx_from_event(event: &PendingDepositEventRecord) -> Resu bridge_core::deposit_receipt_account_id(bridge_program_id, event.deposit_op_id.0); let message = Message::try_new( - bridge_program_id, + bridge_program_id.into(), vec![ system_accounts::bridge_account_id(), recipient_vault_id, @@ -2259,7 +2259,7 @@ fn resubmittable_txs(block: &Block) -> Vec { #[must_use] fn is_sequencer_only_tx(tx: &LeeTransaction) -> bool { matches!(tx, LeeTransaction::Public(tx) - if is_sequencer_only_program(tx.message().program_id)) + if is_sequencer_only_program(lee::ProgramId::from(tx.message().program_account_id))) } /// The cross-zone message an inbox dispatch delivers, or `None` if `tx` is not @@ -2271,7 +2271,7 @@ fn extract_cross_zone_dispatch(tx: &LeeTransaction) -> Option }; let message = tx.message(); - if message.program_id != programs::cross_zone_inbox().id() { + if message.program_account_id != programs::cross_zone_inbox().id().into() { return None; } @@ -2379,7 +2379,7 @@ fn extract_bridge_deposit_id(tx: &LeeTransaction) -> Option { }; let message = tx.message(); - if message.program_id != programs::bridge().id() { + if message.program_account_id != programs::bridge().id().into() { return None; } @@ -2402,7 +2402,7 @@ fn extract_bridge_withdraw_data(tx: &LeeTransaction) -> Option { }; let message = tx.message(); - if message.program_id != programs::bridge().id() { + if message.program_account_id != programs::bridge().id().into() { return None; } diff --git a/lez/sequencer/core/src/tests.rs b/lez/sequencer/core/src/tests.rs index fcd9fd428..54c373c42 100644 --- a/lez/sequencer/core/src/tests.rs +++ b/lez/sequencer/core/src/tests.rs @@ -219,7 +219,7 @@ fn tx_is_bridge_deposit( return false; }; - if public_tx.message.program_id != programs::bridge().id() { + if public_tx.message.program_account_id != programs::bridge().id().into() { return false; } @@ -1623,7 +1623,7 @@ async fn transactions_touching_clock_account_are_dropped_from_block() { // be dropped because their diffs touch the clock accounts. let crafted_clock_tx = { let message = lee::public_transaction::Message::try_new( - programs::clock().id(), + programs::clock().id().into(), system_accounts::clock_account_ids().to_vec(), vec![], 42_u64, @@ -1686,7 +1686,7 @@ async fn user_tx_that_chain_calls_clock_is_dropped() { let timestamp: u64 = 0; let message = lee::public_transaction::Message::try_new( - clock_chain_caller_id, + clock_chain_caller_id.into(), system_accounts::clock_account_ids().to_vec(), vec![], // no signers (clock_program_id, timestamp), @@ -1865,7 +1865,7 @@ fn time_locked_transfer_transaction( ) -> PublicTransaction { let program_id = test_programs::time_locked_transfer().id(); let message = lee::public_transaction::Message::try_new( - program_id, + program_id.into(), vec![from, to, clock_account_id], vec![Nonce(from_nonce)], (amount, deadline), @@ -1992,7 +1992,7 @@ fn pinata_cooldown_transaction( ) -> PublicTransaction { let program_id = test_programs::pinata_cooldown().id(); let message = lee::public_transaction::Message::try_new( - program_id, + program_id.into(), vec![pinata_id, winner_id, clock_account_id], vec![], (), @@ -2177,7 +2177,7 @@ fn pda_mechanism_with_pinata_token_program() { // Submit a solution to the pinata program to claim the prize let solution: u128 = 989_106; let message = lee::public_transaction::Message::try_new( - pinata_token.id(), + pinata_token.id().into(), vec![ pinata_definition_id, pinata_token_holding_id, @@ -2213,7 +2213,7 @@ fn resubmittable_txs_drops_clock_and_bridge_deposits() { .unwrap(); let withdraw_tx = { let message = lee::public_transaction::Message::try_new( - programs::bridge().id(), + programs::bridge().id().into(), vec![system_accounts::bridge_account_id()], vec![], bridge_core::Instruction::Withdraw { diff --git a/lez/wallet/src/lib.rs b/lez/wallet/src/lib.rs index 56a673b82..5889334ed 100644 --- a/lez/wallet/src/lib.rs +++ b/lez/wallet/src/lib.rs @@ -860,7 +860,7 @@ impl WalletCore { let nonces = acc_manager.public_account_nonces(); let message = lee::public_transaction::Message::new_preserialized( - program_id, + program_id.into(), account_ids, nonces, instruction_data, diff --git a/test_programs/guest/src/bin/chain_caller.rs b/test_programs/guest/src/bin/chain_caller.rs index 0473f1d24..155bf8fcf 100644 --- a/test_programs/guest/src/bin/chain_caller.rs +++ b/test_programs/guest/src/bin/chain_caller.rs @@ -37,7 +37,7 @@ fn main() { let mut chained_calls = Vec::new(); for _i in 0..num_chain_calls { let new_chained_call = ChainedCall { - program_id: auth_transfer_id, + program_account_id: auth_transfer_id.into(), instruction_data: instruction_data.clone(), pre_states: vec![running_sender_pre.clone(), running_recipient_pre.clone()], /* <- Account order permutation here */ pda_seeds: pda_seed.iter().copied().collect(), diff --git a/test_programs/guest/src/bin/clock_chain_caller.rs b/test_programs/guest/src/bin/clock_chain_caller.rs index fc9b81c35..43303308f 100644 --- a/test_programs/guest/src/bin/clock_chain_caller.rs +++ b/test_programs/guest/src/bin/clock_chain_caller.rs @@ -28,7 +28,7 @@ fn main() { .collect(); let chained_call = ChainedCall { - program_id: clock_program_id, + program_account_id: clock_program_id.into(), instruction_data: to_vec(×tamp).unwrap(), pre_states: pre_states.clone(), pda_seeds: vec![], diff --git a/test_programs/guest/src/bin/faucet_chain_caller.rs b/test_programs/guest/src/bin/faucet_chain_caller.rs index 0b320a75d..d71c50bab 100644 --- a/test_programs/guest/src/bin/faucet_chain_caller.rs +++ b/test_programs/guest/src/bin/faucet_chain_caller.rs @@ -29,7 +29,7 @@ fn main() { let [faucet_pre, vault_pda_pre] = [pre_states[0].clone(), pre_states[1].clone()]; let chained_calls = vec![ChainedCall { - program_id: faucet_program_id, + program_account_id: faucet_program_id.into(), instruction_data: to_vec(&faucet_core::Instruction::GenesisTransferVault { vault_program_id, recipient_id, diff --git a/test_programs/guest/src/bin/pda_spend_proxy.rs b/test_programs/guest/src/bin/pda_spend_proxy.rs index 0b4c89145..6bea40bd1 100644 --- a/test_programs/guest/src/bin/pda_spend_proxy.rs +++ b/test_programs/guest/src/bin/pda_spend_proxy.rs @@ -31,7 +31,7 @@ fn main() { first_for_callee.is_authorized = true; let chained_call = ChainedCall { - program_id: auth_transfer_id, + program_account_id: auth_transfer_id.into(), instruction_data: to_vec(&authenticated_transfer_core::Instruction::Transfer { amount }) .unwrap(), pre_states: vec![first_for_callee, second.clone()], diff --git a/tools/cross_zone_chat/src/main.rs b/tools/cross_zone_chat/src/main.rs index 3ed3d1253..ddc0b0f5c 100644 --- a/tools/cross_zone_chat/src/main.rs +++ b/tools/cross_zone_chat/src/main.rs @@ -467,16 +467,16 @@ async fn scan_zone(state: Arc, label: &'static str) { let LeeTransaction::Public(public) = tx else { continue; }; - let program_id = public.message.program_id; + let program_id = public.message.program_account_id; let data = &public.message.instruction_data; // A tx targets at most one of these programs; check both // independently rather than chaining (avoids an empty else). - if program_id == inbox_id + if program_id == inbox_id.into() && let Some(text) = decode_inbox_text(data) { state.mark_delivered(label, &text, next); } - if program_id == sender_id + if program_id == sender_id.into() && let Some(ordinal) = decode_send_ordinal(data) { state.mark_source_block(label, ordinal, next); @@ -576,7 +576,7 @@ fn build_send_tx(other_zone: ZoneId, ordinal: u32, text: &str) -> LeeTransaction let sender_id = programs::ping_sender().id(); let outbox_account = outbox_pda(outbox_id, sender_id, &other_zone, ordinal); let message = Message::try_new( - sender_id, + sender_id.into(), vec![sender_config_account_id(sender_id), outbox_account], vec![], send,