Skip to content

Commit

Permalink
Merge branch 'murisi/fix-tx-malleability' into murisi/fix-tx-malleabi…
Browse files Browse the repository at this point in the history
…lity-draft2
  • Loading branch information
murisi committed Jul 2, 2023
2 parents 63c6ea6 + d52a137 commit a3ab7f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
20 changes: 12 additions & 8 deletions wasm/wasm_source/src/vp_implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -661,8 +662,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -829,7 +831,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &secret_key)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &secret_key)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -915,8 +918,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -944,8 +948,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -962,10 +966,10 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down
11 changes: 7 additions & 4 deletions wasm/wasm_source/src/vp_testnet_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn validate_tx(
#[cfg(test)]
mod tests {
use address::testing::arb_non_internal_address;
use namada::proto::{Data, Signature};
use namada::proto::{Code, Data, Signature};
use namada::types::transaction::TxType;
use namada_test_utils::TestWasms;
// Use this as `#[test]` annotation to enable logging
Expand Down Expand Up @@ -260,8 +260,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -390,7 +391,8 @@ mod tests {
vp_env.has_valid_pow = true;
let mut tx_data = Tx::new(TxType::Raw);
tx_data.set_data(Data::new(solution_bytes));
tx_data.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash()], &target_key)));
tx_data.set_code(Code::new(vec![]));
tx_data.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash(), *tx_data.code_sechash()], &target_key)));
let keys_changed: BTreeSet<storage::Key> =
vp_env.all_touched_storage_keys();
let verifiers: BTreeSet<Address> = BTreeSet::default();
Expand Down Expand Up @@ -437,7 +439,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down
28 changes: 18 additions & 10 deletions wasm/wasm_source/src/vp_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -552,8 +553,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -711,8 +713,9 @@ 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_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -750,6 +753,7 @@ mod tests {
let vp_env = vp_host_env::take();
let mut tx_data = Tx::new(TxType::Raw);
tx_data.set_data(Data::new(vec![]));
tx_data.set_code(Code::new(vec![]));
let keys_changed: BTreeSet<storage::Key> =
vp_env.all_touched_storage_keys();
let verifiers: BTreeSet<Address> = BTreeSet::default();
Expand Down Expand Up @@ -792,8 +796,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -839,8 +844,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -887,8 +893,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -939,8 +946,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -968,8 +976,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -986,7 +994,7 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash(), *tx.code_sechash()],
Expand Down
27 changes: 17 additions & 10 deletions wasm/wasm_source/src/vp_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -570,8 +571,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -729,7 +731,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -809,8 +812,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -856,8 +860,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -904,8 +909,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -956,8 +962,9 @@ 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.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -985,8 +992,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -1003,7 +1010,7 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash(), *tx.code_sechash()],
Expand Down

0 comments on commit a3ab7f1

Please sign in to comment.