diff --git a/.changelog/unreleased/improvements/2182-tx-type-tag2.md b/.changelog/unreleased/improvements/2182-tx-type-tag2.md new file mode 100644 index 0000000000..2df5a5375d --- /dev/null +++ b/.changelog/unreleased/improvements/2182-tx-type-tag2.md @@ -0,0 +1,3 @@ +- Added type tags to transactions to enable hardware wallets + to fully decode transactions even after minor Namada updates. + ([\#2182](https://github.com/anoma/namada/pull/2182)) \ No newline at end of file diff --git a/apps/src/lib/bench_utils.rs b/apps/src/lib/bench_utils.rs index f6213e7920..10b4eb549b 100644 --- a/apps/src/lib/bench_utils.rs +++ b/apps/src/lib/bench_utils.rs @@ -79,6 +79,19 @@ use namada::{proof_of_stake, tendermint}; use namada_sdk::masp::{ self, ShieldedContext, ShieldedTransfer, ShieldedUtils, }; +pub use namada_sdk::tx::{ + TX_BOND_WASM, TX_BRIDGE_POOL_WASM, + TX_CHANGE_COMMISSION_WASM as TX_CHANGE_VALIDATOR_COMMISSION_WASM, + TX_CHANGE_CONSENSUS_KEY_WASM, + TX_CHANGE_METADATA_WASM as TX_CHANGE_VALIDATOR_METADATA_WASM, + TX_CLAIM_REWARDS_WASM, TX_DEACTIVATE_VALIDATOR_WASM, TX_IBC_WASM, + TX_INIT_ACCOUNT_WASM, TX_INIT_PROPOSAL as TX_INIT_PROPOSAL_WASM, + TX_INIT_VALIDATOR_WASM, TX_REACTIVATE_VALIDATOR_WASM, TX_REDELEGATE_WASM, + TX_RESIGN_STEWARD, TX_REVEAL_PK as TX_REVEAL_PK_WASM, TX_TRANSFER_WASM, + TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, + TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL as TX_VOTE_PROPOSAL_WASM, + TX_WITHDRAW_WASM, VP_USER_WASM, VP_VALIDATOR_WASM, +}; use namada_sdk::wallet::Wallet; use namada_sdk::NamadaImpl; use namada_test_utils::tx_data::TxWriteData; @@ -97,33 +110,6 @@ use crate::node::ledger::shell::Shell; use crate::wallet::{defaults, CliWalletUtils}; pub const WASM_DIR: &str = "../wasm"; -pub const TX_BOND_WASM: &str = "tx_bond.wasm"; -pub const TX_TRANSFER_WASM: &str = "tx_transfer.wasm"; -pub const TX_UPDATE_ACCOUNT_WASM: &str = "tx_update_account.wasm"; -pub const TX_VOTE_PROPOSAL_WASM: &str = "tx_vote_proposal.wasm"; -pub const TX_UNBOND_WASM: &str = "tx_unbond.wasm"; -pub const TX_REDELEGATE_WASM: &str = "tx_redelegate.wasm"; -pub const TX_INIT_PROPOSAL_WASM: &str = "tx_init_proposal.wasm"; -pub const TX_REVEAL_PK_WASM: &str = "tx_reveal_pk.wasm"; -pub const TX_CHANGE_CONSENSUS_KEY_WASM: &str = "tx_change_consensus_key.wasm"; -pub const TX_CHANGE_VALIDATOR_COMMISSION_WASM: &str = - "tx_change_validator_commission.wasm"; -pub const TX_CHANGE_VALIDATOR_METADATA_WASM: &str = - "tx_change_validator_metadata.wasm"; -pub const TX_IBC_WASM: &str = "tx_ibc.wasm"; -pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm"; -pub const TX_DEACTIVATE_VALIDATOR_WASM: &str = "tx_deactivate_validator.wasm"; -pub const TX_REACTIVATE_VALIDATOR_WASM: &str = "tx_reactivate_validator.wasm"; -pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm"; -pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm"; -pub const TX_INIT_ACCOUNT_WASM: &str = "tx_init_account.wasm"; -pub const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm"; - -pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm"; -pub const TX_UPDATE_STEWARD_COMMISSION: &str = - "tx_update_steward_commission.wasm"; -pub const TX_BRIDGE_POOL_WASM: &str = "tx_bridge_pool.wasm"; -pub const VP_VALIDATOR_WASM: &str = "vp_validator.wasm"; pub const ALBERT_PAYMENT_ADDRESS: &str = "albert_payment"; pub const ALBERT_SPENDING_KEY: &str = "albert_spending"; @@ -248,7 +234,10 @@ impl Default for BenchShell { bench_shell.wl_storage.commit_tx(); // Initialize governance proposal - let content_section = Section::ExtraData(Code::new(vec![])); + let content_section = Section::ExtraData(Code::new( + vec![], + Some(TX_INIT_PROPOSAL_WASM.to_string()), + )); let voting_start_epoch = Epoch(2 + params.pipeline_len + params.unbonding_len); let signed_tx = bench_shell.generate_tx( @@ -306,7 +295,10 @@ impl BenchShell { let code_hash = self .read_storage_key(&Key::wasm_hash(wasm_code_path)) .unwrap(); - tx.set_code(Code::from_hash(code_hash)); + tx.set_code(Code::from_hash( + code_hash, + Some(wasm_code_path.to_string()), + )); tx.set_data(Data::new(borsh::to_vec(&data).unwrap())); if let Some(transaction) = shielded { @@ -341,7 +333,10 @@ impl BenchShell { let code_hash = self .read_storage_key(&Key::wasm_hash(wasm_code_path)) .unwrap(); - tx.set_code(Code::from_hash(code_hash)); + tx.set_code(Code::from_hash( + code_hash, + Some(wasm_code_path.to_string()), + )); let mut data = vec![]; prost::Message::encode(&msg.to_any(), &mut data).unwrap(); @@ -569,7 +564,7 @@ pub fn generate_foreign_key_tx(signer: &SecretKey) -> Tx { let mut tx = Tx::from_type(namada::types::transaction::TxType::Decrypted( namada::types::transaction::DecryptedTx::Decrypted, )); - tx.set_code(Code::new(wasm_code)); + tx.set_code(Code::new(wasm_code, None)); tx.set_data(Data::new( TxWriteData { key: Key::from("bench_foreign_key".to_string().to_db_key()), diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 22d3b2ea3e..3bb7f5c7ad 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2832,6 +2832,17 @@ pub mod args { use namada::types::token::NATIVE_MAX_DECIMAL_PLACES; use namada::types::transaction::GasLimit; pub use namada_sdk::args::*; + pub use namada_sdk::tx::{ + TX_BOND_WASM, TX_BRIDGE_POOL_WASM, TX_CHANGE_COMMISSION_WASM, + TX_CHANGE_CONSENSUS_KEY_WASM, TX_CHANGE_METADATA_WASM, + TX_CLAIM_REWARDS_WASM, TX_DEACTIVATE_VALIDATOR_WASM, TX_IBC_WASM, + TX_INIT_ACCOUNT_WASM, TX_INIT_PROPOSAL, TX_INIT_VALIDATOR_WASM, + TX_REACTIVATE_VALIDATOR_WASM, TX_REDELEGATE_WASM, TX_RESIGN_STEWARD, + TX_REVEAL_PK, TX_TRANSFER_WASM, TX_UNBOND_WASM, + TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, + TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, + VP_USER_WASM, + }; use super::context::*; use super::utils::*; @@ -2841,37 +2852,6 @@ pub mod args { use crate::facade::tendermint::Timeout; use crate::facade::tendermint_config::net::Address as TendermintAddress; - pub const TX_BOND_WASM: &str = "tx_bond.wasm"; - pub const TX_BRIDGE_POOL_WASM: &str = "tx_bridge_pool.wasm"; - pub const TX_CHANGE_COMMISSION_WASM: &str = - "tx_change_validator_commission.wasm"; - pub const TX_CHANGE_CONSENSUS_KEY_WASM: &str = - "tx_change_consensus_key.wasm"; - pub const TX_CHANGE_METADATA_WASM: &str = - "tx_change_validator_metadata.wasm"; - pub const TX_DEACTIVATE_VALIDATOR_WASM: &str = - "tx_deactivate_validator.wasm"; - pub const TX_IBC_WASM: &str = "tx_ibc.wasm"; - pub const TX_INIT_ACCOUNT_WASM: &str = "tx_init_account.wasm"; - pub const TX_INIT_PROPOSAL: &str = "tx_init_proposal.wasm"; - pub const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm"; - pub const TX_REVEAL_PK: &str = "tx_reveal_pk.wasm"; - pub const TX_UPDATE_ACCOUNT_WASM: &str = "tx_update_account.wasm"; - pub const TX_TRANSFER_WASM: &str = "tx_transfer.wasm"; - pub const TX_UNBOND_WASM: &str = "tx_unbond.wasm"; - pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm"; - pub const TX_REACTIVATE_VALIDATOR_WASM: &str = - "tx_reactivate_validator.wasm"; - pub const TX_REDELEGATE_WASM: &str = "tx_redelegate.wasm"; - pub const TX_UPDATE_STEWARD_COMMISSION: &str = - "tx_update_steward_commission.wasm"; - pub const TX_VOTE_PROPOSAL: &str = "tx_vote_proposal.wasm"; - pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm"; - pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm"; - pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm"; - - pub const VP_USER_WASM: &str = "vp_user.wasm"; - pub const ADDRESS: Arg = arg("address"); pub const ALIAS_OPT: ArgOpt = ALIAS.opt(); pub const ALIAS: Arg = arg("alias"); diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index cc972ca5d0..0317ec43f3 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -230,6 +230,8 @@ pub async fn submit_reveal_aux<'a>( sign(context, &mut tx, &args, signing_data).await?; + signing::generate_test_vector(context, &tx).await?; + context.submit(tx, &args).await?; } } @@ -253,6 +255,8 @@ pub async fn submit_bridge_pool_tx<'a, N: Namada<'a>>( sign(namada, &mut tx, &tx_args, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &tx_args).await?; } @@ -277,6 +281,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -299,6 +305,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -322,6 +330,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -419,7 +429,11 @@ pub async fn submit_change_consensus_key<'a>( consensus_key: new_ck, }; - tx.add_code_from_hash(tx_code_hash).add_data(data); + tx.add_code_from_hash( + tx_code_hash, + Some(args::TX_CHANGE_CONSENSUS_KEY_WASM.to_string()), + ) + .add_data(data); let signing_data = aux_signing_data(namada, &tx_args, None, None).await?; tx::prepare_tx( @@ -687,8 +701,10 @@ pub async fn submit_init_validator<'a>( let chain_id = tx_args.chain_id.clone().unwrap(); let mut tx = Tx::new(chain_id, tx_args.expiration); - let extra_section_hash = - tx.add_extra_section_from_hash(validator_vp_code_hash); + let extra_section_hash = tx.add_extra_section_from_hash( + validator_vp_code_hash, + Some(validator_vp_code_path.to_string_lossy().into_owned()), + ); let data = InitValidator { account_keys, @@ -715,7 +731,11 @@ pub async fn submit_init_validator<'a>( all_pks.push(eth_hot_pk); all_pks.push(data.protocol_key.clone()); - tx.add_code_from_hash(tx_code_hash).add_data(data); + tx.add_code_from_hash( + tx_code_hash, + Some(args::TX_INIT_VALIDATOR_WASM.to_string()), + ) + .add_data(data); let signing_data = init_validator_signing_data(namada, &tx_args, all_pks).await?; @@ -736,6 +756,8 @@ pub async fn submit_init_validator<'a>( } else { sign(namada, &mut tx, &tx_args, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + let result = namada.submit(tx, &tx_args).await?.initialized_accounts(); if !tx_args.dry_run { @@ -857,6 +879,8 @@ pub async fn submit_transfer<'a>( } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + let result = namada.submit(tx, &args.tx).await?; let submission_epoch = rpc::query_and_print_epoch(namada).await; @@ -903,6 +927,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1030,6 +1056,8 @@ where } else { sign(namada, &mut tx_builder, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx_builder).await?; + namada.submit(tx_builder, &args.tx).await?; } @@ -1108,6 +1136,8 @@ where } else { sign(namada, &mut tx_builder, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx_builder).await?; + namada.submit(tx_builder, &args.tx).await?; } @@ -1226,6 +1256,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1248,6 +1280,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; tx::query_unbonds(namada, args.clone(), latest_withdrawal_pre).await?; @@ -1272,6 +1306,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1294,6 +1330,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1315,6 +1353,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1337,6 +1377,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1359,6 +1401,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1403,6 +1447,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1425,6 +1471,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1447,6 +1495,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1470,6 +1520,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } @@ -1492,6 +1544,8 @@ where } else { sign(namada, &mut tx, &args.tx, signing_data).await?; + signing::generate_test_vector(namada, &tx).await?; + namada.submit(tx, &args.tx).await?; } diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 206a35f67d..0833f5fb85 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -973,7 +973,7 @@ mod test_finalize_block { None, )))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx.set_data(Data::new( "Encrypted transaction data".as_bytes().to_owned(), )); @@ -1014,7 +1014,7 @@ mod test_finalize_block { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new( "Decrypted transaction data".as_bytes().to_owned(), )); @@ -1129,7 +1129,7 @@ mod test_finalize_block { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new( String::from("transaction data").as_bytes().to_owned(), )); @@ -2906,7 +2906,7 @@ mod test_finalize_block { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new(tx_code)); + wrapper.set_code(Code::new(tx_code, None)); wrapper.set_data(Data::new( "Decrypted transaction data".as_bytes().to_owned(), )); @@ -3036,7 +3036,7 @@ mod test_finalize_block { )))); unsigned_wrapper.header.chain_id = shell.chain_id.clone(); let mut failing_wrapper = unsigned_wrapper.clone(); - unsigned_wrapper.set_code(Code::new(tx_code)); + unsigned_wrapper.set_code(Code::new(tx_code, None)); let addr = Address::from(&keypair.to_public()); let key = Key::from(addr.to_db_key()) .join(&Key::from("test".to_string().to_db_key())); @@ -3051,7 +3051,7 @@ mod test_finalize_block { wasm_path.push("wasm_for_tests/tx_fail.wasm"); let tx_code = std::fs::read(wasm_path) .expect("Expected a file at given code path"); - failing_wrapper.set_code(Code::new(tx_code)); + failing_wrapper.set_code(Code::new(tx_code, None)); failing_wrapper.set_data(Data::new( "Encrypted transaction data".as_bytes().to_owned(), )); @@ -3211,7 +3211,7 @@ mod test_finalize_block { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new( "Encrypted transaction data".as_bytes().to_owned(), )); @@ -3290,7 +3290,7 @@ mod test_finalize_block { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new( "Encrypted transaction data".as_bytes().to_owned(), )); @@ -3373,7 +3373,7 @@ mod test_finalize_block { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new(tx_code)); + wrapper.set_code(Code::new(tx_code, None)); wrapper.set_data(Data::new( "Enxrypted transaction data".as_bytes().to_owned(), )); @@ -4900,7 +4900,7 @@ mod test_finalize_block { .write(&proposal_execution_key, 0u64) .expect("Test failed."); let mut tx = Tx::new(shell.chain_id.clone(), None); - tx.add_code_from_hash(Hash::default()).add_data(0u64); + tx.add_code_from_hash(Hash::default(), None).add_data(0u64); let new_min_confirmations = MinimumConfirmations::from(unsafe { NonZeroU64::new_unchecked(42) }); diff --git a/apps/src/lib/node/ledger/shell/governance.rs b/apps/src/lib/node/ledger/shell/governance.rs index 9cad57168e..0bbdac54ce 100644 --- a/apps/src/lib/node/ledger/shell/governance.rs +++ b/apps/src/lib/node/ledger/shell/governance.rs @@ -273,7 +273,7 @@ where let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); tx.header.chain_id = shell.chain_id.clone(); tx.set_data(Data::new(encode(&id))); - tx.set_code(Code::new(code)); + tx.set_code(Code::new(code, None)); let tx_result = protocol::dispatch_tx( tx, diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 8d63086be0..fa5891c215 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -1403,6 +1403,7 @@ where let unshield = wrapper .check_and_generate_fee_unshielding( transfer_code_hash, + Some(namada_sdk::tx::TX_TRANSFER_WASM.to_string()), descriptions_limit, transaction, ) @@ -2073,7 +2074,7 @@ mod test_utils { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); shell.wl_storage.storage.tx_queue.push(TxInQueue { @@ -2492,7 +2493,8 @@ mod shell_tests { None, )))); unsigned_wrapper.header.chain_id = shell.chain_id.clone(); - unsigned_wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + unsigned_wrapper + .set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); unsigned_wrapper .set_data(Data::new("transaction data".as_bytes().to_owned())); @@ -2528,7 +2530,8 @@ mod shell_tests { None, )))); invalid_wrapper.header.chain_id = shell.chain_id.clone(); - invalid_wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + invalid_wrapper + .set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); invalid_wrapper .set_data(Data::new("transaction data".as_bytes().to_owned())); invalid_wrapper.add_section(Section::Signature(Signature::new( @@ -2561,7 +2564,7 @@ mod shell_tests { let (shell, _recv, _, _) = test_utils::setup(); let mut tx = Tx::new(shell.chain_id.clone(), None); - tx.add_code("wasm_code".as_bytes().to_owned()); + tx.add_code("wasm_code".as_bytes().to_owned(), None); let result = shell.mempool_validate( tx.to_bytes().as_ref(), @@ -2596,7 +2599,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2696,7 +2699,7 @@ mod shell_tests { let wrong_chain_id = ChainId("Wrong chain id".to_string()); let mut tx = Tx::new(wrong_chain_id.clone(), None); - tx.add_code("wasm_code".as_bytes().to_owned()) + tx.add_code("wasm_code".as_bytes().to_owned(), None) .add_data("transaction data".as_bytes().to_owned()) .sign_wrapper(keypair); @@ -2724,7 +2727,7 @@ mod shell_tests { let mut tx = Tx::new(shell.chain_id.clone(), Some(DateTimeUtc::default())); - tx.add_code("wasm_code".as_bytes().to_owned()) + tx.add_code("wasm_code".as_bytes().to_owned(), None) .add_data("transaction data".as_bytes().to_owned()) .sign_wrapper(keypair); @@ -2757,7 +2760,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2790,7 +2793,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2823,7 +2826,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2858,7 +2861,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2892,7 +2895,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2926,7 +2929,7 @@ mod shell_tests { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index ca9bc70114..baf77012d8 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -458,7 +458,7 @@ mod test_prepare_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction_data".as_bytes().to_owned())); let wrapper = wrapper.to_bytes(); #[allow(clippy::redundant_clone)] @@ -756,7 +756,7 @@ mod test_prepare_proposal { None, )))); tx.header.chain_id = shell.chain_id.clone(); - tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); tx.set_data(Data::new( format!("transaction data: {}", i).as_bytes().to_owned(), )); @@ -825,7 +825,7 @@ mod test_prepare_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -872,7 +872,7 @@ mod test_prepare_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -907,7 +907,7 @@ mod test_prepare_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -955,7 +955,7 @@ mod test_prepare_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - let tx_code = Code::new("wasm_code".as_bytes().to_owned()); + let tx_code = Code::new("wasm_code".as_bytes().to_owned(), None); wrapper.set_code(tx_code); let tx_data = Data::new("transaction data".as_bytes().to_owned()); wrapper.set_data(tx_data); @@ -1008,7 +1008,7 @@ mod test_prepare_proposal { )))); wrapper_tx.header.chain_id = shell.chain_id.clone(); wrapper_tx.header.expiration = Some(DateTimeUtc::default()); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1057,7 +1057,7 @@ mod test_prepare_proposal { ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1097,7 +1097,7 @@ mod test_prepare_proposal { let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1146,7 +1146,7 @@ mod test_prepare_proposal { let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1187,7 +1187,7 @@ mod test_prepare_proposal { let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1237,7 +1237,7 @@ mod test_prepare_proposal { ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1277,7 +1277,7 @@ mod test_prepare_proposal { ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1316,7 +1316,7 @@ mod test_prepare_proposal { ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( @@ -1355,7 +1355,7 @@ mod test_prepare_proposal { ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); wrapper_tx.header.chain_id = shell.chain_id.clone(); - wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper_tx.add_section(Section::Signature(Signature::new( diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index d446a75cc1..785eabb04f 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -688,7 +688,7 @@ mod test_process_proposal { use namada::types::token; use namada::types::token::Amount; use namada::types::transaction::protocol::EthereumTxData; - use namada::types::transaction::{Fee, Solution, WrapperTx}; + use namada::types::transaction::{Fee, WrapperTx}; use namada::types::vote_extensions::{bridge_pool_roots, ethereum_events}; use super::*; @@ -930,7 +930,7 @@ mod test_process_proposal { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); let tx = outer_tx.to_bytes(); @@ -981,7 +981,7 @@ mod test_process_proposal { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); outer_tx.add_section(Section::Signature(Signature::new( outer_tx.sechashes(), @@ -1053,7 +1053,7 @@ mod test_process_proposal { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); outer_tx.add_section(Section::Signature(Signature::new( outer_tx.sechashes(), @@ -1119,7 +1119,7 @@ mod test_process_proposal { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); outer_tx.add_section(Section::Signature(Signature::new( outer_tx.sechashes(), @@ -1175,7 +1175,8 @@ mod test_process_proposal { None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); - outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + outer_tx + .set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); outer_tx.set_data(Data::new( format!("transaction data: {}", i).as_bytes().to_owned(), )); @@ -1233,7 +1234,7 @@ mod test_process_proposal { None, )))); tx.header.chain_id = shell.chain_id.clone(); - tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); let gas_limit = Gas::from(tx.header().wrapper().unwrap().gas_limit) .checked_sub(Gas::from(tx.to_bytes().len() as u64)) @@ -1284,7 +1285,6 @@ mod test_process_proposal { epoch: Epoch(0), gas_limit: GAS_LIMIT_MULTIPLIER.into(), unshield_section_hash: None, - pow_solution: Solution::None, }; let tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); @@ -1309,7 +1309,7 @@ mod test_process_proposal { let (shell, _recv, _, _) = test_utils::setup_at_height(3u64); let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); tx.header.chain_id = shell.chain_id.clone(); - tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); + tx.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); let request = ProcessProposal { @@ -1341,7 +1341,7 @@ mod test_process_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); let mut tx = Tx::new(shell.chain_id.clone(), None); - tx.add_code("wasm_code".as_bytes().to_owned()) + tx.add_code("wasm_code".as_bytes().to_owned(), None) .add_data("transaction data".as_bytes().to_owned()) .sign_wrapper(keypair); @@ -1392,7 +1392,7 @@ mod test_process_proposal { )))); wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), [(0, keypair)].into_iter().collect(), @@ -1466,7 +1466,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1518,7 +1518,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1582,7 +1582,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); let mut new_wrapper = wrapper.clone(); wrapper.add_section(Section::Signature(Signature::new( @@ -1637,7 +1637,7 @@ mod test_process_proposal { )))); let wrong_chain_id = ChainId("Wrong chain id".to_string()); wrapper.header.chain_id = wrong_chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1698,7 +1698,7 @@ mod test_process_proposal { )))); wrapper.header.chain_id = shell.chain_id.clone(); wrapper.header.expiration = Some(DateTimeUtc::default()); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1744,7 +1744,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1786,7 +1786,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1827,7 +1827,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1870,7 +1870,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1913,7 +1913,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -1956,7 +1956,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), @@ -2002,7 +2002,7 @@ mod test_process_proposal { None, )))); wrapper.header.chain_id = shell.chain_id.clone(); - wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); + wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned(), None)); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); wrapper.add_section(Section::Signature(Signature::new( wrapper.sechashes(), diff --git a/benches/native_vps.rs b/benches/native_vps.rs index a1527af096..fdaed5d1f9 100644 --- a/benches/native_vps.rs +++ b/benches/native_vps.rs @@ -108,7 +108,8 @@ fn governance(c: &mut Criterion) { ) } "minimal_proposal" => { - let content_section = Section::ExtraData(Code::new(vec![])); + let content_section = + Section::ExtraData(Code::new(vec![], None)); let params = proof_of_stake::read_pos_params(&shell.wl_storage).unwrap(); let voting_start_epoch = @@ -151,13 +152,14 @@ fn governance(c: &mut Criterion) { .expect( "Missing max_proposal_content parameter in storage", ); - let content_section = Section::ExtraData(Code::new(vec![ - 0; - max_proposal_content_size - as _ - ])); - let wasm_code_section = - Section::ExtraData(Code::new(vec![0; max_code_size as _])); + let content_section = Section::ExtraData(Code::new( + vec![0; max_proposal_content_size as _], + None, + )); + let wasm_code_section = Section::ExtraData(Code::new( + vec![0; max_code_size as _], + None, + )); let params = proof_of_stake::read_pos_params(&shell.wl_storage).unwrap(); diff --git a/benches/txs.rs b/benches/txs.rs index 6751a52ada..02d6c9c22d 100644 --- a/benches/txs.rs +++ b/benches/txs.rs @@ -47,17 +47,15 @@ use namada_apps::bench_utils::{ TX_CHANGE_CONSENSUS_KEY_WASM, TX_CHANGE_VALIDATOR_COMMISSION_WASM, TX_CHANGE_VALIDATOR_METADATA_WASM, TX_CLAIM_REWARDS_WASM, TX_DEACTIVATE_VALIDATOR_WASM, TX_IBC_WASM, TX_INIT_ACCOUNT_WASM, - TX_INIT_PROPOSAL_WASM, TX_REACTIVATE_VALIDATOR_WASM, TX_REDELEGATE_WASM, - TX_RESIGN_STEWARD, TX_REVEAL_PK_WASM, TX_UNBOND_WASM, - TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, - TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL_WASM, TX_WITHDRAW_WASM, - VP_VALIDATOR_WASM, + TX_INIT_PROPOSAL_WASM, TX_INIT_VALIDATOR_WASM, + TX_REACTIVATE_VALIDATOR_WASM, TX_REDELEGATE_WASM, TX_RESIGN_STEWARD, + TX_REVEAL_PK_WASM, TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM, + TX_UPDATE_ACCOUNT_WASM, TX_UPDATE_STEWARD_COMMISSION, + TX_VOTE_PROPOSAL_WASM, TX_WITHDRAW_WASM, VP_VALIDATOR_WASM, }; use namada_apps::wallet::defaults; use sha2::Digest; -const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm"; - fn transfer(c: &mut Criterion) { let mut group = c.benchmark_group("transfer"); let amount = Amount::native_whole(500); @@ -373,7 +371,10 @@ fn update_account(c: &mut Criterion) { let vp_code_hash: Hash = shell .read_storage_key(&Key::wasm_hash(VP_VALIDATOR_WASM)) .unwrap(); - let extra_section = Section::ExtraData(Code::from_hash(vp_code_hash)); + let extra_section = Section::ExtraData(Code::from_hash( + vp_code_hash, + Some(VP_VALIDATOR_WASM.to_string()), + )); let data = UpdateAccount { addr: defaults::albert_address(), vp_code_hash: Some(Hash( @@ -413,7 +414,10 @@ fn init_account(c: &mut Criterion) { let vp_code_hash: Hash = shell .read_storage_key(&Key::wasm_hash(VP_VALIDATOR_WASM)) .unwrap(); - let extra_section = Section::ExtraData(Code::from_hash(vp_code_hash)); + let extra_section = Section::ExtraData(Code::from_hash( + vp_code_hash, + Some(VP_VALIDATOR_WASM.to_string()), + )); let extra_hash = Hash( extra_section .hash(&mut sha2::Sha256::new()) @@ -454,7 +458,7 @@ fn init_proposal(c: &mut Criterion) { let signed_tx = match bench_name { "minimal_proposal" => { let content_section = - Section::ExtraData(Code::new(vec![])); + Section::ExtraData(Code::new(vec![], None)); shell.generate_tx( TX_INIT_PROPOSAL_WASM, InitProposalData { @@ -497,13 +501,13 @@ fn init_proposal(c: &mut Criterion) { 0; max_proposal_content_size as _ - ])); + ], None)); let wasm_code_section = Section::ExtraData(Code::new(vec![ 0; max_code_size as _ - ])); + ], None)); shell.generate_tx( TX_INIT_PROPOSAL_WASM, @@ -611,8 +615,10 @@ fn init_validator(c: &mut Criterion) { let validator_vp_code_hash: Hash = shell .read_storage_key(&Key::wasm_hash(VP_VALIDATOR_WASM)) .unwrap(); - let extra_section = - Section::ExtraData(Code::from_hash(validator_vp_code_hash)); + let extra_section = Section::ExtraData(Code::from_hash( + validator_vp_code_hash, + Some(VP_VALIDATOR_WASM.to_string()), + )); let extra_hash = Hash( extra_section .hash(&mut sha2::Sha256::new()) diff --git a/benches/vps.rs b/benches/vps.rs index 9c1f188f03..d101b2a4a9 100644 --- a/benches/vps.rs +++ b/benches/vps.rs @@ -22,12 +22,11 @@ use namada_apps::bench_utils::{ generate_foreign_key_tx, BenchShell, TX_BOND_WASM, TX_CHANGE_VALIDATOR_COMMISSION_WASM, TX_REVEAL_PK_WASM, TX_TRANSFER_WASM, TX_UNBOND_WASM, TX_UPDATE_ACCOUNT_WASM, TX_VOTE_PROPOSAL_WASM, - VP_VALIDATOR_WASM, + VP_USER_WASM, VP_VALIDATOR_WASM, }; use namada_apps::wallet::defaults; use sha2::Digest; -const VP_USER_WASM: &str = "vp_user.wasm"; const VP_IMPLICIT_WASM: &str = "vp_implicit.wasm"; fn vp_user(c: &mut Criterion) { @@ -73,7 +72,10 @@ fn vp_user(c: &mut Criterion) { let vp_validator_hash = shell .read_storage_key(&Key::wasm_hash(VP_VALIDATOR_WASM)) .unwrap(); - let extra_section = Section::ExtraData(Code::from_hash(vp_validator_hash)); + let extra_section = Section::ExtraData(Code::from_hash( + vp_validator_hash, + Some(VP_VALIDATOR_WASM.to_string()), + )); let data = UpdateAccount { addr: defaults::albert_address(), vp_code_hash: Some(Hash( @@ -357,7 +359,10 @@ fn vp_validator(c: &mut Criterion) { vec![&defaults::bertha_keypair()], ); - let extra_section = Section::ExtraData(Code::from_hash(vp_code_hash)); + let extra_section = Section::ExtraData(Code::from_hash( + vp_code_hash, + Some(VP_VALIDATOR_WASM.to_string()), + )); let data = UpdateAccount { addr: defaults::validator_address(), vp_code_hash: Some(Hash( diff --git a/core/src/ledger/tx_env.rs b/core/src/ledger/tx_env.rs index 4b87d97f7c..83f566bfaf 100644 --- a/core/src/ledger/tx_env.rs +++ b/core/src/ledger/tx_env.rs @@ -40,7 +40,8 @@ pub trait TxEnv: StorageRead + StorageWrite { /// writes the given code as its validity predicate into the storage. fn init_account( &mut self, - code: impl AsRef<[u8]>, + code_hash: impl AsRef<[u8]>, + code_tag: &Option, ) -> Result; /// Update a validity predicate @@ -48,6 +49,7 @@ pub trait TxEnv: StorageRead + StorageWrite { &mut self, addr: &Address, code: impl AsRef<[u8]>, + code_tag: &Option, ) -> Result<(), storage_api::Error>; /// Emit an IBC event. On multiple calls, these emitted event will be added. diff --git a/core/src/proto/types.rs b/core/src/proto/types.rs index 1ac9830ad6..97c16f1b1d 100644 --- a/core/src/proto/types.rs +++ b/core/src/proto/types.rs @@ -357,22 +357,29 @@ pub struct Code { pub salt: [u8; 8], /// Actual transaction code pub code: Commitment, + /// The tag for the transaction code + pub tag: Option, } impl Code { /// Make a new code section with the given bytes - pub fn new(code: Vec) -> Self { + pub fn new(code: Vec, tag: Option) -> Self { Self { salt: DateTimeUtc::now().0.timestamp_millis().to_le_bytes(), code: Commitment::Id(code), + tag, } } /// Make a new code section with the given hash - pub fn from_hash(hash: crate::types::hash::Hash) -> Self { + pub fn from_hash( + hash: crate::types::hash::Hash, + tag: Option, + ) -> Self { Self { salt: DateTimeUtc::now().0.timestamp_millis().to_le_bytes(), code: Commitment::Hash(hash), + tag, } } @@ -380,6 +387,7 @@ impl Code { pub fn hash<'a>(&self, hasher: &'a mut Sha256) -> &'a mut Sha256 { hasher.update(self.salt); hasher.update(self.code.hash()); + hasher.update(self.tag.serialize_to_vec()); hasher } } @@ -1456,9 +1464,10 @@ impl Tx { pub fn add_extra_section_from_hash( &mut self, hash: crate::types::hash::Hash, + tag: Option, ) -> crate::types::hash::Hash { let sechash = self - .add_section(Section::ExtraData(Code::from_hash(hash))) + .add_section(Section::ExtraData(Code::from_hash(hash, tag))) .get_hash(); sechash } @@ -1467,9 +1476,10 @@ impl Tx { pub fn add_extra_section( &mut self, code: Vec, + tag: Option, ) -> (&mut Self, crate::types::hash::Hash) { let sechash = self - .add_section(Section::ExtraData(Code::new(code))) + .add_section(Section::ExtraData(Code::new(code, tag))) .get_hash(); (self, sechash) } @@ -1493,14 +1503,19 @@ impl Tx { pub fn add_code_from_hash( &mut self, code_hash: crate::types::hash::Hash, + tag: Option, ) -> &mut Self { - self.set_code(Code::from_hash(code_hash)); + self.set_code(Code::from_hash(code_hash, tag)); self } /// Add wasm code to the tx builder - pub fn add_code(&mut self, code: Vec) -> &mut Self { - self.set_code(Code::new(code)); + pub fn add_code( + &mut self, + code: Vec, + tag: Option, + ) -> &mut Self { + self.set_code(Code::new(code, tag)); self } diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 12e2e94d3b..1ab89ba61f 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -209,7 +209,7 @@ mod test_process_tx { fn test_process_tx_raw_tx_no_data() { let mut outer_tx = Tx::from_type(TxType::Raw); let code_sec = outer_tx - .set_code(Code::new("wasm code".as_bytes().to_owned())) + .set_code(Code::new("wasm code".as_bytes().to_owned(), None)) .clone(); outer_tx.validate_tx().expect("Test failed"); match outer_tx.header().tx_type { @@ -227,7 +227,7 @@ mod test_process_tx { fn test_process_tx_raw_tx_some_data() { let mut tx = Tx::from_type(TxType::Raw); let code_sec = tx - .set_code(Code::new("wasm code".as_bytes().to_owned())) + .set_code(Code::new("wasm code".as_bytes().to_owned(), None)) .clone(); let data_sec = tx .set_data(Data::new("transaction data".as_bytes().to_owned())) @@ -249,7 +249,7 @@ mod test_process_tx { fn test_process_tx_raw_tx_some_signed_data() { let mut tx = Tx::from_type(TxType::Raw); let code_sec = tx - .set_code(Code::new("wasm code".as_bytes().to_owned())) + .set_code(Code::new("wasm code".as_bytes().to_owned(), None)) .clone(); let data_sec = tx .set_data(Data::new("transaction data".as_bytes().to_owned())) @@ -287,7 +287,7 @@ mod test_process_tx { Default::default(), None, )))); - tx.set_code(Code::new("wasm code".as_bytes().to_owned())); + tx.set_code(Code::new("wasm code".as_bytes().to_owned(), None)); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); tx.add_section(Section::Signature(Signature::new( tx.sechashes(), @@ -315,7 +315,7 @@ mod test_process_tx { Default::default(), None, )))); - tx.set_code(Code::new("wasm code".as_bytes().to_owned())); + tx.set_code(Code::new("wasm code".as_bytes().to_owned(), None)); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); let result = tx.validate_tx().expect_err("Test failed"); assert_matches!(result, TxError::SigError(_)); @@ -329,7 +329,7 @@ fn test_process_tx_decrypted_unsigned() { use crate::proto::{Code, Data, Tx}; let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); let code_sec = tx - .set_code(Code::new("transaction data".as_bytes().to_owned())) + .set_code(Code::new("transaction data".as_bytes().to_owned(), None)) .clone(); let data_sec = tx .set_data(Data::new("transaction data".as_bytes().to_owned())) @@ -377,7 +377,7 @@ fn test_process_tx_decrypted_signed() { decrypted.add_section(Section::Signature(sig_sec)); // create the tx with signed decrypted data let code_sec = decrypted - .set_code(Code::new("transaction data".as_bytes().to_owned())) + .set_code(Code::new("transaction data".as_bytes().to_owned(), None)) .clone(); let data_sec = decrypted .set_data(Data::new("transaction data".as_bytes().to_owned())) diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index f9b032b3f4..d66e61dcb3 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -163,21 +163,6 @@ pub mod wrapper_tx { } } - /// A degenerate PoW solution type - #[derive( - Debug, - Clone, - BorshSerialize, - BorshDeserialize, - BorshSchema, - Serialize, - Deserialize, - )] - pub enum Solution { - /// No PoW solution - None, - } - /// A transaction with an encrypted payload, an optional shielded pool /// unshielding tx for fee payment and some non-encrypted metadata for /// inclusion and / or verification purposes @@ -204,8 +189,6 @@ pub mod wrapper_tx { /// The hash of the optional, unencrypted, unshielding transaction for /// fee payment pub unshield_section_hash: Option, - /// Mandatory 0x00 byte for deprecated field - pub pow_solution: Solution, } impl WrapperTx { @@ -227,7 +210,6 @@ pub mod wrapper_tx { epoch, gas_limit, unshield_section_hash: unshield_hash, - pow_solution: Solution::None, } } @@ -251,6 +233,7 @@ pub mod wrapper_tx { pub fn check_and_generate_fee_unshielding( &self, transfer_code_hash: Hash, + transfer_code_tag: Option, descriptions_limit: u64, unshield: Transaction, ) -> Result { @@ -288,13 +271,18 @@ pub mod wrapper_tx { .to_string(), )); } - self.generate_fee_unshielding(transfer_code_hash, unshield) + self.generate_fee_unshielding( + transfer_code_hash, + transfer_code_tag, + unshield, + ) } /// Generates the fee unshielding tx for execution. pub fn generate_fee_unshielding( &self, transfer_code_hash: Hash, + transfer_code_tag: Option, unshield: Transaction, ) -> Result { let mut tx = @@ -322,7 +310,7 @@ pub mod wrapper_tx { }; let data = transfer.serialize_to_vec(); tx.set_data(Data::new(data)); - tx.set_code(Code::from_hash(transfer_code_hash)); + tx.set_code(Code::from_hash(transfer_code_hash, transfer_code_tag)); Ok(tx) } diff --git a/scripts/generator.sh b/scripts/generator.sh index 92c7226efe..1618d5fc9c 100755 --- a/scripts/generator.sh +++ b/scripts/generator.sh @@ -192,9 +192,9 @@ elif [ "$1" = "client" ]; then cargo run --bin namadac --features std -- update-account --code-path vp_user.wasm --address bertha --public-keys albert-key,bertha-key,christel-key --threshold 2 --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- init-validator --alias bertha-validator --account-keys bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys bertha-key --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- init-validator --email me@me.com --alias bertha-validator --account-keys bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys bertha-key --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- init-validator --alias validator-mult --account-keys albert-key,bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys albert-key,bertha-key --threshold 2 --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- init-validator --email me@me.com --alias validator-mult --account-keys albert-key,bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys albert-key,bertha-key --threshold 2 --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 # TODO works but panics cargo run --bin namadac --features std -- unbond --validator christel --amount 5 --signing-keys christel-key --force --ledger-address 127.0.0.1:27657 diff --git a/sdk/src/eth_bridge/bridge_pool.rs b/sdk/src/eth_bridge/bridge_pool.rs index de8de36ebe..e682521987 100644 --- a/sdk/src/eth_bridge/bridge_pool.rs +++ b/sdk/src/eth_bridge/bridge_pool.rs @@ -92,7 +92,11 @@ pub async fn build_bridge_pool_tx( .ok_or_else(|| Error::Other("No chain id available".into()))?; let mut tx = Tx::new(chain_id, tx_args.expiration); - tx.add_code_from_hash(tx_code_hash).add_data(transfer); + tx.add_code_from_hash( + tx_code_hash, + Some(code_path.to_string_lossy().into_owned()), + ) + .add_data(transfer); let epoch = prepare_tx( context, diff --git a/sdk/src/signing.rs b/sdk/src/signing.rs index bb21d2f661..6784be92ba 100644 --- a/sdk/src/signing.rs +++ b/sdk/src/signing.rs @@ -46,7 +46,7 @@ use crate::ibc_proto::google::protobuf::Any; use crate::io::*; use crate::masp::make_asset_type; use crate::proto::{MaspBuilder, Section, Tx}; -use crate::rpc::{query_wasm_code_hash, validate_amount}; +use crate::rpc::validate_amount; use crate::tx::{ TX_BOND_WASM, TX_CHANGE_COMMISSION_WASM, TX_CHANGE_CONSENSUS_KEY_WASM, TX_CHANGE_METADATA_WASM, TX_CLAIM_REWARDS_WASM, @@ -54,6 +54,7 @@ use crate::tx::{ TX_INIT_PROPOSAL, TX_INIT_VALIDATOR_WASM, TX_REACTIVATE_VALIDATOR_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM, TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, VP_USER_WASM, + VP_VALIDATOR_WASM, }; pub use crate::wallet::store::AddressVpType; use crate::wallet::{Wallet, WalletIo}; @@ -1017,38 +1018,6 @@ pub async fn to_ledger_vector<'a>( context: &impl Namada<'a>, tx: &Tx, ) -> Result { - let init_account_hash = - query_wasm_code_hash(context, TX_INIT_ACCOUNT_WASM).await?; - let init_validator_hash = - query_wasm_code_hash(context, TX_INIT_VALIDATOR_WASM).await?; - let init_proposal_hash = - query_wasm_code_hash(context, TX_INIT_PROPOSAL).await?; - let vote_proposal_hash = - query_wasm_code_hash(context, TX_VOTE_PROPOSAL).await?; - let reveal_pk_hash = query_wasm_code_hash(context, TX_REVEAL_PK).await?; - let update_account_hash = - query_wasm_code_hash(context, TX_UPDATE_ACCOUNT_WASM).await?; - let transfer_hash = query_wasm_code_hash(context, TX_TRANSFER_WASM).await?; - let ibc_hash = query_wasm_code_hash(context, TX_IBC_WASM).await?; - let bond_hash = query_wasm_code_hash(context, TX_BOND_WASM).await?; - let unbond_hash = query_wasm_code_hash(context, TX_UNBOND_WASM).await?; - let withdraw_hash = query_wasm_code_hash(context, TX_WITHDRAW_WASM).await?; - let change_commission_hash = - query_wasm_code_hash(context, TX_CHANGE_COMMISSION_WASM).await?; - let change_consensus_key_hash = - query_wasm_code_hash(context, TX_CHANGE_CONSENSUS_KEY_WASM).await?; - let change_metadata_hash = - query_wasm_code_hash(context, TX_CHANGE_METADATA_WASM).await?; - let user_hash = query_wasm_code_hash(context, VP_USER_WASM).await?; - let unjail_validator_hash = - query_wasm_code_hash(context, TX_UNJAIL_VALIDATOR_WASM).await?; - let deactivate_validator_hash = - query_wasm_code_hash(context, TX_DEACTIVATE_VALIDATOR_WASM).await?; - let reactivate_validator_hash = - query_wasm_code_hash(context, TX_REACTIVATE_VALIDATOR_WASM).await?; - let claim_rewards_hash = - query_wasm_code_hash(context, TX_CLAIM_REWARDS_WASM).await?; - // To facilitate lookups of human-readable token names let tokens: HashMap = context .wallet() @@ -1066,7 +1035,7 @@ pub async fn to_ledger_vector<'a>( ..Default::default() }; - let code_hash = tx + let code_sec = tx .get_section(tx.code_sechash()) .ok_or_else(|| { Error::Other("expected tx code section to be present".to_string()) @@ -1074,13 +1043,13 @@ pub async fn to_ledger_vector<'a>( .code_sec() .ok_or_else(|| { Error::Other("expected section to have code tag".to_string()) - })? - .code - .hash(); - tv.output_expert - .push(format!("Code hash : {}", HEXLOWER.encode(&code_hash.0))); + })?; + tv.output_expert.push(format!( + "Code hash : {}", + HEXLOWER.encode(&code_sec.code.hash().0) + )); - if code_hash == init_account_hash { + if code_sec.tag == Some(TX_INIT_ACCOUNT_WASM.to_string()) { let init_account = InitAccount::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1093,13 +1062,15 @@ pub async fn to_ledger_vector<'a>( let extra = tx .get_section(&init_account.vp_code_hash) .and_then(|x| Section::extra_data_sec(x.as_ref())) - .ok_or_else(|| Error::Other("unable to load vp code".to_string()))? - .code - .hash(); - let vp_code = if extra == user_hash { + .ok_or_else(|| { + Error::Other("unable to load vp code".to_string()) + })?; + let vp_code = if extra.tag == Some(VP_USER_WASM.to_string()) { "User".to_string() + } else if extra.tag == Some(VP_VALIDATOR_WASM.to_string()) { + "Validator".to_string() } else { - HEXLOWER.encode(&extra.0) + HEXLOWER.encode(&extra.code.hash().0) }; tv.output.extend(vec![format!("Type : Init Account")]); tv.output.extend( @@ -1121,9 +1092,9 @@ pub async fn to_ledger_vector<'a>( ); tv.output_expert.extend(vec![ format!("Threshold : {}", init_account.threshold), - format!("VP type : {}", HEXLOWER.encode(&extra.0)), + format!("VP type : {}", HEXLOWER.encode(&extra.code.hash().0)), ]); - } else if code_hash == init_validator_hash { + } else if code_sec.tag == Some(TX_INIT_VALIDATOR_WASM.to_string()) { let init_validator = InitValidator::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1137,13 +1108,15 @@ pub async fn to_ledger_vector<'a>( let extra = tx .get_section(&init_validator.validator_vp_code_hash) .and_then(|x| Section::extra_data_sec(x.as_ref())) - .ok_or_else(|| Error::Other("unable to load vp code".to_string()))? - .code - .hash(); - let vp_code = if extra == user_hash { + .ok_or_else(|| { + Error::Other("unable to load vp code".to_string()) + })?; + let vp_code = if extra.tag == Some(VP_USER_WASM.to_string()) { "User".to_string() + } else if extra.tag == Some(VP_VALIDATOR_WASM.to_string()) { + "Validator".to_string() } else { - HEXLOWER.encode(&extra.0) + HEXLOWER.encode(&extra.code.hash().0) }; tv.output.extend(vec!["Type : Init Validator".to_string()]); @@ -1162,10 +1135,21 @@ pub async fn to_ledger_vector<'a>( format!("Commission rate : {}", init_validator.commission_rate), format!( "Maximum commission rate change : {}", - init_validator.max_commission_rate_change + init_validator.max_commission_rate_change, ), - format!("Validator VP type : {}", vp_code,), + format!("Email : {}", init_validator.email), ]); + if let Some(description) = &init_validator.description { + tv.output.push(format!("Description : {}", description)); + } + if let Some(website) = &init_validator.website { + tv.output.push(format!("Website : {}", website)); + } + if let Some(discord_handle) = &init_validator.discord_handle { + tv.output + .push(format!("Discord handle : {}", discord_handle)); + } + tv.output.push(format!("Validator VP type : {}", vp_code)); tv.output_expert.extend( init_validator @@ -1184,9 +1168,24 @@ pub async fn to_ledger_vector<'a>( "Maximum commission rate change : {}", init_validator.max_commission_rate_change ), - format!("Validator VP type : {}", HEXLOWER.encode(&extra.0)), + format!("Email : {}", init_validator.email), ]); - } else if code_hash == init_proposal_hash { + if let Some(description) = &init_validator.description { + tv.output_expert + .push(format!("Description : {}", description)); + } + if let Some(website) = &init_validator.website { + tv.output_expert.push(format!("Website : {}", website)); + } + if let Some(discord_handle) = &init_validator.discord_handle { + tv.output_expert + .push(format!("Discord handle : {}", discord_handle)); + } + tv.output_expert.push(format!( + "Validator VP type : {}", + HEXLOWER.encode(&extra.code.hash().0) + )); + } else if code_sec.tag == Some(TX_INIT_PROPOSAL.to_string()) { let init_proposal_data = InitProposalData::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1246,7 +1245,7 @@ pub async fn to_ledger_vector<'a>( format!("Grace epoch : {}", init_proposal_data.grace_epoch), format!("Content : {}", HEXLOWER.encode(&extra.0)), ]); - } else if code_hash == vote_proposal_hash { + } else if code_sec.tag == Some(TX_VOTE_PROPOSAL.to_string()) { let vote_proposal = VoteProposalData::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1276,7 +1275,7 @@ pub async fn to_ledger_vector<'a>( tv.output_expert .push(format!("Delegation : {}", delegation)); } - } else if code_hash == reveal_pk_hash { + } else if code_sec.tag == Some(TX_REVEAL_PK.to_string()) { let public_key = common::PublicKey::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1294,7 +1293,7 @@ pub async fn to_ledger_vector<'a>( tv.output_expert .extend(vec![format!("Public key : {}", public_key)]); - } else if code_hash == update_account_hash { + } else if code_sec.tag == Some(TX_UPDATE_ACCOUNT_WASM.to_string()) { let update_account = UpdateAccount::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1312,13 +1311,13 @@ pub async fn to_ledger_vector<'a>( .and_then(|x| Section::extra_data_sec(x.as_ref())) .ok_or_else(|| { Error::Other("unable to load vp code".to_string()) - })? - .code - .hash(); - let vp_code = if extra == user_hash { + })?; + let vp_code = if extra.tag == Some(VP_USER_WASM.to_string()) { "User".to_string() + } else if extra.tag == Some(VP_VALIDATOR_WASM.to_string()) { + "Validator".to_string() } else { - HEXLOWER.encode(&extra.0) + HEXLOWER.encode(&extra.code.hash().0) }; tv.output.extend(vec![ format!("Type : Update VP"), @@ -1354,12 +1353,12 @@ pub async fn to_ledger_vector<'a>( } tv.output_expert.extend(vec![format!( "VP type : {}", - HEXLOWER.encode(&extra.0) + HEXLOWER.encode(&extra.code.hash().0) )]); } None => (), }; - } else if code_hash == transfer_hash { + } else if code_sec.tag == Some(TX_TRANSFER_WASM.to_string()) { let transfer = Transfer::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1415,7 +1414,7 @@ pub async fn to_ledger_vector<'a>( &asset_types, ) .await; - } else if code_hash == ibc_hash { + } else if code_sec.tag == Some(TX_IBC_WASM.to_string()) { let any_msg = Any::decode( tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))? @@ -1480,7 +1479,7 @@ pub async fn to_ledger_vector<'a>( } } } - } else if code_hash == bond_hash { + } else if code_sec.tag == Some(TX_BOND_WASM.to_string()) { let bond = pos::Bond::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1513,7 +1512,7 @@ pub async fn to_ledger_vector<'a>( to_ledger_decimal(&bond.amount.to_string_native()) ), ]); - } else if code_hash == unbond_hash { + } else if code_sec.tag == Some(TX_UNBOND_WASM.to_string()) { let unbond = pos::Unbond::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1546,7 +1545,7 @@ pub async fn to_ledger_vector<'a>( to_ledger_decimal(&unbond.amount.to_string_native()) ), ]); - } else if code_hash == withdraw_hash { + } else if code_sec.tag == Some(TX_WITHDRAW_WASM.to_string()) { let withdraw = pos::Withdraw::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1569,7 +1568,7 @@ pub async fn to_ledger_vector<'a>( } tv.output_expert .push(format!("Validator : {}", withdraw.validator)); - } else if code_hash == claim_rewards_hash { + } else if code_sec.tag == Some(TX_CLAIM_REWARDS_WASM.to_string()) { let claim = pos::Withdraw::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1591,7 +1590,7 @@ pub async fn to_ledger_vector<'a>( } tv.output_expert .push(format!("Validator : {}", claim.validator)); - } else if code_hash == change_commission_hash { + } else if code_sec.tag == Some(TX_CHANGE_COMMISSION_WASM.to_string()) { let commission_change = pos::CommissionChange::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1612,7 +1611,7 @@ pub async fn to_ledger_vector<'a>( format!("New rate : {}", commission_change.new_rate), format!("Validator : {}", commission_change.validator), ]); - } else if code_hash == change_metadata_hash { + } else if code_sec.tag == Some(TX_CHANGE_METADATA_WASM.to_string()) { let metadata_change = pos::MetaDataChange::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1654,7 +1653,7 @@ pub async fn to_ledger_vector<'a>( tv.output.extend(other_items.clone()); tv.output_expert.extend(other_items); - } else if code_hash == change_consensus_key_hash { + } else if code_sec.tag == Some(TX_CHANGE_CONSENSUS_KEY_WASM.to_string()) { let consensus_key_change = pos::ConsensusKeyChange::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1681,7 +1680,7 @@ pub async fn to_ledger_vector<'a>( ), format!("Validator : {}", consensus_key_change.validator), ]); - } else if code_hash == unjail_validator_hash { + } else if code_sec.tag == Some(TX_UNJAIL_VALIDATOR_WASM.to_string()) { let address = Address::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1698,7 +1697,7 @@ pub async fn to_ledger_vector<'a>( ]); tv.output_expert.push(format!("Validator : {}", address)); - } else if code_hash == deactivate_validator_hash { + } else if code_sec.tag == Some(TX_DEACTIVATE_VALIDATOR_WASM.to_string()) { let address = Address::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, @@ -1715,7 +1714,7 @@ pub async fn to_ledger_vector<'a>( ]); tv.output_expert.push(format!("Validator : {}", address)); - } else if code_hash == reactivate_validator_hash { + } else if code_sec.tag == Some(TX_REACTIVATE_VALIDATOR_WASM.to_string()) { let address = Address::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index e113a7a015..9378615890 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -116,7 +116,7 @@ pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm"; /// Update steward commission WASM path pub const TX_UPDATE_STEWARD_COMMISSION: &str = "tx_update_steward_commission.wasm"; -/// Redelegat WASM path +/// Redelegate transaction WASM path pub const TX_REDELEGATE_WASM: &str = "tx_redelegate.wasm"; /// Default timeout in seconds for requests to the `/accepted` @@ -1725,12 +1725,12 @@ pub async fn build_default_proposal<'a>( let push_data = |tx_builder: &mut Tx, init_proposal_data: &mut InitProposalData| { let (_, extra_section_hash) = tx_builder - .add_extra_section(proposal_to_vec(proposal.proposal)?); + .add_extra_section(proposal_to_vec(proposal.proposal)?, None); init_proposal_data.content = extra_section_hash; if let Some(init_proposal_code) = proposal.data { let (_, extra_section_hash) = - tx_builder.add_extra_section(init_proposal_code); + tx_builder.add_extra_section(init_proposal_code, None); init_proposal_data.r#type = ProposalType::Default(Some(extra_section_hash)); }; @@ -1864,7 +1864,7 @@ pub async fn build_pgf_funding_proposal<'a>( let add_section = |tx: &mut Tx, data: &mut InitProposalData| { let (_, extra_section_hash) = - tx.add_extra_section(proposal_to_vec(proposal.proposal)?); + tx.add_extra_section(proposal_to_vec(proposal.proposal)?, None); data.content = extra_section_hash; Ok(()) }; @@ -1909,7 +1909,7 @@ pub async fn build_pgf_stewards_proposal<'a>( let add_section = |tx: &mut Tx, data: &mut InitProposalData| { let (_, extra_section_hash) = - tx.add_extra_section(proposal_to_vec(proposal.proposal)?); + tx.add_extra_section(proposal_to_vec(proposal.proposal)?, None); data.content = extra_section_hash; Ok(()) }; @@ -2037,8 +2037,11 @@ pub async fn build_ibc_transfer<'a>( let chain_id = args.tx.chain_id.clone().unwrap(); let mut tx = Tx::new(chain_id, args.tx.expiration); - tx.add_code_from_hash(tx_code_hash) - .add_serialized_data(data); + tx.add_code_from_hash( + tx_code_hash, + Some(args.tx_code_path.to_string_lossy().into_owned()), + ) + .add_serialized_data(data); let epoch = prepare_tx( context, @@ -2103,7 +2106,12 @@ where on_tx(&mut tx_builder, &mut data)?; - tx_builder.add_code_from_hash(tx_code_hash).add_data(data); + tx_builder + .add_code_from_hash( + tx_code_hash, + Some(path.to_string_lossy().into_owned()), + ) + .add_data(data); let epoch = prepare_tx( context, @@ -2377,7 +2385,10 @@ pub async fn build_init_account<'a>( }; let add_code_hash = |tx: &mut Tx, data: &mut InitAccount| { - let extra_section_hash = tx.add_extra_section_from_hash(vp_code_hash); + let extra_section_hash = tx.add_extra_section_from_hash( + vp_code_hash, + Some(vp_code_path.to_string_lossy().into_owned()), + ); data.vp_code_hash = extra_section_hash; Ok(()) }; @@ -2435,8 +2446,14 @@ pub async fn build_update_account<'a>( let chain_id = tx_args.chain_id.clone().unwrap(); let mut tx = Tx::new(chain_id, tx_args.expiration); - let extra_section_hash = vp_code_hash - .map(|vp_code_hash| tx.add_extra_section_from_hash(vp_code_hash)); + let extra_section_hash = vp_code_path.as_ref().zip(vp_code_hash).map( + |(code_path, vp_code_hash)| { + tx.add_extra_section_from_hash( + vp_code_hash, + Some(code_path.to_string_lossy().into_owned()), + ) + }, + ); let data = UpdateAccount { addr, @@ -2446,8 +2463,14 @@ pub async fn build_update_account<'a>( }; let add_code_hash = |tx: &mut Tx, data: &mut UpdateAccount| { - let extra_section_hash = vp_code_hash - .map(|vp_code_hash| tx.add_extra_section_from_hash(vp_code_hash)); + let extra_section_hash = vp_code_path.as_ref().zip(vp_code_hash).map( + |(code_path, vp_code_hash)| { + tx.add_extra_section_from_hash( + vp_code_hash, + Some(code_path.to_string_lossy().into_owned()), + ) + }, + ); data.vp_code_hash = extra_section_hash; Ok(()) }; @@ -2489,16 +2512,16 @@ pub async fn build_custom<'a>( Error::Other("Invalid tx deserialization.".to_string()) })? } else { - let tx_code_hash = query_wasm_code_hash_buf( - context, - code_path - .as_ref() - .ok_or(Error::Other("No code path supplied".to_string()))?, - ) - .await?; + let code_path = code_path + .as_ref() + .ok_or(Error::Other("No code path supplied".to_string()))?; + let tx_code_hash = query_wasm_code_hash_buf(context, code_path).await?; let chain_id = tx_args.chain_id.clone().unwrap(); let mut tx = Tx::new(chain_id, tx_args.expiration); - tx.add_code_from_hash(tx_code_hash); + tx.add_code_from_hash( + tx_code_hash, + Some(code_path.to_string_lossy().into_owned()), + ); data_path.clone().map(|data| tx.add_serialized_data(data)); tx }; diff --git a/shared/src/ledger/mod.rs b/shared/src/ledger/mod.rs index 5042913c08..87103c8b79 100644 --- a/shared/src/ledger/mod.rs +++ b/shared/src/ledger/mod.rs @@ -291,7 +291,7 @@ mod test { let mut outer_tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); outer_tx.header.chain_id = client.wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::from_hash(tx_hash)); + outer_tx.set_code(Code::from_hash(tx_hash, None)); outer_tx.set_data(Data::new(vec![])); let tx_bytes = outer_tx.to_bytes(); let result = RPC diff --git a/shared/src/ledger/native_vp/ibc/mod.rs b/shared/src/ledger/native_vp/ibc/mod.rs index c3bd0baddc..78e1378baa 100644 --- a/shared/src/ledger/native_vp/ibc/mod.rs +++ b/shared/src/ledger/native_vp/ibc/mod.rs @@ -727,7 +727,7 @@ mod tests { let verifiers = BTreeSet::new(); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -801,7 +801,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -929,7 +929,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -1037,7 +1037,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1136,7 +1136,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -1264,7 +1264,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -1373,7 +1373,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1470,7 +1470,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1595,7 +1595,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1719,7 +1719,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1828,7 +1828,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); outer_tx.add_section(Section::Signature(Signature::new( vec![outer_tx.header_hash()], @@ -1935,7 +1935,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -2077,7 +2077,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -2272,7 +2272,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -2419,7 +2419,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -2570,7 +2570,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); @@ -2722,7 +2722,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(wl_storage.storage.chain_id.clone(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(keypair_1()); diff --git a/shared/src/ledger/native_vp/multitoken.rs b/shared/src/ledger/native_vp/multitoken.rs index d3782c9548..809e840848 100644 --- a/shared/src/ledger/native_vp/multitoken.rs +++ b/shared/src/ledger/native_vp/multitoken.rs @@ -167,7 +167,7 @@ mod tests { let tx_data = vec![]; let mut tx = Tx::from_type(TxType::Raw); tx.header.chain_id = wl_storage.storage.chain_id.clone(); - tx.set_code(Code::new(tx_code)); + tx.set_code(Code::new(tx_code, None)); tx.set_data(Data::new(tx_data)); tx.add_section(Section::Signature(Signature::new( tx.sechashes(), diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index c2ff540570..0c01c6134b 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -12,6 +12,7 @@ use namada_core::types::hash::Hash; use namada_core::types::storage::Key; use namada_core::types::token::Amount; use namada_core::types::transaction::WrapperTx; +use namada_sdk::tx::TX_TRANSFER_WASM; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use thiserror::Error; @@ -210,7 +211,7 @@ where S: StorageRead, { let transfer_code_name_key = - Key::wasm_code_name("tx_transfer.wasm".to_string()); + Key::wasm_code_name(TX_TRANSFER_WASM.to_string()); storage .read(&transfer_code_name_key) .expect("Could not read the storage") @@ -327,6 +328,7 @@ where // balance match wrapper.generate_fee_unshielding( get_transfer_hash_from_storage(*wl_storage), + Some(TX_TRANSFER_WASM.to_string()), transaction, ) { Ok(fee_unshielding_tx) => { diff --git a/shared/src/vm/host_env.rs b/shared/src/vm/host_env.rs index 2d18b9898b..2a527d2ff5 100644 --- a/shared/src/vm/host_env.rs +++ b/shared/src/vm/host_env.rs @@ -833,7 +833,7 @@ where let key = Key::parse(key).map_err(TxRuntimeError::StorageDataError)?; if key.is_validity_predicate().is_some() { - tx_validate_vp_code_hash(env, &value)?; + tx_validate_vp_code_hash(env, &value, &None)?; } check_address_existence(env, &key)?; @@ -1432,6 +1432,8 @@ pub fn tx_update_validity_predicate( addr_len: u64, code_hash_ptr: u64, code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, ) -> TxResult<()> where MEM: VmMemory, @@ -1448,6 +1450,14 @@ where let addr = Address::decode(addr).map_err(TxRuntimeError::AddressError)?; tracing::debug!("tx_update_validity_predicate for addr {}", addr); + let (code_tag, gas) = env + .memory + .read_bytes(code_tag_ptr, code_tag_len as _) + .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; + tx_charge_gas(env, gas)?; + let code_tag = Option::::try_from_slice(&code_tag) + .map_err(TxRuntimeError::EncodingError)?; + let key = Key::validity_predicate(&addr); let (code_hash, gas) = env .memory @@ -1455,7 +1465,7 @@ where .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; tx_charge_gas(env, gas)?; - tx_validate_vp_code_hash(env, &code_hash)?; + tx_validate_vp_code_hash(env, &code_hash, &code_tag)?; let write_log = unsafe { env.ctx.write_log.get() }; let (gas, _size_diff) = write_log @@ -1469,6 +1479,8 @@ pub fn tx_init_account( env: &TxVmEnv, code_hash_ptr: u64, code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, result_ptr: u64, ) -> TxResult<()> where @@ -1483,7 +1495,15 @@ where .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; tx_charge_gas(env, gas)?; - tx_validate_vp_code_hash(env, &code_hash)?; + let (code_tag, gas) = env + .memory + .read_bytes(code_tag_ptr, code_tag_len as _) + .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; + tx_charge_gas(env, gas)?; + let code_tag = Option::::try_from_slice(&code_tag) + .map_err(TxRuntimeError::EncodingError)?; + + tx_validate_vp_code_hash(env, &code_hash, &code_tag)?; tracing::debug!("tx_init_account"); @@ -2002,6 +2022,7 @@ where fn tx_validate_vp_code_hash( env: &TxVmEnv, code_hash: &[u8], + code_tag: &Option, ) -> TxResult<()> where MEM: VmMemory, @@ -2009,16 +2030,44 @@ where H: StorageHasher, CA: WasmCacheAccess, { - let hash = Hash::try_from(code_hash) + let code_hash = Hash::try_from(code_hash) .map_err(|e| TxRuntimeError::InvalidVpCodeHash(e.to_string()))?; - let key = Key::wasm_code(&hash); + + // First check that code hash corresponds to the code tag if it is present + if let Some(tag) = code_tag { + let storage = unsafe { env.ctx.storage.get() }; + let hash_key = Key::wasm_hash(tag); + let (result, gas) = storage + .read(&hash_key) + .map_err(TxRuntimeError::StorageError)?; + tx_charge_gas(env, gas)?; + if let Some(tag_hash) = result { + let tag_hash = Hash::try_from(&tag_hash[..]).map_err(|e| { + TxRuntimeError::InvalidVpCodeHash(e.to_string()) + })?; + if tag_hash != code_hash { + return Err(TxRuntimeError::InvalidVpCodeHash( + "The VP code tag does not correspond to the given code \ + hash" + .to_string(), + )); + } + } else { + return Err(TxRuntimeError::InvalidVpCodeHash( + "The VP code tag doesn't exist".to_string(), + )); + } + } + + // Then check that the corresponding VP code does indeed exist + let code_key = Key::wasm_code(&code_hash); let write_log = unsafe { env.ctx.write_log.get() }; - let (result, gas) = write_log.read(&key); + let (result, gas) = write_log.read(&code_key); tx_charge_gas(env, gas)?; if result.is_none() { let storage = unsafe { env.ctx.storage.get() }; let (is_present, gas) = storage - .has_key(&key) + .has_key(&code_key) .map_err(TxRuntimeError::StorageError)?; tx_charge_gas(env, gas)?; if !is_present { diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index 2865e22503..7b7a009c6a 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -110,6 +110,41 @@ where .and_then(|x| Section::code_sec(x.as_ref())) .ok_or(Error::MissingSection(tx.code_sechash().to_string()))?; + // If the transaction code has a tag, ensure that the tag hash equals the + // transaction code's hash. + if let Some(tag) = &tx_code.tag { + // Get the WASM code hash corresponding to the tag from storage + let hash_key = Key::wasm_hash(tag); + let hash_value = match storage + .read(&hash_key) + .map_err(|e| { + Error::LoadWasmCode(format!( + "Read wasm code hash failed from storage: key {}, error {}", + hash_key, e + )) + })? + .0 + { + Some(v) => Hash::try_from_slice(&v) + .map_err(|e| Error::ConversionError(e.to_string()))?, + None => { + return Err(Error::LoadWasmCode(format!( + "No wasm code hash in storage: key {}", + hash_key + ))); + } + }; + // Ensure that the queried code hash equals the transaction's code hash + let tx_code_hash = tx_code.code.hash(); + if tx_code_hash != hash_value { + return Err(Error::LoadWasmCode(format!( + "Transaction code hash does not correspond to tag: tx hash \ + {}, tag {}, tag hash {}", + tx_code_hash, tag, hash_value, + ))); + } + } + let (module, store) = fetch_or_compile( tx_wasm_cache, &tx_code.code, @@ -689,7 +724,7 @@ mod tests { let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); let mut outer_tx = Tx::from_type(TxType::Raw); - outer_tx.set_code(Code::new(tx_code.clone())); + outer_tx.set_code(Code::new(tx_code.clone(), None)); outer_tx.set_data(Data::new(tx_data)); let result = tx( &storage, @@ -706,7 +741,7 @@ mod tests { // should fail let tx_data = 2_usize.pow(24).serialize_to_vec(); let mut outer_tx = Tx::from_type(TxType::Raw); - outer_tx.set_code(Code::new(tx_code)); + outer_tx.set_code(Code::new(tx_code, None)); outer_tx.set_data(Data::new(tx_data)); let error = tx( &storage, @@ -764,7 +799,7 @@ mod tests { let input = 2_usize.pow(23).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); - tx.add_code(vec![]).add_serialized_data(input); + tx.add_code(vec![], None).add_serialized_data(input); let eval_vp = EvalVp { vp_code_hash: limit_code_hash, @@ -772,7 +807,7 @@ mod tests { }; let mut outer_tx = Tx::new(storage.chain_id.clone(), None); - outer_tx.add_code(vec![]).add_data(eval_vp); + outer_tx.add_code(vec![], None).add_data(eval_vp); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); // When the `eval`ed VP doesn't run out of memory, it should return @@ -796,7 +831,7 @@ mod tests { // should fail let input = 2_usize.pow(24).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); - tx.add_code(vec![]).add_data(input); + tx.add_code(vec![], None).add_data(input); let eval_vp = EvalVp { vp_code_hash: limit_code_hash, @@ -804,7 +839,7 @@ mod tests { }; let mut outer_tx = Tx::new(storage.chain_id.clone(), None); - outer_tx.add_code(vec![]).add_data(eval_vp); + outer_tx.add_code(vec![], None).add_data(eval_vp); // When the `eval`ed VP runs out of memory, its result should be // `false`, hence we should also get back `false` from the VP that @@ -859,7 +894,7 @@ mod tests { let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); - outer_tx.set_code(Code::new(vec![])); + outer_tx.set_code(Code::new(vec![], None)); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let result = vp( code_hash, @@ -928,7 +963,7 @@ mod tests { let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); let mut outer_tx = Tx::from_type(TxType::Raw); - outer_tx.set_code(Code::new(tx_no_op)); + outer_tx.set_code(Code::new(tx_no_op, None)); outer_tx.set_data(Data::new(tx_data)); let result = tx( &storage, @@ -991,7 +1026,7 @@ mod tests { let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); - outer_tx.set_code(Code::new(vec![])); + outer_tx.set_code(Code::new(vec![], None)); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let result = vp( code_hash, @@ -1062,7 +1097,7 @@ mod tests { let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); let mut outer_tx = Tx::from_type(TxType::Raw); - outer_tx.set_code(Code::new(tx_read_key)); + outer_tx.set_code(Code::new(tx_read_key, None)); outer_tx.set_data(Data::new(tx_data)); let error = tx( &storage, @@ -1117,7 +1152,7 @@ mod tests { let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); - outer_tx.set_code(Code::new(vec![])); + outer_tx.set_code(Code::new(vec![], None)); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let error = vp( code_hash, @@ -1185,7 +1220,7 @@ mod tests { let input = 2_usize.pow(23).serialize_to_vec(); let mut tx = Tx::new(storage.chain_id.clone(), None); - tx.add_code(vec![]).add_serialized_data(input); + tx.add_code(vec![], None).add_serialized_data(input); let eval_vp = EvalVp { vp_code_hash: read_code_hash, @@ -1193,7 +1228,7 @@ mod tests { }; let mut outer_tx = Tx::new(storage.chain_id.clone(), None); - outer_tx.add_code(vec![]).add_data(eval_vp); + outer_tx.add_code(vec![], None).add_data(eval_vp); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let passed = vp( @@ -1266,7 +1301,7 @@ mod tests { write_log.write(&len_key, code_len).unwrap(); let mut outer_tx = Tx::from_type(TxType::Raw); - outer_tx.set_code(Code::from_hash(code_hash)); + outer_tx.set_code(Code::from_hash(code_hash, None)); outer_tx.set_data(Data::new(tx_data)); tx( diff --git a/tests/src/e2e/setup.rs b/tests/src/e2e/setup.rs index 644110bba6..35f5216905 100644 --- a/tests/src/e2e/setup.rs +++ b/tests/src/e2e/setup.rs @@ -1081,6 +1081,9 @@ pub fn sleep(seconds: u64) { #[allow(dead_code)] pub mod constants { + // Paths to the WASMs used for tests + pub use namada_sdk::tx::{TX_IBC_WASM, TX_TRANSFER_WASM, VP_USER_WASM}; + // User addresses aliases pub const ALBERT: &str = "Albert"; pub const ALBERT_KEY: &str = "Albert-key"; @@ -1126,11 +1129,6 @@ pub mod constants { pub const SCHNITZEL: &str = "Schnitzel"; pub const APFEL: &str = "Apfel"; pub const KARTOFFEL: &str = "Kartoffel"; - - // Paths to the WASMs used for tests - pub const VP_USER_WASM: &str = "vp_user.wasm"; - pub const TX_IBC_WASM: &str = "tx_ibc.wasm"; - pub const TX_TRANSFER_WASM: &str = "tx_transfer.wasm"; } /// Copy WASM files from the `wasm` directory to every node's chain dir. diff --git a/tests/src/native_vp/eth_bridge_pool.rs b/tests/src/native_vp/eth_bridge_pool.rs index ba69c6e380..f6ae375e85 100644 --- a/tests/src/native_vp/eth_bridge_pool.rs +++ b/tests/src/native_vp/eth_bridge_pool.rs @@ -21,11 +21,10 @@ mod test_bridge_pool_vp { wrapped_erc20s, Contracts, Erc20WhitelistEntry, EthereumBridgeParams, UpgradeableContract, }; + use namada_sdk::tx::TX_BRIDGE_POOL_WASM as ADD_TRANSFER_WASM; use crate::native_vp::TestNativeVpEnv; use crate::tx::{tx_host_env, TestTxEnv}; - - const ADD_TRANSFER_WASM: &str = "tx_bridge_pool.wasm"; const ASSET: EthAddress = EthAddress([1; 20]); const BERTHA_WEALTH: u64 = 1_000_000; const BERTHA_TOKENS: u64 = 10_000; @@ -130,7 +129,7 @@ mod test_bridge_pool_vp { wasm_loader::read_wasm_or_exit(wasm_dir(), ADD_TRANSFER_WASM); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(wasm_code) + tx.add_code(wasm_code, None) .add_serialized_data(data) .sign_wrapper(keypair.clone()); tx diff --git a/tests/src/vm_host_env/ibc.rs b/tests/src/vm_host_env/ibc.rs index e0d4cce010..3ca3705fa9 100644 --- a/tests/src/vm_host_env/ibc.rs +++ b/tests/src/vm_host_env/ibc.rs @@ -234,11 +234,11 @@ pub fn init_storage() -> (Address, Address) { }); // initialize a token - let token = tx_host_env::ctx().init_account(code_hash).unwrap(); + let token = tx_host_env::ctx().init_account(code_hash, &None).unwrap(); let denom_key = token::denom_key(&token); let token_denom = token::Denomination(ANY_DENOMINATION); // initialize an account - let account = tx_host_env::ctx().init_account(code_hash).unwrap(); + let account = tx_host_env::ctx().init_account(code_hash, &None).unwrap(); let key = token::balance_key(&token, &account); let init_bal = Amount::from_uint(100, token_denom).unwrap(); tx_host_env::with(|env| { diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index b5895a7d26..25fe337ce2 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -213,7 +213,7 @@ mod tests { tx_host_env::init(); let code = vec![]; - tx::ctx().init_account(code).unwrap(); + tx::ctx().init_account(code, &None).unwrap(); } #[test] @@ -228,7 +228,7 @@ mod tests { let key = Key::wasm_code(&code_hash); env.wl_storage.storage.write(&key, code.clone()).unwrap(); }); - tx::ctx().init_account(code_hash).unwrap(); + tx::ctx().init_account(code_hash, &None).unwrap(); } #[test] @@ -462,7 +462,7 @@ mod tests { let signed_tx_data = vp_host_env::with(|env| { let chain_id = env.wl_storage.storage.chain_id.clone(); let mut tx = Tx::new(chain_id, expiration); - tx.add_code(code.clone()) + tx.add_code(code.clone(), None) .add_serialized_data(data.to_vec()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -555,7 +555,7 @@ mod tests { ]); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(input_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -577,7 +577,7 @@ mod tests { .unwrap(); }); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code_from_hash(code_hash) + tx.add_code_from_hash(code_hash, None) .add_serialized_data(input_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -600,7 +600,7 @@ mod tests { .unwrap(); }); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code_from_hash(code_hash) + tx.add_code_from_hash(code_hash, None) .add_serialized_data(input_data) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -625,7 +625,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -659,7 +659,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -702,7 +702,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -735,7 +735,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -779,7 +779,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -812,7 +812,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -858,7 +858,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -891,7 +891,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -937,7 +937,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -971,7 +971,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1020,7 +1020,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1077,7 +1077,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1131,7 +1131,7 @@ mod tests { .expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); @@ -1178,7 +1178,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1262,7 +1262,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1335,7 +1335,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1414,7 +1414,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1517,7 +1517,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1622,7 +1622,7 @@ mod tests { msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1722,7 +1722,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); @@ -1811,7 +1811,7 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(vec![]) + tx.add_code(vec![], None) .add_serialized_data(tx_data.clone()) .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); diff --git a/tests/src/vm_host_env/tx.rs b/tests/src/vm_host_env/tx.rs index 605a54acae..2dcc5cc4da 100644 --- a/tests/src/vm_host_env/tx.rs +++ b/tests/src/vm_host_env/tx.rs @@ -487,12 +487,16 @@ mod native_tx_host_env { native_host_fn!(tx_update_validity_predicate( addr_ptr: u64, addr_len: u64, - code_ptr: u64, - code_len: u64, + code_hash_ptr: u64, + code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, )); native_host_fn!(tx_init_account( - code_ptr: u64, - code_len: u64, + code_hash_ptr: u64, + code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, result_ptr: u64 )); native_host_fn!(tx_emit_ibc_event(event_ptr: u64, event_len: u64)); diff --git a/tx_prelude/src/lib.rs b/tx_prelude/src/lib.rs index 71b56068ee..29e9881488 100644 --- a/tx_prelude/src/lib.rs +++ b/tx_prelude/src/lib.rs @@ -283,14 +283,18 @@ impl TxEnv for Ctx { fn init_account( &mut self, - code: impl AsRef<[u8]>, + code_hash: impl AsRef<[u8]>, + code_tag: &Option, ) -> Result { - let code = code.as_ref(); + let code_hash = code_hash.as_ref(); + let code_tag = code_tag.serialize_to_vec(); let result = Vec::with_capacity(address::ESTABLISHED_ADDRESS_BYTES_LEN); unsafe { namada_tx_init_account( - code.as_ptr() as _, - code.len() as _, + code_hash.as_ptr() as _, + code_hash.len() as _, + code_tag.as_ptr() as _, + code_tag.len() as _, result.as_ptr() as _, ) }; @@ -307,16 +311,20 @@ impl TxEnv for Ctx { fn update_validity_predicate( &mut self, addr: &Address, - code: impl AsRef<[u8]>, + code_hash: impl AsRef<[u8]>, + code_tag: &Option, ) -> Result<(), Error> { let addr = addr.encode(); - let code = code.as_ref(); + let code_hash = code_hash.as_ref(); + let code_tag = code_tag.serialize_to_vec(); unsafe { namada_tx_update_validity_predicate( addr.as_ptr() as _, addr.len() as _, - code.as_ptr() as _, - code.len() as _, + code_hash.as_ptr() as _, + code_hash.len() as _, + code_tag.as_ptr() as _, + code_tag.len() as _, ) }; Ok(()) diff --git a/tx_prelude/src/proof_of_stake.rs b/tx_prelude/src/proof_of_stake.rs index 5e26a92eb3..ec5f6f0ab8 100644 --- a/tx_prelude/src/proof_of_stake.rs +++ b/tx_prelude/src/proof_of_stake.rs @@ -132,10 +132,12 @@ impl Ctx { validator_vp_code_hash: _, }: InitValidator, validator_vp_code_hash: Hash, + validator_vp_code_tag: &Option, ) -> EnvResult
{ let current_epoch = self.get_block_epoch()?; // Init validator account - let validator_address = self.init_account(validator_vp_code_hash)?; + let validator_address = + self.init_account(validator_vp_code_hash, validator_vp_code_tag)?; storage_api::account::init_account_storage( self, &validator_address, diff --git a/vm_env/src/lib.rs b/vm_env/src/lib.rs index 23fe3fa63a..3b2c5c4dcc 100644 --- a/vm_env/src/lib.rs +++ b/vm_env/src/lib.rs @@ -64,14 +64,18 @@ pub mod tx { pub fn namada_tx_update_validity_predicate( addr_ptr: u64, addr_len: u64, - code_ptr: u64, - code_len: u64, + code_hash_ptr: u64, + code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, ); // Initialize a new account pub fn namada_tx_init_account( - code_ptr: u64, - code_len: u64, + code_hash_ptr: u64, + code_hash_len: u64, + code_tag_ptr: u64, + code_tag_len: u64, result_ptr: u64, ); diff --git a/wasm/checksums.json b/wasm/checksums.json index 23c10a0b79..d93bc795f1 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,28 +1,27 @@ { - "tx_bond.wasm": "tx_bond.3cfcb4952652bacc6695a7327ad6e262aa98d1217a657ec542183144349258c5.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.133b9bb7e885d575235418d45394c62393f25604341cd59c2d1d3226160862a7.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.f06d237ae86aea866068042615108c40f195004de47c983f6b7b2ad8d4edd235.wasm", - "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.e2a3fcc63b80727edbe9c61beab982ed2cac0fdeaaf104a957b08c30849ba2d8.wasm", - "tx_change_consensus_key.wasm": "tx_change_consensus_key.041749d5de20098fdc189d9a80a6c05f55384ce3544bb364930d6574041aa2b4.wasm", - "tx_claim_rewards.wasm": "tx_claim_rewards.8f1ed9528368f8a03f7879f4bafb986ee58c5d47928046838f31b65e03a9b9f9.wasm", - "tx_deactivate_validator.wasm": "tx_deactivate_validator.a59d52f3311c5998528a8aa400d940d44f1290e4e295c53ffb5fdad8b700b75b.wasm", - "tx_ibc.wasm": "tx_ibc.4f3ff8793383fd3a7f5336c94e89750fe784a499362e5a4b12f8ccd1c2c1cf89.wasm", - "tx_init_account.wasm": "tx_init_account.a4730858aea1a0802b1495f851fea559e20422a608ec867220b1ba59f4a1fa4a.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.5b92fdb745211108becc1142e66b1ee4d40150735fb29922f2f34aee8b95d0a9.wasm", - "tx_init_validator.wasm": "tx_init_validator.44d84c00de5fe454d721fe957754642d3fd0395f90a86b07dc67147645a08058.wasm", - "tx_reactivate_validator.wasm": "tx_reactivate_validator.660953ffa8144f795a4d30d2fc4f59593829accc401d8e755569c9bf8624d630.wasm", - "tx_redelegate.wasm": "tx_redelegate.6c97070d523d6cd0c5a3b05e4493894201c93089dcc9e9c48f7709b6f35101e0.wasm", - "tx_resign_steward.wasm": "tx_resign_steward.c0f6fff30ede0e01921c4c20608ee565ea829b48de07a278e03104113ea815ad.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.85bae9a8c2e72fdea99a22b2074c16ce967b3db5dad78110ae0342d9b029f28d.wasm", - "tx_transfer.wasm": "tx_transfer.e8958424155ab20242475cedefea5a992aec93664b22af1b652cc99f18eb8799.wasm", - "tx_unbond.wasm": "tx_unbond.3aeb2b9b5403eb546efd04ddd524c1f5fb06e0318bb9f76a3dcc3d52c772aa8a.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.4a0c9a8c958cff9d7830049d0f349cb1a6801b02e772602436cd503ea13283a1.wasm", - "tx_update_account.wasm": "tx_update_account.6e1e1a6c80b8ca1af280e0e43bbb2fdd45eed60d42e3d60fe7f6bbe1c2419319.wasm", - "tx_update_steward_commission.wasm": "tx_update_steward_commission.08d32be56529c53fbf277d36c8a4b115f98d9d29d86e85199d0348559844e287.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.86834e13c2d06985185af98ce25900da8f164cf262855469099471b7bdf6bec1.wasm", - "tx_withdraw.wasm": "tx_withdraw.049e4d91638270b13572df726337b359a5b15bc69987dfce9e66068d7cdfb0ca.wasm", - "vp_implicit.wasm": "vp_implicit.7253896886d51747442701af361be9954b140aad652f18f56bf39abd88b01531.wasm", - "vp_masp.wasm": "vp_masp.5b21da731e83e41b3dcc7e32839b7a97ae11bc416e5ee3f36bac27ab66426470.wasm", - "vp_user.wasm": "vp_user.2ff00954c8fb5f412ee90c6cd4e2990b217735edcae722b5908d0e5403ee91b2.wasm", - "vp_validator.wasm": "vp_validator.5521a16b39ca5e28d4db2ba26c3335e4c6a551af6dde943b7dc78b905b5b37ec.wasm" -} + "tx_bond.wasm": "tx_bond.b989613b49f49ba69f30ac61b9474931f368102c03027da3eec9b246f81b5277.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.a74c3a41401b5fba2f0d6c010ab62b4a6c3dbed4a6857a4298d07e5fbc002083.wasm", + "tx_change_consensus_key.wasm": "tx_change_consensus_key.10404da7fab6042e4c6ed8b29fa196767364b1ee4e4ad68d827434ada9cc5f4d.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.3ecc31df9aa32fcbfe92c79bef40e3542388b6d361684e58960f910bc36c8839.wasm", + "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.dc4bdd4a89cd465adb05fb6eb48f901a0e1e80f26681709bf8af0e30165c5ad2.wasm", + "tx_claim_rewards.wasm": "tx_claim_rewards.a9237131561c16fa76a5d6eabf10c664ebffe981c16ddee30da9b983f81b6850.wasm", + "tx_deactivate_validator.wasm": "tx_deactivate_validator.c7c739756e481a91150934153d0684df5b2382f9553a92a4714b15460c1518c4.wasm", + "tx_ibc.wasm": "tx_ibc.48eb48367141a2be36175c52d110233a85d0514a974aeef2262b119e0a0db49d.wasm", + "tx_init_account.wasm": "tx_init_account.9ed1359fa57416c5f878698b5a761397b3c6e7f7987008f8cf1ec1304df2e34c.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.b6d269b7f2db4c93ffa46154c2a3efd0ba0bd52fd1027cc12748b7f3c8c5aaa3.wasm", + "tx_init_validator.wasm": "tx_init_validator.95efab261576de7a4fb84c27cc63693fc5da89c655d1de205d2410f1af4573b2.wasm", + "tx_reactivate_validator.wasm": "tx_reactivate_validator.73157f4aace8a61e53cb20a1bb69799475d7455b2723eff5c57f09d2ec1a1dc4.wasm", + "tx_redelegate.wasm": "tx_redelegate.57a559128a73e9acbf46d21d6778e378e0bef0253d877e330208af23de6e56ac.wasm", + "tx_resign_steward.wasm": "tx_resign_steward.f670156c70d2318839489666c9327a17867b2db3763ff60a07b15f2b5862cbe3.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.eff2ae0a82787866d319f7289a0c0742437f12b37fd167f8810b07336c5efefe.wasm", + "tx_transfer.wasm": "tx_transfer.a34b849c0695721c9113ccb75015cca7a5b35f2a4422b24d39c635ac03bcfa88.wasm", + "tx_unbond.wasm": "tx_unbond.66b411757fd4fdfccd640a59ffbdb5b41a1f53b6316f6e515cbbce8f968f6a30.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.f0b8bc20f01053b8209e14d2823a256b6037ba3dd8a2f3d5b9866a7353023bb1.wasm", + "tx_update_account.wasm": "tx_update_account.5690a3d1a16353a4a425814b085cd6ccf4161511e54e952a032c65d7046fe34d.wasm", + "tx_update_steward_commission.wasm": "tx_update_steward_commission.1d5bc824c0c834276be3729a110706b29e66217fd32d210e4336bd9630034a22.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.107d13305ac6639885b7e998d10769e6f59ee8169c602ae3e9ae42e530b66dbb.wasm", + "tx_withdraw.wasm": "tx_withdraw.caef63a4907c6eb6702ec4dd4f57d9dad1f7b9eb3c2bd8e36fecbf6e6b323901.wasm", + "vp_implicit.wasm": "vp_implicit.10a560cf4f79c65e68e310d63ebf3c28d1210898f342bc67ae52ab3d6fe1cd04.wasm", + "vp_user.wasm": "vp_user.14cf33745b83734aba11fa29269e04a8f6f057451079f072036dd05bc69a2b86.wasm", + "vp_validator.wasm": "vp_validator.de918dd5dc3ce3bdbfbf6bd7e1190f7a301dc8296495dc4cbef55198be5c2805.wasm" +} \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index 13075c0c93..419c1e00a0 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -116,7 +116,7 @@ mod tests { let tx_code = vec![]; let tx_data = bond.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(key); diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index e3313e0748..33433b59b3 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -96,7 +96,7 @@ mod tests { let tx_code = vec![]; let tx_data = commission_change.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(key); diff --git a/wasm/wasm_source/src/tx_init_account.rs b/wasm/wasm_source/src/tx_init_account.rs index 236d1335a2..5cc2d3f29f 100644 --- a/wasm/wasm_source/src/tx_init_account.rs +++ b/wasm/wasm_source/src/tx_init_account.rs @@ -14,7 +14,7 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { .wrap_err("failed to decode InitAccount")?; debug_log!("apply_tx called to init a new established account"); - let vp_code = signed + let vp_code_sec = signed .get_section(&tx_data.vp_code_hash) .ok_or_err_msg("vp code section not found") .map_err(|err| { @@ -26,11 +26,10 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { .map_err(|err| { ctx.set_commitment_sentinel(); err - })? - .code - .hash(); + })?; - let address = ctx.init_account(vp_code)?; + let address = + ctx.init_account(vp_code_sec.code.hash(), &vp_code_sec.tag)?; match account::init_account(ctx, &address, tx_data) { Ok(address) => { diff --git a/wasm/wasm_source/src/tx_init_validator.rs b/wasm/wasm_source/src/tx_init_validator.rs index 0666ad7965..f7aa70997b 100644 --- a/wasm/wasm_source/src/tx_init_validator.rs +++ b/wasm/wasm_source/src/tx_init_validator.rs @@ -16,7 +16,7 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { debug_log!("apply_tx called to init a new validator account"); // Get the validator vp code from the extra section - let validator_vp_code_hash = signed + let validator_vp_code_sec = signed .get_section(&init_validator.validator_vp_code_hash) .ok_or_err_msg("validator vp section not found") .map_err(|err| { @@ -28,9 +28,7 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { .map_err(|err| { ctx.set_commitment_sentinel(); err - })? - .code - .hash(); + })?; // Check that the tx has been signed with all the keys to be used for the // validator account @@ -49,7 +47,11 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { } // Register the validator in PoS - match ctx.init_validator(init_validator, validator_vp_code_hash) { + match ctx.init_validator( + init_validator, + validator_vp_code_sec.code.hash(), + &validator_vp_code_sec.tag, + ) { Ok(validator_address) => { debug_log!("Created validator {}", validator_address.encode(),) } diff --git a/wasm/wasm_source/src/tx_redelegate.rs b/wasm/wasm_source/src/tx_redelegate.rs index 4742d407eb..8416c4d553 100644 --- a/wasm/wasm_source/src/tx_redelegate.rs +++ b/wasm/wasm_source/src/tx_redelegate.rs @@ -138,7 +138,7 @@ mod tests { let tx_code = vec![]; let tx_data = redelegation.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(key); let signed_tx = tx; diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index 86a1345706..3747f91d33 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -144,7 +144,7 @@ mod tests { let tx_code = vec![]; let tx_data = unbond.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(key); let signed_tx = tx; diff --git a/wasm/wasm_source/src/tx_update_account.rs b/wasm/wasm_source/src/tx_update_account.rs index f7f6b5729a..adfc1301c5 100644 --- a/wasm/wasm_source/src/tx_update_account.rs +++ b/wasm/wasm_source/src/tx_update_account.rs @@ -20,7 +20,7 @@ fn apply_tx(ctx: &mut Ctx, tx: Tx) -> TxResult { debug_log!("update VP for: {:#?}", tx_data.addr); if let Some(hash) = tx_data.vp_code_hash { - let vp_code_hash = signed + let vp_code_sec = signed .get_section(&hash) .ok_or_err_msg("vp code section not found") .map_err(|err| { @@ -32,11 +32,13 @@ fn apply_tx(ctx: &mut Ctx, tx: Tx) -> TxResult { .map_err(|err| { ctx.set_commitment_sentinel(); err - })? - .code - .hash(); + })?; - ctx.update_validity_predicate(owner, vp_code_hash)?; + ctx.update_validity_predicate( + owner, + vp_code_sec.code.hash(), + &vp_code_sec.tag, + )?; } if let Some(threshold) = tx_data.threshold { diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index a50980f612..1fb10dc588 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -181,7 +181,7 @@ mod tests { let tx_code = vec![]; let tx_data = withdraw.serialize_to_vec(); let mut tx = Tx::new(ChainId::default(), None); - tx.add_code(tx_code) + tx.add_code(tx_code, None) .add_serialized_data(tx_data) .sign_wrapper(key); let signed_tx = tx; diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/wasm_source/src/vp_implicit.rs index db29995c2a..1e49fa8cb8 100644 --- a/wasm/wasm_source/src/vp_implicit.rs +++ b/wasm/wasm_source/src/vp_implicit.rs @@ -537,7 +537,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -667,7 +667,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -832,7 +832,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -870,7 +870,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -916,7 +916,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -925,7 +925,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -971,7 +971,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -979,7 +979,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.set_data(Data::new(vec![])); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs index 6950be2111..d8144d441c 100644 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ b/wasm/wasm_source/src/vp_testnet_faucet.rs @@ -214,7 +214,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -254,7 +254,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -263,7 +263,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -400,7 +400,7 @@ mod tests { vp_env.has_valid_pow = true; let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(solution_bytes)); - tx_data.set_code(Code::new(vec![])); + tx_data.set_code(Code::new(vec![], None)); tx_data.add_section(Section::Signature(Signature::new( vec![tx_data.raw_header_hash()], [(0, target_key)].into_iter().collect(), @@ -454,7 +454,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index 7799a30ad8..f13560d134 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -380,7 +380,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -555,7 +555,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -713,7 +713,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.set_data(Data::new(vec![])); tx.add_section(Section::Signature(Signature::new( vec![ tx.raw_header_hash()], @@ -750,14 +750,14 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); let vp_env = vp_host_env::take(); let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); - tx_data.set_code(Code::new(vec![])); + tx_data.set_code(Code::new(vec![], None)); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); let verifiers: BTreeSet
= BTreeSet::default(); @@ -792,7 +792,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -801,7 +801,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -847,7 +847,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -856,7 +856,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -903,7 +903,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -912,7 +912,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -959,7 +959,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -968,7 +968,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -1015,7 +1015,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -1023,7 +1023,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.set_data(Data::new(vec![])); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], diff --git a/wasm/wasm_source/src/vp_validator.rs b/wasm/wasm_source/src/vp_validator.rs index 7714205e53..4541a13a12 100644 --- a/wasm/wasm_source/src/vp_validator.rs +++ b/wasm/wasm_source/src/vp_validator.rs @@ -389,7 +389,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -575,7 +575,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![secret_key]), @@ -734,7 +734,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -770,7 +770,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -811,7 +811,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -820,7 +820,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -866,7 +866,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -875,7 +875,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -922,7 +922,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -931,7 +931,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -978,7 +978,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -987,7 +987,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); tx.set_data(Data::new(vec![])); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], pks_map.index_secret_keys(vec![keypair]), @@ -1034,7 +1034,7 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Update VP in a transaction tx::ctx() - .update_validity_predicate(address, vp_hash) + .update_validity_predicate(address, vp_hash, &None) .unwrap(); }); @@ -1042,7 +1042,7 @@ mod tests { let mut vp_env = vp_host_env::take(); let mut tx = vp_env.tx.clone(); - tx.set_code(Code::new(vec![])); + tx.set_code(Code::new(vec![], None)); tx.set_data(Data::new(vec![])); tx.add_section(Section::Signature(Signature::new( vec![tx.raw_header_hash()], diff --git a/wasm_for_tests/tx_fail.wasm b/wasm_for_tests/tx_fail.wasm index 0da71e5fcb..947c0e92da 100755 Binary files a/wasm_for_tests/tx_fail.wasm and b/wasm_for_tests/tx_fail.wasm differ diff --git a/wasm_for_tests/tx_memory_limit.wasm b/wasm_for_tests/tx_memory_limit.wasm index 5aac6002b3..7fdfdd43a8 100755 Binary files a/wasm_for_tests/tx_memory_limit.wasm and b/wasm_for_tests/tx_memory_limit.wasm differ diff --git a/wasm_for_tests/tx_mint_tokens.wasm b/wasm_for_tests/tx_mint_tokens.wasm index 03736d7e45..761e1a14e9 100755 Binary files a/wasm_for_tests/tx_mint_tokens.wasm and b/wasm_for_tests/tx_mint_tokens.wasm differ diff --git a/wasm_for_tests/tx_no_op.wasm b/wasm_for_tests/tx_no_op.wasm index 27b5fce4ab..a6c96688f1 100755 Binary files a/wasm_for_tests/tx_no_op.wasm and b/wasm_for_tests/tx_no_op.wasm differ diff --git a/wasm_for_tests/tx_proposal_code.wasm b/wasm_for_tests/tx_proposal_code.wasm index c8f76e568d..91105a8940 100755 Binary files a/wasm_for_tests/tx_proposal_code.wasm and b/wasm_for_tests/tx_proposal_code.wasm differ diff --git a/wasm_for_tests/tx_read_storage_key.wasm b/wasm_for_tests/tx_read_storage_key.wasm index fff0c4164e..a57c4b846d 100755 Binary files a/wasm_for_tests/tx_read_storage_key.wasm and b/wasm_for_tests/tx_read_storage_key.wasm differ diff --git a/wasm_for_tests/tx_write.wasm b/wasm_for_tests/tx_write.wasm index 66acd7c6f7..bb4f097fd4 100755 Binary files a/wasm_for_tests/tx_write.wasm and b/wasm_for_tests/tx_write.wasm differ diff --git a/wasm_for_tests/tx_write_storage_key.wasm b/wasm_for_tests/tx_write_storage_key.wasm index 5822b157de..2f6e3946b4 100755 Binary files a/wasm_for_tests/tx_write_storage_key.wasm and b/wasm_for_tests/tx_write_storage_key.wasm differ diff --git a/wasm_for_tests/vp_always_false.wasm b/wasm_for_tests/vp_always_false.wasm index cfaa632035..98c4f741d4 100755 Binary files a/wasm_for_tests/vp_always_false.wasm and b/wasm_for_tests/vp_always_false.wasm differ diff --git a/wasm_for_tests/vp_always_true.wasm b/wasm_for_tests/vp_always_true.wasm index bb94db2022..0b095b35bd 100755 Binary files a/wasm_for_tests/vp_always_true.wasm and b/wasm_for_tests/vp_always_true.wasm differ diff --git a/wasm_for_tests/vp_eval.wasm b/wasm_for_tests/vp_eval.wasm index 003e97503a..b27f337db2 100755 Binary files a/wasm_for_tests/vp_eval.wasm and b/wasm_for_tests/vp_eval.wasm differ diff --git a/wasm_for_tests/vp_memory_limit.wasm b/wasm_for_tests/vp_memory_limit.wasm index 3ce894054b..2fca9ebe71 100755 Binary files a/wasm_for_tests/vp_memory_limit.wasm and b/wasm_for_tests/vp_memory_limit.wasm differ diff --git a/wasm_for_tests/vp_read_storage_key.wasm b/wasm_for_tests/vp_read_storage_key.wasm index 2b0ff8a148..f54477d842 100755 Binary files a/wasm_for_tests/vp_read_storage_key.wasm and b/wasm_for_tests/vp_read_storage_key.wasm differ