Skip to content

Commit

Permalink
Merge branch 'murisi/tx-type-tag2' (#2182)
Browse files Browse the repository at this point in the history
* origin/murisi/tx-type-tag2:
  Added changelog entry.
  Centralized the definitions of WASM paths.
  Added validation for the VP WASM hashes in transactions.
  Now produce test-vectors of signed transactions as well.
  Print validator email, website, discord handle, and description in test-vectors.
  Modified test-vector generation to use VP tags.
  Now adding type tag for VP hashes.
  Removed the degenerate PoW type.
  Now use code tags to discriminate between transaction types in test-vector generation.
  Added transaction type tag field.
  • Loading branch information
Gianmarco Fraccaroli authored and brentstone committed Nov 20, 2023
2 parents 4600b17 + 385714e commit 0ebfc46
Show file tree
Hide file tree
Showing 60 changed files with 656 additions and 474 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/2182-tx-type-tag2.md
Original file line number Diff line number Diff line change
@@ -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))
57 changes: 26 additions & 31 deletions apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()),
Expand Down
42 changes: 11 additions & 31 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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<WalletAddress> = arg("address");
pub const ALIAS_OPT: ArgOpt<String> = ALIAS.opt();
pub const ALIAS: Arg<String> = arg("alias");
Expand Down
62 changes: 58 additions & 4 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
}
Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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?;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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?;
}

Expand Down Expand Up @@ -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?;
}

Expand Down Expand Up @@ -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?;
}

Expand Down Expand Up @@ -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?;
}

Expand All @@ -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?;
Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand Down Expand Up @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand All @@ -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?;
}

Expand Down
Loading

0 comments on commit 0ebfc46

Please sign in to comment.