From db402ef26b1d0f8569bc9fd6452af4965279ada8 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Sun, 2 Jul 2023 08:17:49 +0200 Subject: [PATCH 1/3] Disable encrypting transactions when sending. --- shared/src/ledger/signing.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/shared/src/ledger/signing.rs b/shared/src/ledger/signing.rs index af64dabe12..b90a0d8a44 100644 --- a/shared/src/ledger/signing.rs +++ b/shared/src/ledger/signing.rs @@ -358,8 +358,6 @@ pub async fn sign_wrapper< // Remove all the sensitive sections tx.protocol_filter(); - // Encrypt all sections not relating to the header - tx.encrypt(&Default::default()); // Then sign over the bound wrapper committing to all other sections tx.add_section(Section::Signature(Signature::new(tx.sechashes(), keypair))); // We use this to determine when the wrapper tx makes it on-chain From 793d901853d0a69c539040d441738a273dd28935 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Sun, 2 Jul 2023 17:45:01 +0200 Subject: [PATCH 2/3] Stop encrypting transactions in tests. --- .../lib/node/ledger/shell/finalize_block.rs | 12 +---- apps/src/lib/node/ledger/shell/mod.rs | 11 +--- .../lib/node/ledger/shell/prepare_proposal.rs | 25 +++------ .../lib/node/ledger/shell/process_proposal.rs | 51 +++++-------------- core/src/types/transaction/mod.rs | 4 +- core/src/types/transaction/wrapper.rs | 10 ++-- 6 files changed, 28 insertions(+), 85 deletions(-) diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 02d85c964c..88a13b347f 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -991,9 +991,8 @@ mod test_finalize_block { wrapper.set_code(Code::new( format!("transaction data: {}", i).as_bytes().to_owned(), )); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); if i > 1 { @@ -1066,7 +1065,6 @@ mod test_finalize_block { outer_tx.set_data(Data::new( String::from("transaction data").as_bytes().to_owned(), )); - outer_tx.encrypt(&Default::default()); shell.enqueue_tx(outer_tx.clone()); outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { @@ -1192,7 +1190,6 @@ mod test_finalize_block { .as_bytes() .to_owned(), )); - outer_tx.encrypt(&Default::default()); shell.enqueue_tx(outer_tx.clone()); outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] @@ -1229,12 +1226,8 @@ mod test_finalize_block { .as_bytes() .to_owned(), )); - wrapper_tx.encrypt(&Default::default()); wrapper_tx.add_section(Section::Signature(Signature::new( - vec![ - wrapper_tx.header_hash(), - wrapper_tx.sections[0].get_hash(), - ], + wrapper_tx.sechashes(), &keypair, ))); valid_txs.push(wrapper_tx.clone()); @@ -1775,7 +1768,6 @@ mod test_finalize_block { "Encrypted transaction data".as_bytes().to_owned(), )); let mut decrypted_tx = wrapper_tx.clone(); - wrapper_tx.encrypt(&Default::default()); decrypted_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index a5ffcef28f..b434dec40e 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -1272,7 +1272,6 @@ mod test_utils { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); shell.wl_storage.storage.tx_queue.push(TxInQueue { tx: wrapper, @@ -1341,7 +1340,6 @@ mod test_mempool_validate { unsigned_wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); unsigned_wrapper .set_data(Data::new("transaction data".as_bytes().to_owned())); - unsigned_wrapper.encrypt(&Default::default()); let mut result = shell.mempool_validate( unsigned_wrapper.to_bytes().as_ref(), @@ -1378,12 +1376,8 @@ mod test_mempool_validate { invalid_wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); invalid_wrapper .set_data(Data::new("transaction data".as_bytes().to_owned())); - invalid_wrapper.encrypt(&Default::default()); invalid_wrapper.add_section(Section::Signature(Signature::new( - vec![ - invalid_wrapper.header_hash(), - invalid_wrapper.sections[0].get_hash(), - ], + invalid_wrapper.sechashes(), &keypair, ))); @@ -1446,9 +1440,8 @@ mod test_mempool_validate { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index 3a91612e44..cd5687ddad 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -327,7 +327,6 @@ mod test_prepare_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction_data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); let wrapper = wrapper.to_bytes(); #[allow(clippy::redundant_clone)] let req = RequestPrepareProposal { @@ -370,9 +369,8 @@ mod test_prepare_proposal { tx.set_data(Data::new( format!("transaction data: {}", i).as_bytes().to_owned(), )); - tx.encrypt(&Default::default()); tx.add_section(Section::Signature(Signature::new( - vec![tx.header_hash(), tx.sections[0].get_hash()], + tx.sechashes(), &keypair, ))); @@ -437,9 +435,8 @@ mod test_prepare_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -489,9 +486,8 @@ mod test_prepare_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -530,9 +526,8 @@ mod test_prepare_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); let inner_unsigned_hash = @@ -585,9 +580,8 @@ mod test_prepare_proposal { wrapper.set_code(tx_code.clone()); let tx_data = Data::new("transaction data".as_bytes().to_owned()); wrapper.set_data(tx_data.clone()); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -607,12 +601,8 @@ mod test_prepare_proposal { new_wrapper.header.timestamp = wrapper.header.timestamp; new_wrapper.set_code(tx_code); new_wrapper.set_data(tx_data); - new_wrapper.encrypt(&Default::default()); new_wrapper.add_section(Section::Signature(Signature::new( - vec![ - new_wrapper.header_hash(), - new_wrapper.sections[0].get_hash(), - ], + wrapper.sechashes(), &keypair, ))); @@ -653,9 +643,8 @@ mod test_prepare_proposal { wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper_tx .set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper_tx.encrypt(&Default::default()); wrapper_tx.add_section(Section::Signature(Signature::new( - vec![wrapper_tx.header_hash(), wrapper_tx.sections[0].get_hash()], + wrapper_tx.sechashes(), &keypair, ))); diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index f81af5bc21..8946621e1d 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -549,7 +549,6 @@ mod test_process_proposal { outer_tx.header.chain_id = shell.chain_id.clone(); outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - outer_tx.encrypt(&Default::default()); let tx = outer_tx.to_bytes(); #[allow(clippy::redundant_clone)] let request = ProcessProposal { @@ -594,9 +593,8 @@ mod test_process_proposal { outer_tx.header.chain_id = shell.chain_id.clone(); outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - outer_tx.encrypt(&Default::default()); outer_tx.add_section(Section::Signature(Signature::new( - vec![outer_tx.header_hash(), outer_tx.sections[0].get_hash()], + outer_tx.sechashes(), &keypair, ))); let mut new_tx = outer_tx.clone(); @@ -658,9 +656,8 @@ mod test_process_proposal { outer_tx.header.chain_id = shell.chain_id.clone(); outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - outer_tx.encrypt(&Default::default()); outer_tx.add_section(Section::Signature(Signature::new( - vec![outer_tx.header_hash(), outer_tx.sections[0].get_hash()], + outer_tx.sechashes(), &keypair, ))); @@ -725,9 +722,8 @@ mod test_process_proposal { outer_tx.header.chain_id = shell.chain_id.clone(); outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); outer_tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - outer_tx.encrypt(&Default::default()); outer_tx.add_section(Section::Signature(Signature::new( - vec![outer_tx.header_hash(), outer_tx.sections[0].get_hash()], + outer_tx.sechashes(), &keypair, ))); @@ -778,7 +774,6 @@ mod test_process_proposal { outer_tx.set_data(Data::new( format!("transaction data: {}", i).as_bytes().to_owned(), )); - outer_tx.encrypt(&Default::default()); shell.enqueue_tx(outer_tx.clone()); outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { @@ -835,7 +830,6 @@ mod test_process_proposal { tx.header.chain_id = shell.chain_id.clone(); tx.set_code(Code::new("wasm_code".as_bytes().to_owned())); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - tx.encrypt(&Default::default()); shell.enqueue_tx(tx.clone()); tx.header.tx_type = TxType::Decrypted(DecryptedTx::Undecryptable); @@ -885,7 +879,6 @@ mod test_process_proposal { tx.set_data(Data::new("transaction data".as_bytes().to_owned())); tx.set_code_sechash(Hash([0u8; 32])); tx.set_data_sechash(Hash([0u8; 32])); - tx.encrypt(&Default::default()); shell.enqueue_tx(tx.clone()); @@ -1034,9 +1027,8 @@ 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.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -1109,9 +1101,8 @@ mod test_process_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -1167,9 +1158,8 @@ mod test_process_proposal { wrapper.header.chain_id = shell.chain_id.clone(); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); let inner_unsigned_hash = @@ -1258,9 +1248,8 @@ mod test_process_proposal { wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); let mut new_wrapper = wrapper.clone(); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); let inner_unsigned_hash = @@ -1277,12 +1266,8 @@ mod test_process_proposal { #[cfg(not(feature = "mainnet"))] None, )))); - new_wrapper.encrypt(&Default::default()); new_wrapper.add_section(Section::Signature(Signature::new( - vec![ - new_wrapper.header_hash(), - new_wrapper.sections[0].get_hash(), - ], + new_wrapper.sechashes(), &keypair, ))); @@ -1333,9 +1318,8 @@ mod test_process_proposal { wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); let mut protocol_tx = wrapper.clone(); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -1401,17 +1385,12 @@ mod test_process_proposal { wrapper .set_data(Data::new("new transaction data".as_bytes().to_owned())); let mut decrypted = wrapper.clone(); - wrapper.encrypt(&Default::default()); decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted { has_valid_pow: false, })); decrypted.add_section(Section::Signature(Signature::new( - vec![ - decrypted.header_hash(), - decrypted.sections[0].get_hash(), - decrypted.sections[1].get_hash(), - ], + decrypted.sechashes(), &keypair, ))); let wrapper_in_queue = TxInQueue { @@ -1465,9 +1444,8 @@ mod test_process_proposal { wrapper.header.expiration = Some(DateTimeUtc::now()); wrapper.set_code(Code::new("wasm_code".as_bytes().to_owned())); wrapper.set_data(Data::new("transaction data".as_bytes().to_owned())); - wrapper.encrypt(&Default::default()); wrapper.add_section(Section::Signature(Signature::new( - vec![wrapper.header_hash(), wrapper.sections[0].get_hash()], + wrapper.sechashes(), &keypair, ))); @@ -1510,17 +1488,12 @@ mod test_process_proposal { wrapper .set_data(Data::new("new transaction data".as_bytes().to_owned())); let mut decrypted = wrapper.clone(); - wrapper.encrypt(&Default::default()); decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted { has_valid_pow: false, })); decrypted.add_section(Section::Signature(Signature::new( - vec![ - decrypted.header_hash(), - decrypted.sections[0].get_hash(), - decrypted.sections[1].get_hash(), - ], + decrypted.sechashes(), &keypair, ))); let wrapper_in_queue = TxInQueue { diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 099c3a2018..9c93f42fc9 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -331,9 +331,8 @@ mod test_process_tx { )))); tx.set_code(Code::new("wasm code".as_bytes().to_owned())); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - tx.encrypt(&Default::default()); tx.add_section(Section::Signature(Signature::new( - vec![tx.header_hash(), tx.sections[0].get_hash()], + tx.sechashes(), &keypair, ))); @@ -367,7 +366,6 @@ mod test_process_tx { )))); tx.set_code(Code::new("wasm code".as_bytes().to_owned())); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); - tx.encrypt(&Default::default()); let result = tx.validate_tx().expect_err("Test failed"); assert_matches!(result, TxError::SigError(_)); } diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index d1427a0c76..66f5aa8e5f 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -446,6 +446,10 @@ pub mod wrapper_tx { tx.set_code(Code::new("wasm code".as_bytes().to_owned())); tx.set_data(Data::new("transaction data".as_bytes().to_owned())); + tx.add_section(Section::Signature(Signature::new( + tx.sechashes(), + &keypair, + ))); // we now try to alter the inner tx maliciously // malicious transaction @@ -453,12 +457,6 @@ pub mod wrapper_tx { // We change the commitment appropriately let malicious = "Give me all the money".as_bytes().to_owned(); tx.set_data(Data::new(malicious.clone())); - tx.encrypt(&Default::default()); - - tx.add_section(Section::Signature(Signature::new( - vec![tx.header_hash(), tx.sections[0].get_hash()], - &keypair, - ))); // we check ciphertext validity still passes assert!(tx.validate_ciphertext()); From 9028fe299f4f8c3690f13f6a4b99605e01d9f033 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Mon, 3 Jul 2023 11:23:00 +0200 Subject: [PATCH 3/3] Added a changelog entry. --- .changelog/unreleased/improvements/1636-disable-encryption.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1636-disable-encryption.md diff --git a/.changelog/unreleased/improvements/1636-disable-encryption.md b/.changelog/unreleased/improvements/1636-disable-encryption.md new file mode 100644 index 0000000000..7a407171d4 --- /dev/null +++ b/.changelog/unreleased/improvements/1636-disable-encryption.md @@ -0,0 +1,2 @@ +- Disable encryption when sending transactions + ([\#1636](https://github.com/anoma/namada/pull/1636)) \ No newline at end of file