diff --git a/.changelog/unreleased/improvements/1873-remove-pow.md b/.changelog/unreleased/improvements/1873-remove-pow.md new file mode 100644 index 0000000000..b18baf6d7f --- /dev/null +++ b/.changelog/unreleased/improvements/1873-remove-pow.md @@ -0,0 +1,2 @@ +- Remove pay-fee-with-pow feature and faucet vp. + ([\#1873](https://github.com/anoma/namada/pull/1873)) \ No newline at end of file diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index c3a46d3fd7..2cb05cff2f 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -440,8 +440,6 @@ pub async fn submit_init_validator< &mut tx, signing_data.fee_payer.clone(), None, - #[cfg(not(feature = "mainnet"))] - false, ) .await?; diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index 0e5fced67e..eced8e1047 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -6,8 +6,6 @@ use borsh::{BorshDeserialize, BorshSerialize}; use derivative::Derivative; use namada::core::ledger::governance::parameters::GovernanceParameters; use namada::core::ledger::pgf::parameters::PgfParameters; -#[cfg(not(feature = "mainnet"))] -use namada::core::ledger::testnet_pow; use namada::ledger::eth_bridge::EthereumBridgeConfig; use namada::ledger::parameters::EpochDuration; use namada::ledger::pos::{Dec, GenesisValidator, PosParams}; @@ -32,8 +30,6 @@ pub mod genesis_config { use eyre::Context; use namada::core::ledger::governance::parameters::GovernanceParameters; use namada::core::ledger::pgf::parameters::PgfParameters; - #[cfg(not(feature = "mainnet"))] - use namada::core::ledger::testnet_pow; use namada::ledger::parameters::EpochDuration; use namada::ledger::pos::{Dec, GenesisValidator, PosParams}; use namada::types::address::Address; @@ -42,7 +38,6 @@ pub mod genesis_config { use namada::types::key::*; use namada::types::time::Rfc3339String; use namada::types::token::Denomination; - use namada::types::uint::Uint; use namada::types::{storage, token}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -116,13 +111,6 @@ pub mod genesis_config { // Name of the native token - this must one of the tokens included in // the `token` field pub native_token: String, - #[cfg(not(feature = "mainnet"))] - /// Testnet faucet PoW difficulty - defaults to `0` when not set - pub faucet_pow_difficulty: Option, - #[cfg(not(feature = "mainnet"))] - /// Testnet faucet withdrawal limit - defaults to 1000 tokens when not - /// set - pub faucet_withdrawal_limit: Option, // Initial validator set pub validator: HashMap, // Token accounts present at genesis @@ -535,10 +523,6 @@ pub mod genesis_config { let GenesisConfig { genesis_time, native_token, - #[cfg(not(feature = "mainnet"))] - faucet_pow_difficulty, - #[cfg(not(feature = "mainnet"))] - faucet_withdrawal_limit, validator, token, established, @@ -699,10 +683,6 @@ pub mod genesis_config { let mut genesis = Genesis { genesis_time: genesis_time.try_into().unwrap(), native_token, - #[cfg(not(feature = "mainnet"))] - faucet_pow_difficulty, - #[cfg(not(feature = "mainnet"))] - faucet_withdrawal_limit, validators: validators.into_values().collect(), token_accounts, established_accounts: established_accounts.into_values().collect(), @@ -753,10 +733,6 @@ pub mod genesis_config { pub struct Genesis { pub genesis_time: DateTimeUtc, pub native_token: Address, - #[cfg(not(feature = "mainnet"))] - pub faucet_pow_difficulty: Option, - #[cfg(not(feature = "mainnet"))] - pub faucet_withdrawal_limit: Option, pub validators: Vec, pub token_accounts: Vec, pub established_accounts: Vec, @@ -1157,10 +1133,6 @@ pub fn genesis(num_validators: u64) -> Genesis { }, }), native_token: address::nam(), - #[cfg(not(feature = "mainnet"))] - faucet_pow_difficulty: None, - #[cfg(not(feature = "mainnet"))] - faucet_withdrawal_limit: None, } } diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 57ed9269e0..51a745f6e1 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -248,9 +248,6 @@ where .flatten() }) .flatten(); - #[cfg(not(feature = "mainnet"))] - let has_valid_pow = - self.invalidate_pow_solution_if_valid(wrapper); if let Err(msg) = protocol::charge_fee( wrapper, masp_transaction, @@ -260,8 +257,6 @@ where &mut self.vp_wasm_cache, &mut self.tx_wasm_cache, ), - #[cfg(not(feature = "mainnet"))] - has_valid_pow, Some(&native_block_proposer_address), &mut BTreeSet::default(), ) { @@ -281,165 +276,146 @@ where continue; } - let ( - mut tx_event, - tx_unsigned_hash, - mut tx_gas_meter, - has_valid_pow, - wrapper, - ) = match &tx_header.tx_type { - TxType::Wrapper(wrapper) => { - stats.increment_wrapper_txs(); - let tx_event = Event::new_tx_event(&tx, height.0); - #[cfg(not(feature = "mainnet"))] - let has_valid_pow = - self.invalidate_pow_solution_if_valid(wrapper); - - let gas_meter = TxGasMeter::new(wrapper.gas_limit); - - ( - tx_event, - None, - gas_meter, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, - Some(tx.clone()), - ) - } - TxType::Decrypted(inner) => { - // We remove the corresponding wrapper tx from the queue - let mut tx_in_queue = self - .wl_storage - .storage - .tx_queue - .pop() - .expect("Missing wrapper tx in queue"); - let mut event = Event::new_tx_event(&tx, height.0); - - match inner { - DecryptedTx::Decrypted { has_valid_pow: _ } => { - if let Some(code_sec) = tx - .get_section(tx.code_sechash()) - .and_then(|x| Section::code_sec(x.as_ref())) - { - stats.increment_tx_type( - code_sec.code.hash().to_string(), + let (mut tx_event, tx_unsigned_hash, mut tx_gas_meter, wrapper) = + match &tx_header.tx_type { + TxType::Wrapper(wrapper) => { + stats.increment_wrapper_txs(); + let tx_event = Event::new_tx_event(&tx, height.0); + let gas_meter = TxGasMeter::new(wrapper.gas_limit); + (tx_event, None, gas_meter, Some(tx.clone())) + } + TxType::Decrypted(inner) => { + // We remove the corresponding wrapper tx from the queue + let mut tx_in_queue = self + .wl_storage + .storage + .tx_queue + .pop() + .expect("Missing wrapper tx in queue"); + let mut event = Event::new_tx_event(&tx, height.0); + + match inner { + DecryptedTx::Decrypted => { + if let Some(code_sec) = tx + .get_section(tx.code_sechash()) + .and_then(|x| Section::code_sec(x.as_ref())) + { + stats.increment_tx_type( + code_sec.code.hash().to_string(), + ); + } + } + DecryptedTx::Undecryptable => { + tracing::info!( + "Tx with hash {} was un-decryptable", + tx_in_queue.tx.header_hash() ); + event["info"] = + "Transaction is invalid.".into(); + event["log"] = "Transaction could not be \ + decrypted." + .into(); + event["code"] = + ErrorCodes::Undecryptable.into(); + continue; } } - DecryptedTx::Undecryptable => { - tracing::info!( - "Tx with hash {} was un-decryptable", - tx_in_queue.tx.header_hash() - ); - event["info"] = "Transaction is invalid.".into(); - event["log"] = - "Transaction could not be decrypted.".into(); - event["code"] = ErrorCodes::Undecryptable.into(); - continue; - } - } - ( - event, - Some( - tx_in_queue - .tx - .update_header(TxType::Raw) - .header_hash(), + ( + event, + Some( + tx_in_queue + .tx + .update_header(TxType::Raw) + .header_hash(), + ), + TxGasMeter::new_from_sub_limit(tx_in_queue.gas), + None, + ) + } + TxType::Raw => { + tracing::error!( + "Internal logic error: FinalizeBlock received a \ + TxType::Raw transaction" + ); + continue; + } + TxType::Protocol(protocol_tx) => match protocol_tx.tx { + ProtocolTxType::BridgePoolVext + | ProtocolTxType::BridgePool + | ProtocolTxType::ValSetUpdateVext + | ProtocolTxType::ValidatorSetUpdate => ( + Event::new_tx_event(&tx, height.0), + None, + TxGasMeter::new_from_sub_limit(0.into()), + None, ), - TxGasMeter::new_from_sub_limit(tx_in_queue.gas), - #[cfg(not(feature = "mainnet"))] - false, - None, - ) - } - TxType::Raw => { - tracing::error!( - "Internal logic error: FinalizeBlock received a \ - TxType::Raw transaction" - ); - continue; - } - TxType::Protocol(protocol_tx) => match protocol_tx.tx { - ProtocolTxType::BridgePoolVext - | ProtocolTxType::BridgePool - | ProtocolTxType::ValSetUpdateVext - | ProtocolTxType::ValidatorSetUpdate => ( - Event::new_tx_event(&tx, height.0), - None, - TxGasMeter::new_from_sub_limit(0.into()), - #[cfg(not(feature = "mainnet"))] - false, - None, - ), - ProtocolTxType::EthEventsVext => { - let ext = + ProtocolTxType::EthEventsVext => { + let ext = ethereum_tx_data_variants::EthEventsVext::try_from( &tx, ) .unwrap(); - if self - .mode - .get_validator_address() - .map(|validator| { - validator == &ext.data.validator_addr - }) - .unwrap_or(false) - { - for event in ext.data.ethereum_events.iter() { - self.mode.dequeue_eth_event(event); + if self + .mode + .get_validator_address() + .map(|validator| { + validator == &ext.data.validator_addr + }) + .unwrap_or(false) + { + for event in ext.data.ethereum_events.iter() { + self.mode.dequeue_eth_event(event); + } } + ( + Event::new_tx_event(&tx, height.0), + None, + TxGasMeter::new_from_sub_limit(0.into()), + None, + ) } - ( - Event::new_tx_event(&tx, height.0), - None, - TxGasMeter::new_from_sub_limit(0.into()), - #[cfg(not(feature = "mainnet"))] - false, - None, - ) - } - ProtocolTxType::EthereumEvents => { - let digest = + ProtocolTxType::EthereumEvents => { + let digest = ethereum_tx_data_variants::EthereumEvents::try_from( &tx, ).unwrap(); - if let Some(address) = - self.mode.get_validator_address().cloned() - { - let this_signer = &( - address, - self.wl_storage.storage.get_last_block_height(), - ); - for MultiSignedEthEvent { event, signers } in - &digest.events + if let Some(address) = + self.mode.get_validator_address().cloned() { - if signers.contains(this_signer) { - self.mode.dequeue_eth_event(event); + let this_signer = &( + address, + self.wl_storage + .storage + .get_last_block_height(), + ); + for MultiSignedEthEvent { event, signers } in + &digest.events + { + if signers.contains(this_signer) { + self.mode.dequeue_eth_event(event); + } } } + ( + Event::new_tx_event(&tx, height.0), + None, + TxGasMeter::new_from_sub_limit(0.into()), + None, + ) } - ( - Event::new_tx_event(&tx, height.0), - None, - TxGasMeter::new_from_sub_limit(0.into()), - #[cfg(not(feature = "mainnet"))] - false, - None, - ) - } - ref protocol_tx_type => { - tracing::error!( - ?protocol_tx_type, - "Internal logic error: FinalizeBlock received an \ - unsupported TxType::Protocol transaction: {:?}", - protocol_tx - ); - continue; - } - }, - }; + ref protocol_tx_type => { + tracing::error!( + ?protocol_tx_type, + "Internal logic error: FinalizeBlock received \ + an unsupported TxType::Protocol transaction: \ + {:?}", + protocol_tx + ); + continue; + } + }, + }; match protocol::dispatch_tx( tx, @@ -454,8 +430,6 @@ where &mut self.vp_wasm_cache, &mut self.tx_wasm_cache, Some(&native_block_proposer_address), - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ) .map_err(Error::TxApply) { @@ -470,8 +444,6 @@ where self.wl_storage.storage.tx_queue.push(TxInQueue { tx: wrapper.expect("Missing expected wrapper"), gas: tx_gas_meter.get_available_gas(), - #[cfg(not(feature = "mainnet"))] - has_valid_pow, }); } else { tracing::trace!( @@ -1145,8 +1117,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper_tx.header.chain_id = shell.chain_id.clone(); @@ -1187,8 +1157,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1201,10 +1169,7 @@ mod test_finalize_block { .checked_sub(Gas::from(outer_tx.to_bytes().len() as u64)) .unwrap(); shell.enqueue_tx(outer_tx.clone(), gas_limit); - outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); outer_tx.decrypt(::G2Affine::prime_subgroup_generator()) .expect("Test failed"); ProcessedTx { @@ -1312,8 +1277,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1327,10 +1290,7 @@ mod test_finalize_block { .unwrap(); shell.enqueue_tx(outer_tx.clone(), gas_limit); - outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); let processed_tx = ProcessedTx { tx: outer_tx.to_bytes(), result: TxResult { @@ -1371,8 +1331,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); let processed_tx = ProcessedTx { @@ -2400,8 +2358,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper_tx.header.chain_id = shell.chain_id.clone(); @@ -2411,10 +2367,7 @@ mod test_finalize_block { )); let mut decrypted_tx = wrapper_tx.clone(); - decrypted_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + decrypted_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); // Write inner hash in storage let inner_hash_key = replay_protection::get_replay_protection_key( @@ -2478,8 +2431,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), 0.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2551,8 +2502,6 @@ mod test_finalize_block { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2635,8 +2584,6 @@ mod test_finalize_block { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), 5_000_000.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); diff --git a/apps/src/lib/node/ledger/shell/governance.rs b/apps/src/lib/node/ledger/shell/governance.rs index 7e9d72eac3..cc79c9a9f0 100644 --- a/apps/src/lib/node/ledger/shell/governance.rs +++ b/apps/src/lib/node/ledger/shell/governance.rs @@ -265,10 +265,7 @@ where let pending_execution_key = gov_storage::get_proposal_execution_key(id); shell.wl_storage.write(&pending_execution_key, ())?; - let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + 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)); @@ -284,8 +281,6 @@ where &mut shell.vp_wasm_cache, &mut shell.tx_wasm_cache, None, - #[cfg(not(feature = "mainnet"))] - false, ); shell .wl_storage diff --git a/apps/src/lib/node/ledger/shell/init_chain.rs b/apps/src/lib/node/ledger/shell/init_chain.rs index b650e2d730..e25e72c8d1 100644 --- a/apps/src/lib/node/ledger/shell/init_chain.rs +++ b/apps/src/lib/node/ledger/shell/init_chain.rs @@ -2,8 +2,6 @@ use std::collections::HashMap; use std::hash::Hash; -#[cfg(not(feature = "mainnet"))] -use namada::core::ledger::testnet_pow; use namada::ledger::eth_bridge::EthBridgeStatus; use namada::ledger::parameters::{self, Parameters}; use namada::ledger::pos::{staking_token_address, PosParams}; @@ -18,7 +16,6 @@ use namada::types::dec::Dec; use namada::types::hash::Hash as CodeHash; use namada::types::key::*; use namada::types::time::{DateTimeUtc, TimeZone, Utc}; -use namada::types::token; use super::*; use crate::facade::tendermint_proto::google::protobuf; @@ -100,24 +97,6 @@ where fee_unshielding_gas_limit, fee_unshielding_descriptions_limit, } = genesis.parameters; - #[cfg(not(feature = "mainnet"))] - // Try to find a faucet account - let faucet_account = { - genesis.established_accounts.iter().find_map( - |genesis::EstablishedAccount { - address, - vp_code_path, - .. - }| { - if vp_code_path == "vp_testnet_faucet.wasm" { - Some(address.clone()) - } else { - None - } - }, - ) - }; - // Store wasm codes into storage let checksums = wasm_loader::Checksums::read_checksums(&self.wasm_dir); for (name, full_name) in checksums.0.iter() { @@ -198,8 +177,6 @@ where pos_gain_d, staked_ratio, pos_inflation_amount, - #[cfg(not(feature = "mainnet"))] - faucet_account, gas_cost, fee_unshielding_gas_limit, fee_unshielding_descriptions_limit, @@ -242,8 +219,6 @@ where // Initialize genesis established accounts self.initialize_established_accounts( - genesis.faucet_pow_difficulty, - genesis.faucet_withdrawal_limit, genesis.established_accounts, &implicit_vp_code_path, )?; @@ -272,8 +247,6 @@ where /// Initialize genesis established accounts fn initialize_established_accounts( &mut self, - faucet_pow_difficulty: Option, - faucet_withdrawal_limit: Option, accounts: Vec, implicit_vp_code_path: &str, ) -> Result<()> { @@ -320,26 +293,8 @@ where for (key, value) in storage { self.wl_storage.write_bytes(&key, value).unwrap(); } - - // When using a faucet WASM, initialize its PoW challenge storage - #[cfg(not(feature = "mainnet"))] - if vp_code_path == "vp_testnet_faucet.wasm" { - let difficulty = faucet_pow_difficulty.unwrap_or_default(); - // withdrawal limit defaults to 1000 NAM when not set - let withdrawal_limit = - faucet_withdrawal_limit.unwrap_or_else(|| { - token::Amount::native_whole(1_000).into() - }); - - testnet_pow::init_faucet_storage( - &mut self.wl_storage, - &address, - difficulty, - withdrawal_limit, - ) - .expect("Couldn't init faucet storage") - } } + Ok(()) } diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 46a985b8fc..4e9cae744f 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -1272,6 +1272,7 @@ where None } }); + // Validate wrapper fees if let Err(e) = self.wrapper_fee_check( &wrapper, @@ -1307,56 +1308,6 @@ where response } - #[cfg(not(feature = "mainnet"))] - /// Check if the tx has a valid PoW solution. Unlike - /// `apply_pow_solution_if_valid`, this won't invalidate the solution. - fn has_valid_pow_solution( - &self, - tx: &namada::types::transaction::WrapperTx, - ) -> bool { - if let Some(solution) = &tx.pow_solution { - if let Some(faucet_address) = - namada::ledger::parameters::read_faucet_account_parameter( - &self.wl_storage, - ) - .expect("Must be able to read faucet account parameter") - { - let source = Address::from(&tx.pk); - return solution - .validate(&self.wl_storage, &faucet_address, source) - .expect("Must be able to validate PoW solutions"); - } - } - false - } - - #[cfg(not(feature = "mainnet"))] - /// Check if the tx has a valid PoW solution and if so invalidate it to - /// prevent replay. - fn invalidate_pow_solution_if_valid( - &mut self, - tx: &namada::types::transaction::WrapperTx, - ) -> bool { - if let Some(solution) = &tx.pow_solution { - if let Some(faucet_address) = - namada::ledger::parameters::read_faucet_account_parameter( - &self.wl_storage, - ) - .expect("Must be able to read faucet account parameter") - { - let source = Address::from(&tx.pk); - return solution - .invalidate_if_valid( - &mut self.wl_storage, - &faucet_address, - &source, - ) - .expect("Must be able to validate PoW solutions"); - } - } - false - } - /// Check that the Wrapper's signer has enough funds to pay fees. If a block /// proposer is provided, updates the balance of the fee payer #[allow(clippy::too_many_arguments)] @@ -1437,8 +1388,6 @@ where vp_wasm_cache, tx_wasm_cache, ), - #[cfg(not(feature = "mainnet"))] - false, ) { Ok(result) => { if !result.is_accepted() { @@ -1462,19 +1411,10 @@ where } let result = match block_proposer { - Some(proposer) => protocol::transfer_fee( - temp_wl_storage, - proposer, - #[cfg(not(feature = "mainnet"))] - self.has_valid_pow_solution(wrapper), - wrapper, - ), - None => protocol::check_fees( - temp_wl_storage, - #[cfg(not(feature = "mainnet"))] - self.has_valid_pow_solution(wrapper), - wrapper, - ), + Some(proposer) => { + protocol::transfer_fee(temp_wl_storage, proposer, wrapper) + } + None => protocol::check_fees(temp_wl_storage, wrapper), }; result.map_err(Error::TxApply) @@ -1836,8 +1776,6 @@ mod test_utils { self.shell.wl_storage.storage.tx_queue.push(TxInQueue { tx, gas: inner_tx_gas, - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, }); } @@ -2054,8 +1992,6 @@ mod test_utils { keypair.ref_to(), Epoch(0), 300_000.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2065,8 +2001,6 @@ mod test_utils { shell.wl_storage.storage.tx_queue.push(TxInQueue { tx: wrapper, gas: u64::MAX.into(), - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, }); // Artificially increase the block height so that chain // will read the new block when restarted @@ -2336,8 +2270,6 @@ mod test_mempool_validate { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); unsigned_wrapper.header.chain_id = shell.chain_id.clone(); @@ -2374,8 +2306,6 @@ mod test_mempool_validate { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); invalid_wrapper.header.chain_id = shell.chain_id.clone(); @@ -2443,8 +2373,6 @@ mod test_mempool_validate { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2602,8 +2530,6 @@ mod test_mempool_validate { keypair.ref_to(), Epoch(0), (block_gas_limit + 1).into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2636,8 +2562,6 @@ mod test_mempool_validate { keypair.ref_to(), Epoch(0), 0.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2670,8 +2594,6 @@ mod test_mempool_validate { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2704,8 +2626,6 @@ mod test_mempool_validate { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2737,8 +2657,6 @@ mod test_mempool_validate { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), 150_000.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2770,8 +2688,6 @@ mod test_mempool_validate { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index e8633940b9..df7a540522 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -259,6 +259,7 @@ where } }) }); + match self.wrapper_fee_check( &wrapper, fee_unshield, @@ -300,17 +301,12 @@ where |TxInQueue { tx, gas: _, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, }| { let mut tx = tx.clone(); match tx.decrypt(privkey).ok() { Some(_) => { - tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: *has_valid_pow, - })); + tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); tx }, // An absent or undecryptable inner_tx are both @@ -644,9 +640,7 @@ mod test_prepare_proposal { #[test] fn test_prepare_proposal_rejects_non_wrapper_tx() { let (shell, _recv, _, _) = test_utils::setup(); - let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - has_valid_pow: true, - })); + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); tx.header.chain_id = shell.chain_id.clone(); let req = RequestPrepareProposal { txs: vec![tx.to_bytes()], @@ -672,8 +666,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -1124,8 +1116,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); tx.header.chain_id = shell.chain_id.clone(); @@ -1146,10 +1136,7 @@ mod test_prepare_proposal { shell.enqueue_tx(tx.clone(), gas); expected_wrapper.push(tx.clone()); req.txs.push(tx.to_bytes()); - tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); expected_decrypted.push(tx.clone()); } // we extract the inner data from the txs for testing @@ -1199,8 +1186,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -1253,8 +1238,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -1295,8 +1278,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -1350,8 +1331,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -1373,8 +1352,6 @@ mod test_prepare_proposal { keypair_2.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); new_wrapper.add_section(Section::Signature(Signature::new( @@ -1410,8 +1387,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper_tx.header.chain_id = shell.chain_id.clone(); @@ -1460,8 +1435,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), (block_gas_limit + 1).into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); @@ -1500,8 +1473,6 @@ mod test_prepare_proposal { keypair.ref_to(), Epoch(0), 0.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); @@ -1540,8 +1511,6 @@ mod test_prepare_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); @@ -1580,8 +1549,6 @@ mod test_prepare_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); @@ -1618,8 +1585,6 @@ mod test_prepare_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); @@ -1656,8 +1621,6 @@ mod test_prepare_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ); let mut wrapper_tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index dca2d4fe4e..bb2c4ec939 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -1598,8 +1598,6 @@ mod test_process_proposal { public_key, Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1651,8 +1649,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1724,8 +1720,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1790,8 +1784,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1846,8 +1838,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); outer_tx.header.chain_id = shell.chain_id.clone(); @@ -1861,10 +1851,7 @@ mod test_process_proposal { .unwrap(); shell.enqueue_tx(outer_tx.clone(), gas_limit); - outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); txs.push(outer_tx); } #[cfg(feature = "abcipp")] @@ -1929,8 +1916,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); tx.header.chain_id = shell.chain_id.clone(); @@ -1985,8 +1970,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); tx.header.chain_id = shell.chain_id.clone(); @@ -2035,8 +2018,6 @@ mod test_process_proposal { pk: keypair.ref_to(), epoch: Epoch(0), gas_limit: GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - pow_solution: None, unshield_section_hash: None, }; @@ -2071,10 +2052,7 @@ mod test_process_proposal { #[test] fn test_too_many_decrypted_txs() { let (shell, _recv, _, _) = test_utils::setup_at_height(3u64); - let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + 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_data(Data::new("transaction data".as_bytes().to_owned())); @@ -2155,8 +2133,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2232,8 +2208,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2291,8 +2265,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2355,8 +2327,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2378,8 +2348,6 @@ mod test_process_proposal { keypair_2.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); new_wrapper.add_section(Section::Signature(Signature::new( @@ -2427,8 +2395,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); let wrong_chain_id = ChainId("Wrong chain id".to_string()); @@ -2491,8 +2457,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = wrong_chain_id.clone(); @@ -2501,9 +2465,7 @@ mod test_process_proposal { .set_data(Data::new("new transaction data".as_bytes().to_owned())); let mut decrypted = wrapper.clone(); - decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - has_valid_pow: false, - })); + decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); decrypted.add_section(Section::Signature(Signature::new( decrypted.sechashes(), &keypair, @@ -2514,7 +2476,6 @@ mod test_process_proposal { let wrapper_in_queue = TxInQueue { tx: wrapper, gas: gas_limit, - has_valid_pow: false, }; shell.wl_storage.storage.tx_queue.push(wrapper_in_queue); @@ -2557,8 +2518,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2601,8 +2560,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2612,9 +2569,7 @@ mod test_process_proposal { .set_data(Data::new("new transaction data".as_bytes().to_owned())); let mut decrypted = wrapper.clone(); - decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - has_valid_pow: false, - })); + decrypted.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); decrypted.add_section(Section::Signature(Signature::new( decrypted.sechashes(), &keypair, @@ -2625,7 +2580,6 @@ mod test_process_proposal { let wrapper_in_queue = TxInQueue { tx: wrapper, gas: gas_limit, - has_valid_pow: false, }; shell.wl_storage.storage.tx_queue.push(wrapper_in_queue); @@ -2665,8 +2619,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), (block_gas_limit + 1).into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2708,8 +2660,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), 0.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2750,8 +2700,6 @@ mod test_process_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2792,8 +2740,6 @@ mod test_process_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2834,8 +2780,6 @@ mod test_process_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), 150_000.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2876,8 +2820,6 @@ mod test_process_proposal { crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); @@ -2921,8 +2863,6 @@ mod test_process_proposal { keypair.ref_to(), Epoch(0), GAS_LIMIT_MULTIPLIER.into(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.header.chain_id = shell.chain_id.clone(); diff --git a/apps/src/lib/node/ledger/shell/testing/node.rs b/apps/src/lib/node/ledger/shell/testing/node.rs index cebb970f62..92ecd86c32 100644 --- a/apps/src/lib/node/ledger/shell/testing/node.rs +++ b/apps/src/lib/node/ledger/shell/testing/node.rs @@ -225,6 +225,7 @@ impl MockNode { }; let mut locked = self.shell.lock().unwrap(); let mut result = locked.process_proposal(req); + let mut errors: Vec<_> = result .tx_results .iter() @@ -395,7 +396,7 @@ impl<'a> Client for &'a MockNode { tx: namada::tendermint::abci::Transaction, ) -> Result { - let resp = tendermint_rpc::endpoint::broadcast::tx_sync::Response { + let mut resp = tendermint_rpc::endpoint::broadcast::tx_sync::Response { code: Default::default(), data: Default::default(), log: Default::default(), @@ -404,6 +405,7 @@ impl<'a> Client for &'a MockNode { let tx_bytes: Vec = tx.into(); self.submit_tx(tx_bytes); if !self.success() { + resp.code = tendermint::abci::Code::Err(1337); // TODO: submit_tx should return the correct error code + message return Ok(resp); } else { self.clear_results(); diff --git a/benches/lib.rs b/benches/lib.rs index 11042c84b3..fa459a0d04 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -406,10 +406,7 @@ pub fn generate_tx( signer: Option<&SecretKey>, ) -> Tx { let mut tx = Tx::from_type(namada::types::transaction::TxType::Decrypted( - namada::types::transaction::DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: true, - }, + namada::types::transaction::DecryptedTx::Decrypted, )); // NOTE: don't use the hash to avoid computing the cost of loading the wasm @@ -445,10 +442,7 @@ pub fn generate_tx( pub fn generate_ibc_tx(wasm_code_path: &str, msg: impl Msg) -> Tx { // This function avoid serializaing the tx data with Borsh let mut tx = Tx::from_type(namada::types::transaction::TxType::Decrypted( - namada::types::transaction::DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: true, - }, + namada::types::transaction::DecryptedTx::Decrypted, )); tx.set_code(Code::new(wasm_loader::read_wasm_or_exit( WASM_DIR, @@ -467,10 +461,7 @@ pub fn generate_foreign_key_tx(signer: &SecretKey) -> Tx { let wasm_code = std::fs::read("../wasm_for_tests/tx_write.wasm").unwrap(); let mut tx = Tx::from_type(namada::types::transaction::TxType::Decrypted( - namada::types::transaction::DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: true, - }, + namada::types::transaction::DecryptedTx::Decrypted, )); tx.set_code(Code::new(wasm_code)); tx.set_data(Data::new( diff --git a/benches/process_wrapper.rs b/benches/process_wrapper.rs index 72b26e0cb1..c050d83600 100644 --- a/benches/process_wrapper.rs +++ b/benches/process_wrapper.rs @@ -42,8 +42,6 @@ fn process_tx(c: &mut Criterion) { defaults::albert_keypair().ref_to(), 0.into(), 1000.into(), - #[cfg(not(feature = "mainnet"))] - None, None, ), ))); diff --git a/benches/vps.rs b/benches/vps.rs index 20e6055885..0163ab33fe 100644 --- a/benches/vps.rs +++ b/benches/vps.rs @@ -161,8 +161,6 @@ fn vp_user(c: &mut Criterion) { &keys_changed, &verifiers, shell.vp_wasm_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap() ); @@ -308,8 +306,6 @@ fn vp_implicit(c: &mut Criterion) { &keys_changed, &verifiers, shell.vp_wasm_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap() ) @@ -459,8 +455,6 @@ fn vp_validator(c: &mut Criterion) { &keys_changed, &verifiers, shell.vp_wasm_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap() ); @@ -550,8 +544,6 @@ fn vp_masp(c: &mut Criterion) { &keys_changed, &verifiers, shielded_ctx.shell.vp_wasm_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap() ); diff --git a/core/src/ledger/mod.rs b/core/src/ledger/mod.rs index 9a84fbc126..890d58044d 100644 --- a/core/src/ledger/mod.rs +++ b/core/src/ledger/mod.rs @@ -10,6 +10,5 @@ pub mod pgf; pub mod replay_protection; pub mod storage; pub mod storage_api; -pub mod testnet_pow; pub mod tx_env; pub mod vp_env; diff --git a/core/src/ledger/parameters/mod.rs b/core/src/ledger/parameters/mod.rs index 5be01fde56..31801cf7c5 100644 --- a/core/src/ledger/parameters/mod.rs +++ b/core/src/ledger/parameters/mod.rs @@ -61,9 +61,6 @@ pub struct Parameters { pub staked_ratio: Dec, /// PoS inflation amount from the last epoch (read + write for every epoch) pub pos_inflation_amount: token::Amount, - #[cfg(not(feature = "mainnet"))] - /// Faucet account for free token withdrawal - pub faucet_account: Option
, /// Fee unshielding gas limit pub fee_unshielding_gas_limit: u64, /// Fee unshielding descriptions limit @@ -133,8 +130,6 @@ impl Parameters { pos_gain_d, staked_ratio, pos_inflation_amount, - #[cfg(not(feature = "mainnet"))] - faucet_account, gas_cost, fee_unshielding_gas_limit, fee_unshielding_descriptions_limit, @@ -218,12 +213,6 @@ impl Parameters { let pos_inflation_key = storage::get_pos_inflation_amount_key(); storage.write(&pos_inflation_key, pos_inflation_amount)?; - #[cfg(not(feature = "mainnet"))] - if let Some(faucet_account) = faucet_account { - let faucet_account_key = storage::get_faucet_account_key(); - storage.write(&faucet_account_key, faucet_account)?; - } - let gas_cost_key = storage::get_gas_cost_key(); storage.write(&gas_cost_key, gas_cost)?; @@ -414,18 +403,6 @@ where .into_storage_result() } -#[cfg(not(feature = "mainnet"))] -/// Read the faucet account's address, if any -pub fn read_faucet_account_parameter( - storage: &S, -) -> storage_api::Result> -where - S: StorageRead, -{ - let faucet_account_key = storage::get_faucet_account_key(); - storage.read(&faucet_account_key) -} - /// Read the cost per unit of gas for the provided token pub fn read_gas_cost( storage: &S, @@ -558,10 +535,6 @@ where .ok_or(ReadError::ParametersMissing) .into_storage_result()?; - // read faucet account - #[cfg(not(feature = "mainnet"))] - let faucet_account = read_faucet_account_parameter(storage)?; - // read gas cost let gas_cost_key = storage::get_gas_cost_key(); let value = storage.read(&gas_cost_key)?; @@ -583,8 +556,6 @@ where pos_gain_d, staked_ratio, pos_inflation_amount, - #[cfg(not(feature = "mainnet"))] - faucet_account, gas_cost, fee_unshielding_gas_limit, fee_unshielding_descriptions_limit, diff --git a/core/src/ledger/parameters/storage.rs b/core/src/ledger/parameters/storage.rs index 3e87799016..c31a6e59da 100644 --- a/core/src/ledger/parameters/storage.rs +++ b/core/src/ledger/parameters/storage.rs @@ -43,7 +43,6 @@ struct Keys { vp_whitelist: &'static str, max_proposal_bytes: &'static str, max_block_gas: &'static str, - faucet_account: &'static str, gas_cost: &'static str, fee_unshielding_gas_limit: &'static str, fee_unshielding_descriptions_limit: &'static str, @@ -193,11 +192,6 @@ pub fn get_max_block_gas_key() -> Key { get_max_block_gas_key_at_addr(ADDRESS) } -/// Storage key used for faucet account. -pub fn get_faucet_account_key() -> Key { - get_faucet_account_key_at_addr(ADDRESS) -} - /// Storage key used for the gas cost table pub fn get_gas_cost_key() -> Key { get_gas_cost_key_at_addr(ADDRESS) diff --git a/core/src/ledger/storage/mod.rs b/core/src/ledger/storage/mod.rs index 507c3b4e02..c06f94feec 100644 --- a/core/src/ledger/storage/mod.rs +++ b/core/src/ledger/storage/mod.rs @@ -1283,8 +1283,6 @@ mod tests { pos_gain_d: Dec::new(1,1).expect("Cannot fail"), staked_ratio: Dec::new(1,1).expect("Cannot fail"), pos_inflation_amount: token::Amount::zero(), - #[cfg(not(feature = "mainnet"))] - faucet_account: None, fee_unshielding_gas_limit: 20_000, fee_unshielding_descriptions_limit: 15, gas_cost: BTreeMap::default(), diff --git a/core/src/ledger/testnet_pow.rs b/core/src/ledger/testnet_pow.rs deleted file mode 100644 index dcb7c9feb2..0000000000 --- a/core/src/ledger/testnet_pow.rs +++ /dev/null @@ -1,491 +0,0 @@ -//! PoW challenge is used for testnet zero-fee transaction to prevent spam. - -use std::fmt::Display; - -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_macros::StorageKeys; -use serde::{Deserialize, Serialize}; - -use super::storage_api::collections::{lazy_map, LazyCollection}; -use super::storage_api::{self, StorageRead, StorageWrite}; -use crate::ledger::storage_api::collections::LazyMap; -use crate::types::address::Address; -use crate::types::hash::Hash; -use crate::types::storage::{self, DbKeySeg, Key}; -use crate::types::uint::Uint; - -/// Initialize faucet's storage. This must be called at genesis if faucet -/// account is being used. -pub fn init_faucet_storage( - storage: &mut S, - address: &Address, - difficulty: Difficulty, - withdrawal_limit: Uint, -) -> storage_api::Result<()> -where - S: StorageWrite, -{ - write_difficulty(storage, address, difficulty)?; - write_withdrawal_limit(storage, address, withdrawal_limit) -} - -/// Counters are associated with transfer target addresses. -pub type Counter = u64; - -/// A PoW challenge that must be provably solved to withdraw from faucet. -#[derive( - Clone, - Debug, - BorshSerialize, - BorshDeserialize, - PartialEq, - Serialize, - Deserialize, -)] -pub struct Challenge { - /// The address derived from the `WrapperTx`'s signer `pk` field - pub source: Address, - /// Parameters - pub params: ChallengeParams, -} - -/// PoW challenge parameters. -#[derive( - Clone, - Debug, - BorshSerialize, - BorshDeserialize, - BorshSchema, - PartialEq, - Serialize, - Deserialize, -)] -pub struct ChallengeParams { - /// PoW difficulty - pub difficulty: Difficulty, - /// The counter value of the `transfer.target`. - pub counter: Counter, -} - -/// One must find a value for this type to solve a [`Challenge`] that is at -/// least of the matching difficulty of the challenge. -pub type SolutionValue = u64; -/// Size of `SolutionValue` when serialized with borsh -const SOLUTION_VAL_BYTES_LEN: usize = 8; - -/// A [`SolutionValue`] with the [`Challenge`]. -#[derive( - Clone, - Debug, - BorshSerialize, - BorshDeserialize, - BorshSchema, - Serialize, - Deserialize, -)] -pub struct Solution { - /// Challenge params - pub params: ChallengeParams, - /// Solution value, that produces hash with at least `difficulty` leading - /// zeros - pub value: SolutionValue, -} - -impl ChallengeParams { - /// Obtain a PoW challenge for a given transfer. - pub fn new( - storage: &mut S, - faucet_address: &Address, - source: &Address, - ) -> storage_api::Result - where - S: StorageRead + StorageWrite, - { - let difficulty = read_difficulty(storage, faucet_address)?; - let counter = get_counter(storage, faucet_address, source)?; - Ok(Self { - difficulty, - counter, - }) - } -} - -impl Challenge { - /// Obtain a PoW challenge for a given transfer. - pub fn new( - storage: &mut S, - faucet_address: &Address, - source: Address, - ) -> storage_api::Result - where - S: StorageRead + StorageWrite, - { - let params = ChallengeParams::new(storage, faucet_address, &source)?; - Ok(Self { source, params }) - } - - /// Try to find a solution to the [`Challenge`]. - pub fn solve(self) -> Solution { - use std::io::Write; - - println!( - "Looking for a solution with difficulty {}...", - self.params.difficulty - ); - let challenge_bytes = self.try_to_vec().expect("Serializable"); - let challenge_len = challenge_bytes.len(); - let mut stdout = std::io::stdout(); - - // Pre-allocate for the bytes - let mut bytes: Vec = - vec![0; challenge_bytes.len() + SOLUTION_VAL_BYTES_LEN]; - - // Set the first part from `challenge_bytes`... - for (old, new) in - bytes[0..challenge_len].iter_mut().zip(&challenge_bytes[..]) - { - *old = *new; - } - let mut maybe_solution: SolutionValue = 0; - 'outer: loop { - stdout.flush().unwrap(); - print!("\rChecking {}.", maybe_solution); - let solution_bytes = - maybe_solution.try_to_vec().expect("Serializable"); - // ...and the second part from `solution_bytes` - for (old, new) in - bytes[challenge_len..].iter_mut().zip(&solution_bytes[..]) - { - *old = *new; - } - let hash = Hash::sha256(&bytes); - - // Check if it's a solution - for i in 0..self.params.difficulty.0 as usize { - if hash.0[i] != b'0' { - maybe_solution += 1; - continue 'outer; - } - } - - println!(); - println!("Found a solution: {}.", maybe_solution); - stdout.flush().unwrap(); - return Solution { - params: self.params, - value: maybe_solution, - }; - } - } -} - -impl Solution { - /// Invalidate a solution if it's valid so that it cannot be used again by - /// updating the counter in storage. - pub fn invalidate_if_valid( - &self, - storage: &mut S, - faucet_address: &Address, - source: &Address, - ) -> storage_api::Result - where - S: StorageWrite + StorageRead, - { - if self.validate(storage, faucet_address, source.clone())? { - self.apply_from_tx(storage, faucet_address, source)?; - Ok(true) - } else { - Ok(false) - } - } - - /// Apply a solution from a tx so that it cannot be used again. - pub fn apply_from_tx( - &self, - storage: &mut S, - faucet_address: &Address, - source: &Address, - ) -> storage_api::Result<()> - where - S: StorageWrite + StorageRead, - { - increment_counter(storage, faucet_address, source, self.params.counter) - } - - /// Verify a solution and that the counter has been increment to prevent - /// solution replay. - /// The difficulty of the challenge must match the one set in faucet's - /// storage and the counter value. - pub fn validate( - &self, - storage: &S, - faucet_address: &Address, - source: Address, - ) -> storage_api::Result - where - S: StorageRead, - { - let counter = get_counter(storage, faucet_address, &source)?; - // Check that the counter matches expected counter - if self.params.counter != counter { - return Ok(false); - } - // Check that the difficulty matches expected difficulty - let current_difficulty = read_difficulty(storage, faucet_address)?; - if self.params.difficulty != current_difficulty { - return Ok(false); - } - - // Check the solution itself - if !self.verify_solution(source) { - return Ok(false); - } - - Ok(true) - } - - /// Verify that the given solution is correct. Note that this doesn't check - /// the difficulty or the counter. - pub fn verify_solution(&self, source: Address) -> bool { - let challenge = Challenge { - source, - params: self.params.clone(), - }; - let mut bytes = challenge.try_to_vec().expect("Serializable"); - let mut solution_bytes = self.value.try_to_vec().expect("Serializable"); - bytes.append(&mut solution_bytes); - let hash = Hash::sha256(&bytes); - - // Check if it's a solution - for i in 0..challenge.params.difficulty.0 as usize { - if hash.0[i] != b'0' { - return false; - } - } - - true - } -} - -/// Storage keys -#[derive(StorageKeys)] -pub struct Keys { - /// Withdrawal counters associated with recipient addresses. To withdraw - /// tokens from faucet, one must find a solution to a PoW challenge - /// containing the current value of their counter (or `0` is none). - counters: &'static str, - /// PoW difficulty - pow_difficulty: &'static str, - /// withdrawal limit - withdrawal_limit: &'static str, -} - -/// Storage key prefix to the `counters` field. The rest of the key is composed -/// from `LazyMap` stored at this key. -pub fn counter_prefix(address: &Address) -> storage::Key { - storage::Key { - segments: vec![ - DbKeySeg::AddressSeg(address.clone()), - DbKeySeg::StringSeg(Keys::VALUES.counters.to_string()), - ], - } -} - -/// Is the storage key for the `counters` field? If so, returns the owner. -pub fn is_counter_key<'a>( - key: &'a storage::Key, - faucet_address: &Address, -) -> Option<&'a Address> { - match &key.segments[..] { - [ - DbKeySeg::AddressSeg(address), - DbKeySeg::StringSeg(sub_key), - DbKeySeg::StringSeg(data), - DbKeySeg::AddressSeg(owner), - ] if address == faucet_address - && sub_key.as_str() == Keys::VALUES.counters - && data.as_str() == lazy_map::DATA_SUBKEY => - { - Some(owner) - } - _ => None, - } -} - -/// Storage key to the `difficulty` field. -pub fn difficulty_key(address: &Address) -> storage::Key { - storage::Key { - segments: vec![ - DbKeySeg::AddressSeg(address.clone()), - DbKeySeg::StringSeg(Keys::VALUES.pow_difficulty.to_string()), - ], - } -} - -/// Is the storage key for the `difficulty` field? -pub fn is_difficulty_key(key: &storage::Key, faucet_address: &Address) -> bool { - matches!( - &key.segments[..], - [ - DbKeySeg::AddressSeg(address), - DbKeySeg::StringSeg(sub_key), - ] if address == faucet_address && sub_key.as_str() == Keys::VALUES.pow_difficulty, - ) -} - -/// Storage key to the `withdrawal_limit` field. -pub fn withdrawal_limit_key(address: &Address) -> storage::Key { - storage::Key { - segments: vec![ - DbKeySeg::AddressSeg(address.clone()), - DbKeySeg::StringSeg(Keys::VALUES.withdrawal_limit.to_string()), - ], - } -} - -/// Is the storage key for the `withdrawal_limit` field? -pub fn is_withdrawal_limit_key( - key: &storage::Key, - faucet_address: &Address, -) -> bool { - matches!( - &key.segments[..], - [ - DbKeySeg::AddressSeg(address), - DbKeySeg::StringSeg(sub_key), - ] if address == faucet_address && sub_key.as_str() == Keys::VALUES.withdrawal_limit, - ) -} - -/// Read faucet's counter value for a given target address. -pub fn get_counter( - storage: &S, - faucet_address: &Address, - source: &Address, -) -> storage_api::Result -where - S: StorageRead, -{ - let counter: Counter = counters_handle(faucet_address) - .get(storage, source)? - // `0` if not previously set - .unwrap_or_default(); - Ok(counter) -} - -/// Increment faucet's counter value for a given source address. -pub fn increment_counter( - storage: &mut S, - faucet_address: &Address, - source: &Address, - current_counter: Counter, -) -> storage_api::Result<()> -where - S: StorageWrite + StorageRead, -{ - counters_handle(faucet_address).insert( - storage, - source.clone(), - current_counter + 1, - )?; - Ok(()) -} - -/// A handle to read/write withdrawal counters -pub fn counters_handle(address: &Address) -> LazyMap { - LazyMap::open(counter_prefix(address)) -} - -/// PoW difficulty (value between `0..=9`). -#[derive( - Copy, - Clone, - Debug, - Default, - BorshSerialize, - BorshDeserialize, - BorshSchema, - Eq, - PartialEq, - PartialOrd, - Ord, - Serialize, - Deserialize, -)] -#[serde(transparent)] -pub struct Difficulty(u8); -impl Difficulty { - /// The value must be between `0..=9` (inclusive upper bound). - pub fn try_new(raw: u8) -> Option { - if raw > 9 { None } else { Some(Self(raw)) } - } -} - -impl Display for Difficulty { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) - } -} - -/// Read PoW [`Difficulty`]. -pub fn read_difficulty( - storage: &S, - address: &Address, -) -> storage_api::Result -where - S: StorageRead, -{ - let difficulty = storage - .read(&difficulty_key(address))? - .expect("difficulty must always be set"); - Ok(difficulty) -} - -/// Write PoW [`Difficulty`]. -pub fn write_difficulty( - storage: &mut S, - address: &Address, - difficulty: Difficulty, -) -> storage_api::Result<()> -where - S: StorageWrite, -{ - storage.write(&difficulty_key(address), difficulty) -} - -/// Read the withdrawal limit. -pub fn read_withdrawal_limit( - storage: &S, - address: &Address, -) -> storage_api::Result -where - S: StorageRead, -{ - let withdrawal_limit = storage - .read(&withdrawal_limit_key(address))? - .expect("withdrawal_limit must always be set"); - Ok(withdrawal_limit) -} - -/// Write faucet withdrawal limit -pub fn write_withdrawal_limit( - storage: &mut S, - address: &Address, - withdrawal_limit: Uint, -) -> Result<(), storage_api::Error> -where - S: StorageWrite, -{ - storage.write(&withdrawal_limit_key(address), withdrawal_limit) -} - -#[cfg(test)] -mod test { - use super::*; - #[test] - fn test_solution_val_bytes_len() { - let val: SolutionValue = 10; - let bytes = val.try_to_vec().unwrap(); - assert_eq!(bytes.len(), SOLUTION_VAL_BYTES_LEN); - } -} diff --git a/core/src/proto/types.rs b/core/src/proto/types.rs index 43da551d87..29ca643473 100644 --- a/core/src/proto/types.rs +++ b/core/src/proto/types.rs @@ -25,7 +25,6 @@ use thiserror::Error; use super::generated::types; use crate::ledger::gas::{GasMetering, VpGasMeter, VERIFY_TX_SIG_GAS_COST}; use crate::ledger::storage::{KeccakHasher, Sha256Hasher, StorageHasher}; -use crate::ledger::testnet_pow; #[cfg(any(feature = "tendermint", feature = "tendermint-abcipp"))] use crate::tendermint_proto::abci::ResponseDeliverTx; use crate::types::account::AccountPublicKeysMap; @@ -1696,9 +1695,6 @@ impl Tx { fee_payer: common::PublicKey, epoch: Epoch, gas_limit: GasLimit, - #[cfg(not(feature = "mainnet"))] requires_pow: Option< - testnet_pow::Solution, - >, fee_unshield_hash: Option, ) -> &mut Self { self.header.tx_type = TxType::Wrapper(Box::new(WrapperTx::new( @@ -1706,8 +1702,6 @@ impl Tx { fee_payer, epoch, gas_limit, - #[cfg(not(feature = "mainnet"))] - requires_pow, fee_unshield_hash, ))); self diff --git a/core/src/types/internal.rs b/core/src/types/internal.rs index b5a2c43092..496287ed5e 100644 --- a/core/src/types/internal.rs +++ b/core/src/types/internal.rs @@ -61,12 +61,6 @@ mod tx_queue { /// This allows for a more detailed logging about the gas used by the /// wrapper and that used by the inner pub gas: Gas, - #[cfg(not(feature = "mainnet"))] - /// A PoW solution can be used to allow zero-fee testnet - /// transactions. - /// This is true when the wrapper of this tx contains a valid - /// `testnet_pow::Solution` - pub has_valid_pow: bool, } #[derive(Default, Debug, Clone, BorshDeserialize, BorshSerialize)] diff --git a/core/src/types/transaction/decrypted.rs b/core/src/types/transaction/decrypted.rs index 59b9965160..bbebc85e77 100644 --- a/core/src/types/transaction/decrypted.rs +++ b/core/src/types/transaction/decrypted.rs @@ -24,17 +24,7 @@ pub mod decrypted_tx { /// other validators to verify pub enum DecryptedTx { /// The decrypted payload - Decrypted { - #[cfg(not(feature = "mainnet"))] - /// A PoW solution can be used to allow zero-fee testnet - /// transactions. - /// This is true when the wrapper of this tx contains a valid - /// `testnet_pow::Solution`. - // For some reason, we get `warning: fields `tx` and - // `has_valid_pow` are never read` even though they are being used! - #[allow(dead_code)] - has_valid_pow: bool, - }, + Decrypted, /// The wrapper whose payload could not be decrypted Undecryptable, } diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 6b00e4dfcc..c83e62ddc4 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -263,8 +263,6 @@ mod test_process_tx { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); tx.set_code(Code::new("wasm code".as_bytes().to_owned())); @@ -300,8 +298,6 @@ mod test_process_tx { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); tx.set_code(Code::new("wasm code".as_bytes().to_owned())); @@ -316,10 +312,7 @@ mod test_process_tx { #[test] fn test_process_tx_decrypted_unsigned() { use crate::proto::{Code, Data, Tx}; - let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); let code_sec = tx .set_code(Code::new("transaction data".as_bytes().to_owned())) .clone(); @@ -328,10 +321,7 @@ fn test_process_tx_decrypted_unsigned() { .clone(); tx.validate_tx().expect("Test failed"); match tx.header().tx_type { - TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: _, - }) => { + TxType::Decrypted(DecryptedTx::Decrypted) => { assert_eq!(tx.header().code_hash, code_sec.get_hash(),); assert_eq!(tx.header().data_hash, data_sec.get_hash(),); } @@ -357,10 +347,7 @@ fn test_process_tx_decrypted_signed() { use crate::types::key::Signature as S; let mut decrypted = - Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - })); + Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); // Invalid signed data let ed_sig = ed25519::Signature::try_from_slice([0u8; 64].as_ref()).unwrap(); @@ -377,10 +364,7 @@ fn test_process_tx_decrypted_signed() { .clone(); decrypted.validate_tx().expect("Test failed"); match decrypted.header().tx_type { - TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: _, - }) => { + TxType::Decrypted(DecryptedTx::Decrypted) => { assert_eq!(decrypted.header.code_hash, code_sec.get_hash()); assert_eq!(decrypted.header.data_hash, data_sec.get_hash()); } diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index bda7142220..58deb6f093 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -15,7 +15,6 @@ pub mod wrapper_tx { use sha2::{Digest, Sha256}; use thiserror::Error; - use crate::ledger::testnet_pow; use crate::proto::{Code, Data, Section, Tx}; use crate::types::address::{masp, Address}; use crate::types::hash::Hash; @@ -191,9 +190,6 @@ pub mod wrapper_tx { /// The hash of the optional, unencrypted, unshielding transaction for /// fee payment pub unshield_section_hash: Option, - #[cfg(not(feature = "mainnet"))] - /// A PoW solution can be used to allow zero-fee testnet transactions - pub pow_solution: Option, } impl WrapperTx { @@ -207,9 +203,6 @@ pub mod wrapper_tx { pk: common::PublicKey, epoch: Epoch, gas_limit: GasLimit, - #[cfg(not(feature = "mainnet"))] pow_solution: Option< - testnet_pow::Solution, - >, unshield_hash: Option, ) -> WrapperTx { Self { @@ -218,8 +211,6 @@ pub mod wrapper_tx { epoch, gas_limit, unshield_section_hash: unshield_hash, - #[cfg(not(feature = "mainnet"))] - pow_solution, } } @@ -293,10 +284,7 @@ pub mod wrapper_tx { ) -> Result { let mut tx = Tx::from_type(crate::types::transaction::TxType::Decrypted( - crate::types::transaction::DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, - }, + crate::types::transaction::DecryptedTx::Decrypted, )); let masp_section = tx.add_section(Section::MaspTx(unshield)); let masp_hash = Hash( @@ -441,8 +429,6 @@ pub mod wrapper_tx { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.set_code(Code::new("wasm code".as_bytes().to_owned())); @@ -476,8 +462,6 @@ pub mod wrapper_tx { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); wrapper.set_code(Code::new("wasm code".as_bytes().to_owned())); @@ -514,8 +498,6 @@ pub mod wrapper_tx { keypair.ref_to(), Epoch(0), Default::default(), - #[cfg(not(feature = "mainnet"))] - None, None, )))); diff --git a/genesis/dev.toml b/genesis/dev.toml index f704f5883f..105bdbda19 100644 --- a/genesis/dev.toml +++ b/genesis/dev.toml @@ -1,8 +1,6 @@ # Developer network genesis_time = "2021-12-20T15:00:00.00Z" native_token = "NAM" -faucet_pow_difficulty = 0 -faucet_withdrawal_limit = "1000" # Some tokens present at genesis. @@ -19,8 +17,6 @@ Christel = "1000000" "Christel.public_key" = "100" Daewon = "1000000" Ester = "1000000" -faucet = "922337203685400000000" -"faucet.public_key" = "100" [token.NAM.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -37,7 +33,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.BTC.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -54,7 +49,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.ETH.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -71,7 +65,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.DOT.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -88,7 +81,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Schnitzel.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -105,7 +97,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Apfel.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" @@ -123,17 +114,12 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Kartoffel.parameters] max_reward_rate = "0.1" kd_gain_nom = "0.1" kp_gain_nom = "0.1" locked_ratio_target_key = "0.6667" -# Some established accounts present at genesis. -[established.faucet] -vp = "vp_testnet_faucet" - [established.Albert] vp = "vp_user" @@ -168,10 +154,6 @@ filename = "vp_user.wasm" # filename (relative to wasm path used by the node) filename = "vp_validator.wasm" -# Faucet VP -[wasm.vp_testnet_faucet] -filename = "vp_testnet_faucet.wasm" - # MASP VP [wasm.vp_masp] filename = "vp_masp.wasm" diff --git a/genesis/e2e-tests-single-node.toml b/genesis/e2e-tests-single-node.toml index 0af2a23b86..5419429563 100644 --- a/genesis/e2e-tests-single-node.toml +++ b/genesis/e2e-tests-single-node.toml @@ -4,8 +4,6 @@ genesis_time = "2021-09-30T10:00:00Z" native_token = "NAM" -faucet_pow_difficulty = 0 -faucet_withdrawal_limit = "1000" [validator.validator-0] # Validator's staked NAM at genesis. @@ -37,8 +35,6 @@ Christel = "1000000" "Christel.public_key" = "100" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" -"faucet.public_key" = "100" "validator-0.public_key" = "100" [token.BTC] @@ -50,7 +46,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.ETH] address = "atest1v4ehgw36xqmr2d3nx3ryvd2xxgmrq33j8qcns33sxezrgv6zxdzrydjrxveygd2yxumrsdpsf9jc2p" @@ -61,7 +56,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.DOT] address = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn" @@ -72,7 +66,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Schnitzel] address = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt" @@ -83,7 +76,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Apfel] address = "atest1v4ehgw36gfryydj9g3p5zv3kg9znyd358ycnzsfcggc5gvecgc6ygs2rxv6ry3zpg4zrwdfeumqcz9" @@ -94,7 +86,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" [token.Kartoffel] address = "atest1v4ehgw36gep5ysecxq6nyv3jg3zygv3e89qn2vp48pryxsf4xpznvve5gvmy23fs89pryvf5a6ht90" @@ -106,11 +97,6 @@ Bertha = "1000000" Christel = "1000000" Daewon = "1000000" Ester = "1000000" -faucet = "9223372036854" - -# Some established accounts present at genesis. -[established.faucet] -vp = "vp_testnet_faucet" [established.Albert] vp = "vp_user" @@ -144,10 +130,6 @@ filename = "vp_user.wasm" # filename (relative to wasm path used by the node) filename = "vp_validator.wasm" -# Faucet VP -[wasm.vp_testnet_faucet] -filename = "vp_testnet_faucet.wasm" - # MASP VP [wasm.vp_masp] filename = "vp_masp.wasm" diff --git a/shared/src/ledger/eth_bridge/bridge_pool.rs b/shared/src/ledger/eth_bridge/bridge_pool.rs index 2b2220a5f9..4e4369266d 100644 --- a/shared/src/ledger/eth_bridge/bridge_pool.rs +++ b/shared/src/ledger/eth_bridge/bridge_pool.rs @@ -121,8 +121,6 @@ pub async fn build_bridge_pool_tx< &mut tx, wrapper_fee_payer, None, - #[cfg(not(feature = "mainnet"))] - false, ) .await?; diff --git a/shared/src/ledger/native_vp/mod.rs b/shared/src/ledger/native_vp/mod.rs index f6dbb82dba..7fb2337304 100644 --- a/shared/src/ledger/native_vp/mod.rs +++ b/shared/src/ledger/native_vp/mod.rs @@ -496,8 +496,6 @@ where self.keys_changed, &eval_runner, &mut vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - false, ); match eval_runner.eval_native_result(ctx, vp_code_hash, input_data) { diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index c6ed0814b1..863ac32834 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -147,7 +147,6 @@ pub fn dispatch_tx<'a, D, H, CA>( vp_wasm_cache: &'a mut VpCache, tx_wasm_cache: &'a mut TxCache, block_proposer: Option<&'a Address>, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, @@ -156,10 +155,7 @@ where { match tx.header().tx_type { TxType::Raw => Err(Error::TxTypeError), - TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow, - }) => apply_wasm_tx( + TxType::Decrypted(DecryptedTx::Decrypted) => apply_wasm_tx( tx, &tx_index, ShellParams { @@ -168,8 +164,6 @@ where vp_wasm_cache, tx_wasm_cache, }, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ), TxType::Protocol(protocol_tx) => { apply_protocol_tx(protocol_tx.tx, tx.data(), wl_storage) @@ -197,8 +191,6 @@ where tx_wasm_cache, }, block_proposer, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, )?; Ok(TxResult { gas_used: tx_gas_meter.get_tx_consumed_gas(), @@ -242,7 +234,6 @@ pub(crate) fn apply_wrapper_tx<'a, D, H, CA, WLS>( tx_bytes: &[u8], mut shell_params: ShellParams<'a, CA, WLS>, block_proposer: Option<&Address>, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Result> where CA: 'static + WasmCacheAccess + Sync, @@ -269,8 +260,6 @@ where wrapper, fee_unshield_transaction, &mut shell_params, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, block_proposer, &mut changed_keys, )?; @@ -301,7 +290,6 @@ pub fn charge_fee<'a, D, H, CA, WLS>( wrapper: &WrapperTx, masp_transaction: Option, shell_params: &mut ShellParams<'a, CA, WLS>, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, block_proposer: Option<&Address>, changed_keys: &mut BTreeSet, ) -> Result<()> @@ -354,8 +342,6 @@ where vp_wasm_cache, tx_wasm_cache, }, - #[cfg(not(feature = "mainnet"))] - false, ) { Ok(result) => { // NOTE: do not commit yet cause this could be @@ -385,19 +371,8 @@ where // Charge or check fees match block_proposer { - Some(proposer) => transfer_fee( - *wl_storage, - proposer, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, - wrapper, - )?, - None => check_fees( - *wl_storage, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, - wrapper, - )?, + Some(proposer) => transfer_fee(*wl_storage, proposer, wrapper)?, + None => check_fees(*wl_storage, wrapper)?, } changed_keys.extend(wl_storage.write_log_mut().get_keys_with_precommit()); @@ -413,7 +388,6 @@ where pub fn transfer_fee( wl_storage: &mut WLS, block_proposer: &Address, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, wrapper: &WrapperTx, ) -> Result<()> where @@ -439,45 +413,31 @@ where .map_err(|e| Error::FeeError(e.to_string())) } else { // Balance was insufficient for fee payment - #[cfg(not(feature = "mainnet"))] - let reject = !has_valid_pow; - #[cfg(feature = "mainnet")] - let reject = true; - - if reject { - #[cfg(not(any(feature = "abciplus", feature = "abcipp")))] - { - // Move all the available funds in the transparent - // balance of the fee payer - token_transfer( - wl_storage, - &wrapper.fee.token, - &wrapper.fee_payer(), - block_proposer, - balance, - ) - .map_err(|e| Error::FeeError(e.to_string()))?; + #[cfg(not(any(feature = "abciplus", feature = "abcipp")))] + { + // Move all the available funds in the transparent + // balance of the fee payer + token_transfer( + wl_storage, + &wrapper.fee.token, + &wrapper.fee_payer(), + block_proposer, + balance, + ) + .map_err(|e| Error::FeeError(e.to_string()))?; - return Err(Error::FeeError( - "Transparent balance of wrapper's signer was \ - insufficient to pay fee. All the available \ - transparent funds have been moved to the block \ - proposer" - .to_string(), - )); - } - #[cfg(any(feature = "abciplus", feature = "abcipp"))] return Err(Error::FeeError( - "Insufficient transparent balance to pay fees" + "Transparent balance of wrapper's signer was \ + insufficient to pay fee. All the available \ + transparent funds have been moved to the block \ + proposer" .to_string(), )); - } else { - tracing::debug!( - "Balance was insufficient for fee payment but a valid \ - PoW was provided" - ); - Ok(()) } + #[cfg(any(feature = "abciplus", feature = "abcipp"))] + return Err(Error::FeeError( + "Insufficient transparent balance to pay fees".to_string(), + )); } } Err(e) => { @@ -564,11 +524,7 @@ where } /// Check if the fee payer has enough transparent balance to pay fees -pub fn check_fees( - wl_storage: &WLS, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, - wrapper: &WrapperTx, -) -> Result<()> +pub fn check_fees(wl_storage: &WLS, wrapper: &WrapperTx) -> Result<()> where WLS: WriteLogAndStorage + StorageRead, { @@ -586,23 +542,9 @@ where if balance.checked_sub(fees).is_some() { Ok(()) } else { - // Balance was insufficient for fee payment - #[cfg(not(feature = "mainnet"))] - let reject = !has_valid_pow; - #[cfg(feature = "mainnet")] - let reject = true; - - if reject { - Err(Error::FeeError( - "Insufficient transparent balance to pay fees".to_string(), - )) - } else { - tracing::debug!( - "Balance was insufficient for fee payment but a valid PoW was \ - provided" - ); - Ok(()) - } + Err(Error::FeeError( + "Insufficient transparent balance to pay fees".to_string(), + )) } } @@ -612,7 +554,6 @@ pub fn apply_wasm_tx<'a, D, H, CA, WLS>( tx: Tx, tx_index: &TxIndex, shell_params: ShellParams<'a, CA, WLS>, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Result where CA: 'static + WasmCacheAccess + Sync, @@ -656,8 +597,6 @@ where write_log, verifiers_from_tx: &verifiers, vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, })?; let gas_used = tx_gas_meter.get_tx_consumed_gas(); @@ -798,8 +737,6 @@ where write_log: &'a WriteLog, verifiers_from_tx: &'a BTreeSet
, vp_wasm_cache: &'a mut VpCache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow: bool, } /// Check the acceptance of a transaction by validity predicates @@ -812,8 +749,6 @@ fn check_vps( write_log, verifiers_from_tx, vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, }: CheckVps<'_, D, H, CA>, ) -> Result where @@ -833,7 +768,6 @@ where write_log, tx_gas_meter, vp_wasm_cache, - has_valid_pow, )?; tracing::debug!("Total VPs gas cost {:?}", vps_result.gas_used); @@ -853,10 +787,6 @@ fn execute_vps( write_log: &WriteLog, tx_gas_meter: &TxGasMeter, vp_wasm_cache: &mut VpCache, - #[cfg(not(feature = "mainnet"))] - // This is true when the wrapper of this tx contained a valid - // `testnet_pow::Solution` - has_valid_pow: bool, ) -> Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, @@ -892,8 +822,6 @@ where &keys_changed, &verifiers, vp_wasm_cache.clone(), - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ) .map_err(Error::VpRunnerError) } diff --git a/shared/src/ledger/queries/shell.rs b/shared/src/ledger/queries/shell.rs index 2db40f0a07..a766846916 100644 --- a/shared/src/ledger/queries/shell.rs +++ b/shared/src/ledger/queries/shell.rs @@ -132,8 +132,6 @@ where &mut ctx.tx_wasm_cache, ), None, - #[cfg(not(feature = "mainnet"))] - false, ) .into_storage_result()?; @@ -144,12 +142,7 @@ where // hardcoded, dummy one let _privkey = ::G2Affine::prime_subgroup_generator(); - tx.update_header(TxType::Decrypted( - DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] - // To be able to dry-run testnet faucet withdrawal, pretend - // that we got a valid PoW - has_valid_pow: true }, - )); + tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); TxGasMeter::new_from_sub_limit(tx_gas_meter.get_available_gas()) } TxType::Protocol(_) | TxType::Decrypted(_) => { @@ -163,10 +156,7 @@ where } TxType::Raw => { // Cast tx to a decrypted for execution - tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - has_valid_pow: true, - })); + tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted)); // If dry run only the inner tx, use the max block gas as the gas // limit @@ -187,8 +177,6 @@ where &mut ctx.vp_wasm_cache, &mut ctx.tx_wasm_cache, ), - #[cfg(not(feature = "mainnet"))] - true, ) .into_storage_result()?; cumulated_gas = cumulated_gas @@ -631,12 +619,7 @@ mod test { // Request dry run tx let mut outer_tx = - Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { - #[cfg(not(feature = "mainnet"))] - // To be able to dry-run testnet faucet withdrawal, pretend - // that we got a valid PoW - has_valid_pow: true, - })); + 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_data(Data::new(vec![])); diff --git a/shared/src/ledger/queries/vp/mod.rs b/shared/src/ledger/queries/vp/mod.rs index c53386b2f8..48e39b5c8b 100644 --- a/shared/src/ledger/queries/vp/mod.rs +++ b/shared/src/ledger/queries/vp/mod.rs @@ -22,135 +22,3 @@ router! {VP, ( "governance" ) = (sub GOV), ( "pgf" ) = (sub PGF), } - -/// Client-only methods for the router type are composed from router functions. -#[cfg(any(test, feature = "async-client"))] -pub mod client_only_methods { - #[cfg(not(feature = "mainnet"))] - use borsh::BorshDeserialize; - #[cfg(not(feature = "mainnet"))] - use namada_core::ledger::testnet_pow; - - use super::Vp; - #[cfg(not(feature = "mainnet"))] - use crate::ledger::queries::{Client, RPC}; - #[cfg(not(feature = "mainnet"))] - use crate::types::address::Address; - - impl Vp { - #[cfg(not(feature = "mainnet"))] - /// Get faucet account address, if any is setup for the network. - pub async fn get_faucet_address( - &self, - client: &CLIENT, - ) -> Result, ::Error> - where - CLIENT: Client + Sync, - { - let faucet_account_key = namada_core::ledger::parameters::storage::get_faucet_account_key(); - if RPC - .shell() - .storage_has_key(client, &faucet_account_key) - .await? - { - let faucet_account = Address::try_from_slice( - &RPC.shell() - .storage_value( - client, - None, - None, - false, - &faucet_account_key, - ) - .await? - .data, - ) - .expect("Faucet address couldn't be read"); - Ok(Some(faucet_account)) - } else { - Ok(None) - } - } - - #[cfg(not(feature = "mainnet"))] - /// Check if the given address is a faucet account address. - pub async fn is_faucet( - &self, - client: &CLIENT, - address: &Address, - ) -> Result::Error> - where - CLIENT: Client + Sync, - { - if let Some(faucet_address) = - self.get_faucet_address(client).await? - { - Ok(address == &faucet_address) - } else { - Ok(false) - } - } - - #[cfg(not(feature = "mainnet"))] - /// Get a faucet PoW challenge for token withdrawal. - pub async fn testnet_pow_challenge( - &self, - client: &CLIENT, - source: Address, - ) -> Result::Error> - where - CLIENT: Client + Sync, - { - let params = self.testnet_pow_params(client, &source).await?; - Ok(testnet_pow::Challenge { source, params }) - } - - #[cfg(not(feature = "mainnet"))] - /// Read faucet PoW challenge parameters for token withdrawal. - pub async fn testnet_pow_params( - &self, - client: &CLIENT, - source: &Address, - ) -> Result::Error> - where - CLIENT: Client + Sync, - { - let faucet_address = self - .get_faucet_address(client) - .await? - .expect("No faucet account found"); - let difficulty_key = &testnet_pow::difficulty_key(&faucet_address); - let counter_key = &testnet_pow::counters_handle(&faucet_address) - .get_data_key(source); - let difficulty = testnet_pow::Difficulty::try_from_slice( - &RPC.shell() - .storage_value(client, None, None, false, difficulty_key) - .await? - .data, - ) - .expect("Faucet PoW difficulty couldn't be read"); - let counter = if RPC - .shell() - .storage_has_key(client, counter_key) - .await? - { - testnet_pow::Counter::try_from_slice( - &RPC.shell() - .storage_value(client, None, None, false, counter_key) - .await? - .data, - ) - .expect("Faucet counter has unexpected encoding") - } else { - // `0` if not previously set (same as - // `testnet_pow::get_counter`) - testnet_pow::Counter::default() - }; - - Ok(testnet_pow::ChallengeParams { - difficulty, - counter, - }) - } - } -} diff --git a/shared/src/ledger/rpc.rs b/shared/src/ledger/rpc.rs index ddef3ecb20..e73c5ebb6d 100644 --- a/shared/src/ledger/rpc.rs +++ b/shared/src/ledger/rpc.rs @@ -12,8 +12,6 @@ use namada_core::ledger::governance::parameters::GovernanceParameters; use namada_core::ledger::governance::storage::proposal::StorageProposal; use namada_core::ledger::governance::utils::Vote; use namada_core::ledger::storage::LastBlock; -#[cfg(not(feature = "mainnet"))] -use namada_core::ledger::testnet_pow; use namada_core::types::account::Account; use namada_core::types::address::Address; use namada_core::types::storage::Key; @@ -213,39 +211,6 @@ pub async fn known_address( } } -#[cfg(not(feature = "mainnet"))] -/// Check if the given address is a testnet faucet account address. -pub async fn is_faucet_account( - client: &C, - address: &Address, -) -> bool { - unwrap_client_response::(RPC.vp().is_faucet(client, address).await) -} - -#[cfg(not(feature = "mainnet"))] -/// Get faucet account address, if any is setup for the network. -pub async fn get_faucet_address( - client: &C, -) -> Option
{ - unwrap_client_response::>( - RPC.vp().get_faucet_address(client).await, - ) -} - -#[cfg(not(feature = "mainnet"))] -/// Obtain a PoW challenge for a withdrawal from a testnet faucet account, if -/// any is setup for the network. -pub async fn get_testnet_pow_challenge< - C: crate::ledger::queries::Client + Sync, ->( - client: &C, - source: Address, -) -> testnet_pow::Challenge { - unwrap_client_response::( - RPC.vp().testnet_pow_challenge(client, source).await, - ) -} - // Consider how we want to handle this unwrap. It gets used in contexts that // often ignore the optional value and do not have any error type surrounding // it. diff --git a/shared/src/ledger/signing.rs b/shared/src/ledger/signing.rs index 1753c645d3..059b297cf5 100644 --- a/shared/src/ledger/signing.rs +++ b/shared/src/ledger/signing.rs @@ -51,7 +51,7 @@ use crate::types::transaction::governance::{ InitProposalData, VoteProposalData, }; use crate::types::transaction::pos::InitValidator; -use crate::types::transaction::{Fee, TxType}; +use crate::types::transaction::Fee; #[cfg(feature = "std")] /// Env. var specifying where to store signing test vectors @@ -291,132 +291,6 @@ pub async fn aux_signing_data< }) } -#[cfg(not(feature = "mainnet"))] -/// Solve the PoW challenge if balance is insufficient to pay transaction fees -/// or if solution is explicitly requested. -pub async fn solve_pow_challenge( - client: &C, - args: &args::Tx, - requires_pow: bool, - total_fee: Amount, - balance: Amount, - source: Address, -) -> Option { - let is_bal_sufficient = total_fee <= balance; - if !is_bal_sufficient { - let token_addr = args.fee_token.clone(); - let err_msg = format!( - "The wrapper transaction source doesn't have enough balance to \ - pay fee {}, got {}.", - format_denominated_amount(client, &token_addr, total_fee).await, - format_denominated_amount(client, &token_addr, balance).await, - ); - if !args.force && cfg!(feature = "mainnet") { - panic!("{}", err_msg); - } - } - // A PoW solution can be used to allow zero-fee testnet transactions - // If the address derived from the keypair doesn't have enough balance - // to pay for the fee, allow to find a PoW solution instead. - if (requires_pow || !is_bal_sufficient) && !args.dump_tx { - println!("The transaction requires the completion of a PoW challenge."); - // Obtain a PoW challenge for faucet withdrawal - let challenge = rpc::get_testnet_pow_challenge(client, source).await; - - // Solve the solution, this blocks until a solution is found - let solution = challenge.solve(); - Some(solution) - } else { - None - } -} - -#[cfg(not(feature = "mainnet"))] -/// Update the PoW challenge inside the given transaction -pub async fn update_pow_challenge( - client: &C, - args: &args::Tx, - tx: &mut Tx, - requires_pow: bool, - source: Address, -) { - let gas_cost_key = parameter_storage::get_gas_cost_key(); - let minimum_fee = match rpc::query_storage_value::< - C, - BTreeMap, - >(client, &gas_cost_key) - .await - .and_then(|map| { - map.get(&args.fee_token) - .map(ToOwned::to_owned) - .ok_or_else(|| Error::Other("no fee found".to_string())) - }) { - Ok(amount) => amount, - Err(_e) => { - eprintln!( - "Could not retrieve the gas cost for token {}", - args.fee_token - ); - if !args.force { - panic!(); - } else { - token::Amount::default() - } - } - }; - let fee_amount = match args.fee_amount { - Some(amount) => { - let validated_fee_amount = - validate_amount(client, amount, &args.fee_token, args.force) - .await - .expect("Expected to be able to validate fee"); - - let amount = - Amount::from_uint(validated_fee_amount.amount, 0).unwrap(); - - if amount >= minimum_fee { - amount - } else if !args.force { - // Update the fee amount if it's not enough - println!( - "The provided gas price {} is less than the minimum \ - amount required {}, changing it to match the minimum", - amount.to_string_native(), - minimum_fee.to_string_native() - ); - minimum_fee - } else { - amount - } - } - None => minimum_fee, - }; - let total_fee = fee_amount * u64::from(args.gas_limit); - - let balance_key = token::balance_key(&args.fee_token, &source); - let balance = - rpc::query_storage_value::(client, &balance_key) - .await - .unwrap_or_default(); - - if let TxType::Wrapper(wrapper) = &mut tx.header.tx_type { - let pow_solution = solve_pow_challenge( - client, - args, - requires_pow, - total_fee, - balance, - source, - ) - .await; - wrapper.fee = Fee { - amount_per_gas_unit: fee_amount, - token: args.fee_token.clone(), - }; - wrapper.pow_solution = pow_solution; - } -} - /// Informations about the post-tx balance of the tx's source. Used to correctly /// handle fee validation in the wrapper tx pub struct TxSourcePostBalance { @@ -443,7 +317,6 @@ pub async fn wrap_tx< tx_source_balance: Option, epoch: Epoch, fee_payer: common::PublicKey, - #[cfg(not(feature = "mainnet"))] requires_pow: bool, ) -> Option { let fee_payer_address = Address::from(&fee_payer); // Validate fee amount and token @@ -585,7 +458,6 @@ pub async fn wrap_tx< if u64::try_from(descriptions).unwrap() > descriptions_limit && !args.force - && cfg!(feature = "mainnet") { panic!( "Fee unshielding descriptions exceed the limit" @@ -597,7 +469,7 @@ pub async fn wrap_tx< } Ok(None) => { eprintln!("Missing unshielding transaction"); - if !args.force && cfg!(feature = "mainnet") { + if !args.force { panic!(); } @@ -605,7 +477,7 @@ pub async fn wrap_tx< } Err(e) => { eprintln!("Error in fee unshielding generation: {}", e); - if !args.force && cfg!(feature = "mainnet") { + if !args.force { panic!(); } @@ -627,7 +499,7 @@ pub async fn wrap_tx< .await, ); eprintln!("{}", err_msg); - if !args.force && cfg!(feature = "mainnet") { + if !args.force { panic!("{}", err_msg); } @@ -653,17 +525,6 @@ pub async fn wrap_tx< namada_core::types::hash::Hash(hasher.finalize().into()) }); - #[cfg(not(feature = "mainnet"))] - let pow_solution = solve_pow_challenge( - client, - args, - requires_pow, - total_fee, - updated_balance, - fee_payer_address, - ) - .await; - tx.add_wrapper( Fee { amount_per_gas_unit: fee_amount, @@ -673,8 +534,6 @@ pub async fn wrap_tx< epoch, // TODO: partially validate the gas limit in client args.gas_limit, - #[cfg(not(feature = "mainnet"))] - pow_solution, unshield_section_hash, ); diff --git a/shared/src/ledger/tx.rs b/shared/src/ledger/tx.rs index 5ebc7f52bb..7b08045cda 100644 --- a/shared/src/ledger/tx.rs +++ b/shared/src/ledger/tx.rs @@ -158,7 +158,6 @@ pub async fn prepare_tx< tx: &mut Tx, fee_payer: common::PublicKey, tx_source_balance: Option, - #[cfg(not(feature = "mainnet"))] requires_pow: bool, ) -> Result> { if !args.dry_run { let epoch = rpc::query_epoch(client).await?; @@ -171,8 +170,6 @@ pub async fn prepare_tx< tx_source_balance, epoch, fee_payer, - #[cfg(not(feature = "mainnet"))] - requires_pow, ) .await) } else { @@ -296,7 +293,7 @@ pub async fn build_reveal_pk< } /// Broadcast a transaction to be included in the blockchain and checks that -/// the tx has been successfully included into the mempool of a validator +/// the tx has been successfully included into the mempool of a node /// /// In the case of errors in any of those stages, an error message is returned pub async fn broadcast_tx( @@ -1406,8 +1403,6 @@ pub async fn build_ibc_transfer< &mut tx, fee_payer, tx_source_balance, - #[cfg(not(feature = "mainnet"))] - false, ) .await?; @@ -1443,8 +1438,6 @@ where on_tx, gas_payer, tx_source_balance, - #[cfg(not(feature = "mainnet"))] - false, ) .await } @@ -1460,7 +1453,6 @@ async fn build_pow_flag( on_tx: F, gas_payer: &common::PublicKey, tx_source_balance: Option, - #[cfg(not(feature = "mainnet"))] requires_pow: bool, ) -> Result<(Tx, Option)> where F: FnOnce(&mut Tx, &mut D) -> Result<()>, @@ -1488,8 +1480,6 @@ where &mut tx_builder, gas_payer.clone(), tx_source_balance, - #[cfg(not(feature = "mainnet"))] - requires_pow, ) .await?; Ok((tx_builder, epoch)) @@ -1629,11 +1619,6 @@ pub async fn build_transfer< _ => None, }; - #[cfg(not(feature = "mainnet"))] - let is_source_faucet = rpc::is_faucet_account(client, &source).await; - #[cfg(feature = "mainnet")] - let is_source_faucet = false; - // Construct the shielded part of the transaction, if any let stx_result = shielded.gen_shielded_transfer(client, args.clone()).await; @@ -1713,8 +1698,6 @@ pub async fn build_transfer< add_shielded, &fee_payer, tx_source_balance, - #[cfg(not(feature = "mainnet"))] - is_source_faucet, ) .await?; // Manage the two masp epochs @@ -1908,8 +1891,6 @@ pub async fn build_custom< &mut tx, fee_payer.clone(), None, - #[cfg(not(feature = "mainnet"))] - false, ) .await?; diff --git a/shared/src/vm/host_env.rs b/shared/src/vm/host_env.rs index 179472a890..e8609bfbde 100644 --- a/shared/src/vm/host_env.rs +++ b/shared/src/vm/host_env.rs @@ -268,10 +268,6 @@ where /// To avoid unused parameter without "wasm-runtime" feature #[cfg(not(feature = "wasm-runtime"))] pub cache_access: std::marker::PhantomData, - #[cfg(not(feature = "mainnet"))] - /// This is true when the wrapper of this tx contained a valid - /// `testnet_pow::Solution` - has_valid_pow: bool, } /// A Validity predicate runner for calls from the [`vp_eval`] function. @@ -328,7 +324,6 @@ where keys_changed: &BTreeSet, eval_runner: &EVAL, #[cfg(feature = "wasm-runtime")] vp_wasm_cache: &mut VpCache, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Self { let ctx = VpCtx::new( address, @@ -344,8 +339,6 @@ where eval_runner, #[cfg(feature = "wasm-runtime")] vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ); Self { memory, ctx } @@ -396,7 +389,6 @@ where keys_changed: &BTreeSet, eval_runner: &EVAL, #[cfg(feature = "wasm-runtime")] vp_wasm_cache: &mut VpCache, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Self { let address = unsafe { HostRef::new(address) }; let storage = unsafe { HostRef::new(storage) }; @@ -427,8 +419,6 @@ where vp_wasm_cache, #[cfg(not(feature = "wasm-runtime"))] cache_access: std::marker::PhantomData, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, } } } @@ -457,8 +447,6 @@ where vp_wasm_cache: self.vp_wasm_cache.clone(), #[cfg(not(feature = "wasm-runtime"))] cache_access: std::marker::PhantomData, - #[cfg(not(feature = "mainnet"))] - has_valid_pow: self.has_valid_pow, } } } @@ -2005,33 +1993,6 @@ where vp_host_fns::add_gas(gas_meter, gas) } -/// Find if the wrapper tx had a valid `testnet_pow::Solution` -pub fn vp_has_valid_pow( - env: &VpVmEnv, -) -> vp_host_fns::EnvResult -where - MEM: VmMemory, - DB: storage::DB + for<'iter> storage::DBIter<'iter>, - H: StorageHasher, - EVAL: VpEvaluator, - CA: WasmCacheAccess, -{ - #[cfg(feature = "mainnet")] - let _ = env; - - #[cfg(not(feature = "mainnet"))] - let has_valid_pow = env.ctx.has_valid_pow; - #[cfg(feature = "mainnet")] - let has_valid_pow = false; - - Ok(if has_valid_pow { - HostEnvResult::Success - } else { - HostEnvResult::Fail - } - .to_i64()) -} - /// Log a string from exposed to the wasm VM VP environment. The message will be /// printed at the [`tracing::Level::INFO`]. This function is for development /// only. @@ -2116,7 +2077,6 @@ pub mod testing { keys_changed: &BTreeSet, eval_runner: &EVAL, #[cfg(feature = "wasm-runtime")] vp_wasm_cache: &mut VpCache, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> VpVmEnv<'static, NativeMemory, DB, H, EVAL, CA> where DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, @@ -2139,8 +2099,6 @@ pub mod testing { eval_runner, #[cfg(feature = "wasm-runtime")] vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ) } } diff --git a/shared/src/vm/wasm/host_env.rs b/shared/src/vm/wasm/host_env.rs index f31832b9bd..30e58f38d7 100644 --- a/shared/src/vm/wasm/host_env.rs +++ b/shared/src/vm/wasm/host_env.rs @@ -130,7 +130,6 @@ where "namada_vp_verify_masp" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_verify_masp), "namada_vp_eval" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_eval), "namada_vp_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_native_token), - "namada_vp_has_valid_pow" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_has_valid_pow), "namada_vp_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_log_string), }, } diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index 667b6884ee..ebe57c693d 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -205,7 +205,6 @@ pub fn vp( keys_changed: &BTreeSet, verifiers: &BTreeSet
, mut vp_wasm_cache: VpCache, - #[cfg(not(feature = "mainnet"))] has_valid_pow: bool, ) -> Result where DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, @@ -243,8 +242,6 @@ where keys_changed, &eval_runner, &mut vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, ); let initial_memory = @@ -762,8 +759,6 @@ mod tests { &keys_changed, &verifiers, vp_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap(); assert!(passed); @@ -796,8 +791,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap(); @@ -850,8 +843,6 @@ mod tests { &keys_changed, &verifiers, vp_cache.clone(), - #[cfg(not(feature = "mainnet"))] - false, ); assert!(result.is_ok(), "Expected success, got {:?}", result); @@ -872,8 +863,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ) .expect_err("Expected to run out of memory"); @@ -986,8 +975,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ); // Depending on platform, we get a different error from the running out // of memory @@ -1114,8 +1101,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ) .expect_err("Expected to run out of memory"); @@ -1193,8 +1178,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ) .unwrap(); assert!(!passed); @@ -1327,8 +1310,6 @@ mod tests { &keys_changed, &verifiers, vp_cache, - #[cfg(not(feature = "mainnet"))] - false, ) } diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index f2a6d20da3..2794839734 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -33,7 +33,7 @@ use namada_core::ledger::governance::cli::onchain::{ PgfFunding, PgfFundingTarget, StewardsUpdate, }; use namada_test_utils::TestWasms; -use namada_vp_prelude::{testnet_pow, BTreeSet}; +use namada_vp_prelude::BTreeSet; use serde_json::json; use setup::constants::*; use setup::Test; @@ -409,22 +409,7 @@ fn stop_ledger_at_height() -> Result<()> { /// 8. Query the raw bytes of a storage key #[test] fn ledger_txs_and_queries() -> Result<()> { - let test = setup::network( - |genesis| { - #[cfg(not(feature = "mainnet"))] - { - GenesisConfig { - faucet_pow_difficulty: testnet_pow::Difficulty::try_new(1), - ..genesis - } - } - #[cfg(feature = "mainnet")] - { - genesis - } - }, - None, - )?; + let test = setup::network(|genesis| genesis, None)?; set_ethereum_bridge_mode( &test, @@ -569,42 +554,6 @@ fn ledger_txs_and_queries() -> Result<()> { "--node", &validator_one_rpc, ], - // 6. Submit a tx to withdraw from faucet account (requires PoW challenge - // solution) - vec![ - "transfer", - "--source", - "faucet", - "--target", - ALBERT, - "--token", - NAM, - "--amount", - "10.1", - // Faucet withdrawal requires an explicit signer - "--signing-keys", - ALBERT_KEY, - "--node", - &validator_one_rpc, - ], - // 6. Submit a tx to withdraw from faucet account (requires PoW challenge - // solution) - vec![ - "transfer", - "--source", - "faucet", - "--target", - ALBERT, - "--token", - NAM, - "--amount", - "10.1", - // Faucet withdrawal requires an explicit signer - "--signing-keys", - ALBERT_KEY, - "--node", - &validator_one_rpc, - ], ]; for tx_args in &txs_args { @@ -882,7 +831,7 @@ fn masp_txs_and_queries() -> Result<()> { /// 1. Test that a tx requesting a disposable signer with a correct unshielding /// operation is succesful /// 2. Test that a tx requesting a disposable signer -/// providing an insufficient unshielding goes through the PoW +/// providing an insufficient unshielding fails #[test] fn wrapper_disposable_signer() -> Result<()> { // Download the shielded pool parameters before starting node @@ -968,9 +917,10 @@ fn wrapper_disposable_signer() -> Result<()> { "--disposable-gas-payer", "--ledger-address", &validator_one_rpc, + "--force", ], // Not enough funds for fee payment, will use PoW - "Looking for a solution with difficulty", + "Error while processing transaction's fees", ), ]; diff --git a/tests/src/integration/masp.rs b/tests/src/integration/masp.rs index ac69f08a0d..4300b51e23 100644 --- a/tests/src/integration/masp.rs +++ b/tests/src/integration/masp.rs @@ -1230,7 +1230,6 @@ fn masp_txs_and_queries() -> Result<()> { /// 3. Submit a new wrapper with an invalid unshielding tx and assert the /// failure #[test] -#[should_panic(expected = "No faucet account found")] fn wrapper_fee_unshielding() { // This address doesn't matter for tests. But an argument is required. let validator_one_rpc = "127.0.0.1:26567"; @@ -1282,8 +1281,6 @@ fn wrapper_fee_unshielding() { NAM, "--amount", "1", - "--gas-price", - "30", "--gas-limit", "20000", "--gas-spending-key", @@ -1298,7 +1295,7 @@ fn wrapper_fee_unshielding() { // 3. Invalid unshielding // TODO: this test shall panic because of the panic in the sdk. Once the // panics are removed from there, this test can be updated - run( + let tx_run = run( &node, Bin::Client, vec![ @@ -1317,7 +1314,10 @@ fn wrapper_fee_unshielding() { B_SPENDING_KEY, "--ledger-address", validator_one_rpc, + "--force", ], ) - .unwrap(); + .is_err(); + + assert!(tx_run); } diff --git a/tests/src/storage_api/mod.rs b/tests/src/storage_api/mod.rs index a03a21ebd0..bc487bd59e 100644 --- a/tests/src/storage_api/mod.rs +++ b/tests/src/storage_api/mod.rs @@ -1,2 +1 @@ mod collections; -mod testnet_pow; diff --git a/tests/src/storage_api/testnet_pow.rs b/tests/src/storage_api/testnet_pow.rs deleted file mode 100644 index ab45bc99c8..0000000000 --- a/tests/src/storage_api/testnet_pow.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Tests for [`namada_core::ledger::testnet_pow`]. - -use namada_core::ledger::storage_api; -use namada_core::ledger::testnet_pow::*; -use namada_core::types::{address, token}; - -use crate::tx::{self, TestTxEnv}; -use crate::vp; - -#[test] -fn test_challenge_and_solution() -> storage_api::Result<()> { - let faucet_address = address::testing::established_address_1(); - let difficulty = Difficulty::try_new(1).unwrap(); - let withdrawal_limit = token::Amount::native_whole(1_000).into(); - - let mut tx_env = TestTxEnv::default(); - - // Source address that's using PoW (this would be derived from the tx - // wrapper pk) - let source = address::testing::established_address_2(); - - // Ensure that the addresses exists, so we can use them in a tx - tx_env.spawn_accounts([&faucet_address, &source]); - - init_faucet_storage( - &mut tx_env.wl_storage, - &faucet_address, - difficulty, - withdrawal_limit, - )?; - tx_env.commit_genesis(); - - let challenge = Challenge::new( - &mut tx_env.wl_storage, - &faucet_address, - source.clone(), - )?; - - let solution = challenge.solve(); - - // The solution must be valid - assert!(solution.verify_solution(source.clone())); - - // Changing the solution to `0` invalidates it - { - let solution = Solution { - value: 0, - ..solution.clone() - }; - // If you're unlucky and this fails, try changing the solution to - // a different literal. - assert!(!solution.verify_solution(source.clone())); - } - // Changing the counter invalidates it - { - let solution = Solution { - params: ChallengeParams { - difficulty: solution.params.difficulty, - counter: 10, - }, - ..solution - }; - // If you're unlucky and this fails, try changing the counter to - // a different literal. - assert!(!solution.verify_solution(source.clone())); - } - - // Apply the solution from a tx - vp::vp_host_env::init_from_tx(faucet_address.clone(), tx_env, |_addr| { - solution - .apply_from_tx(tx::ctx(), &faucet_address, &source) - .unwrap(); - }); - - // Check that it's valid - let is_valid = - solution.validate(&vp::ctx().pre(), &faucet_address, source.clone())?; - assert!(is_valid); - - // Commit the tx - let vp_env = vp::vp_host_env::take(); - tx::tx_host_env::set_from_vp_env(vp_env); - tx::tx_host_env::commit_tx_and_block(); - let tx_env = tx::tx_host_env::take(); - - // Re-apply the same solution from a tx - vp::vp_host_env::init_from_tx(faucet_address.clone(), tx_env, |_addr| { - solution - .apply_from_tx(tx::ctx(), &faucet_address, &source) - .unwrap(); - }); - - // Check that it's not longer valid - let is_valid = - solution.validate(&vp::ctx().pre(), &faucet_address, source)?; - assert!(!is_valid); - - Ok(()) -} diff --git a/tests/src/vm_host_env/vp.rs b/tests/src/vm_host_env/vp.rs index 7324fbd90e..296a32d384 100644 --- a/tests/src/vm_host_env/vp.rs +++ b/tests/src/vm_host_env/vp.rs @@ -52,8 +52,6 @@ pub struct TestVpEnv { pub result_buffer: Option>, pub vp_wasm_cache: VpCache, pub vp_cache_dir: TempDir, - #[cfg(not(feature = "mainnet"))] - pub has_valid_pow: bool, } impl Default for TestVpEnv { @@ -87,8 +85,6 @@ impl Default for TestVpEnv { result_buffer: None, vp_wasm_cache, vp_cache_dir, - #[cfg(not(feature = "mainnet"))] - has_valid_pow: false, } } } @@ -270,8 +266,6 @@ mod native_vp_host_env { result_buffer, vp_wasm_cache, vp_cache_dir: _, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, }: &mut TestVpEnv| { let env = vm::host_env::testing::vp_env( @@ -287,8 +281,6 @@ mod native_vp_host_env { keys_changed, eval_runner, vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - *has_valid_pow, ); // Call the `host_env` function and unwrap any @@ -317,8 +309,6 @@ mod native_vp_host_env { result_buffer, vp_wasm_cache, vp_cache_dir: _, - #[cfg(not(feature = "mainnet"))] - has_valid_pow, }: &mut TestVpEnv| { let env = vm::host_env::testing::vp_env( @@ -334,8 +324,6 @@ mod native_vp_host_env { keys_changed, eval_runner, vp_wasm_cache, - #[cfg(not(feature = "mainnet"))] - *has_valid_pow, ); // Call the `host_env` function and unwrap any @@ -372,7 +360,6 @@ mod native_vp_host_env { input_data_ptr: u64, input_data_len: u64, ) -> i64); - native_host_fn!(vp_has_valid_pow() -> i64); native_host_fn!(vp_log_string(str_ptr: u64, str_len: u64)); native_host_fn!(vp_verify_tx_section_signature( hash_list_ptr: u64, diff --git a/vm_env/src/lib.rs b/vm_env/src/lib.rs index 099460258b..d2ea27cbc6 100644 --- a/vm_env/src/lib.rs +++ b/vm_env/src/lib.rs @@ -216,8 +216,6 @@ pub mod vp { pub fn namada_vp_verify_masp(tx_ptr: u64, tx_len: u64) -> i64; - pub fn namada_vp_has_valid_pow() -> i64; - /// Charge the provided amount of gas for the current vp pub fn namada_vp_charge_gas(used_gas: u64); } diff --git a/vp_prelude/src/lib.rs b/vp_prelude/src/lib.rs index 32e29df46b..9a7e891624 100644 --- a/vp_prelude/src/lib.rs +++ b/vp_prelude/src/lib.rs @@ -15,13 +15,13 @@ use std::marker::PhantomData; pub use borsh::{BorshDeserialize, BorshSerialize}; pub use namada_core::ledger::governance::storage as gov_storage; +pub use namada_core::ledger::parameters; pub use namada_core::ledger::pgf::storage as pgf_storage; pub use namada_core::ledger::storage_api::{ self, iter_prefix, iter_prefix_bytes, Error, OptionExt, ResultExt, StorageRead, }; pub use namada_core::ledger::vp_env::VpEnv; -pub use namada_core::ledger::{parameters, testnet_pow}; pub use namada_core::proto::{Section, Tx}; pub use namada_core::types::address::Address; use namada_core::types::chain::CHAIN_ID_LENGTH; @@ -188,12 +188,6 @@ impl Ctx { pub fn post(&self) -> CtxPostStorageRead<'_> { CtxPostStorageRead { _ctx: self } } - - /// Check if the wrapper tx contained a valid testnet PoW - pub fn has_valid_pow(&self) -> bool { - let valid = unsafe { namada_vp_has_valid_pow() }; - HostEnvResult::is_success(valid) - } } /// Read access to the prior storage (state before tx execution) via diff --git a/wasm/checksums.json b/wasm/checksums.json index 9c50dd46dc..f02c940c6b 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,23 +1,22 @@ { - "tx_bond.wasm": "tx_bond.8d1ddbeb397209c5efa22dd57fbdb31825d67c2942441cb2612583ec2593831a.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.41ada308019a6227a495d996f5d3248e3f8052fcadf8779ee2b2e293aa73ccd0.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.137f2871848970aa9cf1d3a92a1e1a6e7a48b0537632d838bbb4e69fd301f8c3.wasm", - "tx_ibc.wasm": "tx_ibc.af007e03e8de1f8c34eb928fcfe91fd44b05c0183ca1149c5b262c8f62fcdd36.wasm", - "tx_init_account.wasm": "tx_init_account.d527ea17b417fca1a72d6a26abc34219630efcad4701e629a89e026e06ee06c1.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.e605bb96ff8b6ad1e10491a81590d15ed792f87b0382d1faee9966cb25a09028.wasm", - "tx_init_validator.wasm": "tx_init_validator.91ce97ff0bfa49ce9baa7585ae7e2c0514e91a66c625502b4aced635da5b021a.wasm", - "tx_resign_steward.wasm": "tx_resign_steward.a34a5737653182ecb75f6fcbac5b74ef849eb29b0072a20e90897acc14d8886e.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.8ab38f516ac799dcb96ba372cd5e5defd381ddf9d69579ce1556d1721d34f668.wasm", - "tx_transfer.wasm": "tx_transfer.738ac69d4a4f3dfb154aeed6b806ef1042b1a707de98bf8c6cc5ad66d478f6d9.wasm", - "tx_unbond.wasm": "tx_unbond.0c90a1f9a95b7171e0ebdca8318c19ba45f358158aa68370f630f84025635c8f.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.310c196cb7b2d371bb74fe37ee1f2f7e233ead59477027891e4e28751b6bb3fe.wasm", - "tx_update_account.wasm": "tx_update_account.8f5934e4fcca4e7d3c58e1c0b8722ce0a948efa6b99e7801dd1c16f8ea22fb59.wasm", - "tx_update_steward_commission.wasm": "tx_update_steward_commission.3deda3d2d0fcce2e14c6a4d72931ea3a3713666c6eed5fd29a78e30d395b3cf5.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.33567afd0c59d5f2499a3cf4ebf3c254de1cae1d310d004b8e0e538f2fc8377a.wasm", - "tx_withdraw.wasm": "tx_withdraw.00e0a04e892eb67ac3c3c7a3162b12dc198506c1c466893923911c3ab471dc03.wasm", - "vp_implicit.wasm": "vp_implicit.0fc8114c5d87db4d818b4b38ded664c1ca1d3d42026e6b1328213c00e99f01eb.wasm", - "vp_masp.wasm": "vp_masp.8b01ab3c616342973fb30e37c8b9e4c83615f25b7cc6657f0360146266d36890.wasm", - "vp_testnet_faucet.wasm": "vp_testnet_faucet.720d6808fa225cb3381ac0ff682e1c9136d8ef1193933ce30356ef2252fee001.wasm", - "vp_user.wasm": "vp_user.f93b90d5a0226c79159edd48f2801e7a12525751b937fda58525a8fc8b42d745.wasm", - "vp_validator.wasm": "vp_validator.3decad0fd761b928cdec3f89ed241fc218dd402be300f5edabf511677ae3d37d.wasm" + "tx_bond.wasm": "tx_bond.8dc46e48acf75c428d94a18a9467b7d185aae0a0bf467f662b63a15dbcf7564b.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.18f0e18aff3d8434001b649224c0fa6e69f9a116a04754ef88d46e3e9033445a.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.7e8690a39a0d6320ed6f5076f37c2d0ccce3ffa09d3b65ebf428e277a0f5a10a.wasm", + "tx_ibc.wasm": "tx_ibc.de43adc2364a7d0c6f17883ddbe9d36a4c7bb3bdb879c7950d2b9cee413c3720.wasm", + "tx_init_account.wasm": "tx_init_account.08c6b153997e28c19bdf5346568bc312ff022d57e039f4007d8b88eae52afb96.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.3f5a7fbc3bb06e2085252e60552a8a3655165834017af2852b3a9fe1d6409bbb.wasm", + "tx_init_validator.wasm": "tx_init_validator.d44de88c2e16d3f3970d432b27702942d0b511fa93f707d8ceac0165a4221311.wasm", + "tx_resign_steward.wasm": "tx_resign_steward.7fc38c6da69450ba4b5fc2eb78dbe5d0fdc601a50d3187b1646773cf476a9d15.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.5c19b170860b6b06f5cd8eeb466d93523ce96606268c46fa4eb4332b4e8e011e.wasm", + "tx_transfer.wasm": "tx_transfer.0c4a142ce5c1d317938cc27a4be85f929e43bd622ec7d4ad42d8dc20bafb1cd5.wasm", + "tx_unbond.wasm": "tx_unbond.5f11e4a5e6cb5be87d933eba303bd23ce9ef3f3f10b48a7ac63ba48d548afd9f.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.29235c9bae4a223e58ada2eadd1e9c3cb69caa36fbfe22c92e0363e67e0209b9.wasm", + "tx_update_account.wasm": "tx_update_account.951f5605b68427e3ace13d08779805d042ec904051b2c2944f757067ac85510f.wasm", + "tx_update_steward_commission.wasm": "tx_update_steward_commission.d7f2d79441f6521a5cfc895059cdb66d9029270850312fc6f6bf392814b42bec.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.09dc959eca5953ac572071f009760623c94dac1ba92b2d4ec9b43a922ffdadc1.wasm", + "tx_withdraw.wasm": "tx_withdraw.5d5098964e9c838fe2997c64192a6cf996a6fc1cedeb40cffbbe99ad62e992e7.wasm", + "vp_implicit.wasm": "vp_implicit.167b506e08d3047f7dde101c58e6d13fe675f27cc29259c976d5d303efef1554.wasm", + "vp_masp.wasm": "vp_masp.8444a5a8baff94479a3caf3cbf938e34c28e7c75310a34daef053ca38c5b5672.wasm", + "vp_user.wasm": "vp_user.9f2f1bec670446bbc3df30394af09c94b6f93db0f2867842b34dc433298422da.wasm", + "vp_validator.wasm": "vp_validator.6fca0d8ce915c8bffd4150f13d177b7b43596d7fedf3066dc3bab74a7615db6d.wasm" } \ No newline at end of file diff --git a/wasm/wasm_source/Cargo.toml b/wasm/wasm_source/Cargo.toml index 67e7bbc913..4682bc612e 100644 --- a/wasm/wasm_source/Cargo.toml +++ b/wasm/wasm_source/Cargo.toml @@ -31,7 +31,6 @@ tx_update_steward_commission = ["namada_tx_prelude"] tx_resign_steward = ["namada_tx_prelude"] vp_implicit = ["namada_vp_prelude", "once_cell"] vp_masp = ["namada_vp_prelude", "masp_primitives"] -vp_testnet_faucet = ["namada_vp_prelude", "once_cell"] vp_token = ["namada_vp_prelude"] vp_user = ["namada_vp_prelude", "once_cell"] vp_validator = ["namada_vp_prelude", "once_cell"] diff --git a/wasm/wasm_source/Makefile b/wasm/wasm_source/Makefile index 247062d610..7b00424baf 100644 --- a/wasm/wasm_source/Makefile +++ b/wasm/wasm_source/Makefile @@ -23,7 +23,6 @@ wasms += tx_update_steward_commission wasms += tx_resign_steward wasms += vp_implicit wasms += vp_masp -wasms += vp_testnet_faucet wasms += vp_user wasms += vp_validator diff --git a/wasm/wasm_source/src/lib.rs b/wasm/wasm_source/src/lib.rs index f4fd69cda3..d376f8ca70 100644 --- a/wasm/wasm_source/src/lib.rs +++ b/wasm/wasm_source/src/lib.rs @@ -35,8 +35,6 @@ pub mod tx_withdraw; pub mod vp_implicit; #[cfg(feature = "vp_masp")] pub mod vp_masp; -#[cfg(feature = "vp_testnet_faucet")] -pub mod vp_testnet_faucet; #[cfg(feature = "vp_user")] pub mod vp_user; #[cfg(feature = "vp_validator")] diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs deleted file mode 100644 index 44b5adfb06..0000000000 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ /dev/null @@ -1,466 +0,0 @@ -//! A "faucet" account for testnet. -//! -//! This VP allows anyone to withdraw up to -//! [`testnet_pow::read_withdrawal_limit`] tokens without the faucet's -//! signature, but with a valid PoW challenge solution that cannot be replayed. -//! -//! Any other storage key changes are allowed only with a valid signature. - -use namada_vp_prelude::*; -use once_cell::unsync::Lazy; - -#[validity_predicate(gas = 0)] -fn validate_tx( - ctx: &Ctx, - tx_data: Tx, - addr: Address, - keys_changed: BTreeSet, - verifiers: BTreeSet
, -) -> VpResult { - debug_log!( - "vp_testnet_faucet called with user addr: {}, key_changed: {:?}, \ - verifiers: {:?}", - addr, - keys_changed, - verifiers - ); - - let valid_sig = Lazy::new(|| { - matches!(verify_signatures(ctx, &tx_data, &addr), Ok(true)) - }); - - if !is_valid_tx(ctx, &tx_data)? { - return reject(); - } - - for key in keys_changed.iter() { - let is_valid = if let Some([token, owner]) = - token::is_any_token_balance_key(key) - { - if owner == &addr { - let pre: token::Amount = ctx.read_pre(key)?.unwrap_or_default(); - let post: token::Amount = - ctx.read_post(key)?.unwrap_or_default(); - let change = post.change() - pre.change(); - let maybe_denom = - storage_api::token::read_denom(&ctx.pre(), token)?; - if maybe_denom.is_none() { - debug_log!( - "A denomination for token address {} does not exist \ - in storage", - token, - ); - return reject(); - } - let denom = maybe_denom.unwrap(); - if !change.non_negative() { - // Allow to withdraw without a sig if there's a valid PoW - if ctx.has_valid_pow() { - let max_free_debit = - testnet_pow::read_withdrawal_limit( - &ctx.pre(), - &addr, - )?; - - token::Amount::from_uint(change.abs(), 0).unwrap() - <= token::Amount::from_uint(max_free_debit, denom) - .unwrap() - } else { - debug_log!("No PoW solution, a signature is required"); - // Debit without a solution has to signed - *valid_sig - } - } else { - // credit is permissive - true - } - } else { - // balance changes of other accounts - true - } - } else if let Some(owner) = key.is_validity_predicate() { - let has_post: bool = ctx.has_key_post(key)?; - if owner == &addr { - if has_post { - let vp_hash: Vec = ctx.read_bytes_post(key)?.unwrap(); - return Ok(*valid_sig && is_vp_whitelisted(ctx, &vp_hash)?); - } else { - return reject(); - } - } else { - let vp_hash: Vec = ctx.read_bytes_post(key)?.unwrap(); - return is_vp_whitelisted(ctx, &vp_hash); - } - } else { - // Allow any other key change if authorized by a signature - *valid_sig - }; - - if !is_valid { - debug_log!("key {} modification failed vp", key); - return reject(); - } - } - - accept() -} - -#[cfg(test)] -mod tests { - use address::testing::arb_non_internal_address; - use namada::proto::{Code, Data, MultiSignature, Signature}; - use namada::types::transaction::TxType; - use namada_test_utils::TestWasms; - // Use this as `#[test]` annotation to enable logging - use namada_tests::log::test; - use namada_tests::tx::{self, tx_host_env, TestTxEnv}; - use namada_tests::vp::vp_host_env::storage::Key; - use namada_tests::vp::*; - use namada_tx_prelude::{StorageWrite, TxEnv}; - use namada_vp_prelude::account::AccountPublicKeysMap; - use namada_vp_prelude::key::RefTo; - use proptest::prelude::*; - use storage::testing::arb_account_storage_key_no_vp; - - use super::*; - - /// Allows anyone to withdraw up to 1_000 tokens in a single tx - pub const MAX_FREE_DEBIT: i128 = 1_000_000_000; // in micro units - - /// Test that no-op transaction (i.e. no storage modifications) accepted. - #[test] - fn test_no_op_transaction() { - let mut tx_data = Tx::from_type(TxType::Raw); - tx_data.set_data(Data::new(vec![])); - let addr: Address = address::testing::established_address_1(); - let keys_changed: BTreeSet = BTreeSet::default(); - let verifiers: BTreeSet
= BTreeSet::default(); - - // The VP env must be initialized before calling `validate_tx` - vp_host_env::init(); - - assert!( - validate_tx(&CTX, tx_data, addr, keys_changed, verifiers).unwrap() - ); - } - - /// Test that a credit transfer is accepted. - #[test] - fn test_credit_transfer_accepted() { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - let vp_owner = address::testing::established_address_1(); - let source = address::testing::established_address_2(); - let token = address::nam(); - let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); - - // Spawn the accounts to be able to modify their storage - tx_env.spawn_accounts([&vp_owner, &source, &token]); - - // Credit the tokens to the source before running the transaction to be - // able to transfer from it - tx_env.credit_tokens(&source, &token, amount); - - let amount = token::DenominatedAmount { - amount, - denom: token::NATIVE_MAX_DECIMAL_PLACES.into(), - }; - - // Initialize VP environment from a transaction - vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { - // Apply transfer in a transaction - tx_host_env::token::transfer( - tx_host_env::ctx(), - &source, - address, - &token, - amount, - &None, - &None, - &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![])); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!( - validate_tx(&CTX, tx_data, vp_owner, keys_changed, verifiers) - .unwrap() - ); - } - - /// Test that a validity predicate update without a valid signature is - /// rejected. - #[test] - fn test_unsigned_vp_update_rejected() { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - let vp_owner = address::testing::established_address_1(); - let vp_code = TestWasms::VpAlwaysTrue.read_bytes(); - let vp_hash = sha256(&vp_code); - // for the update - tx_env.store_wasm_code(vp_code); - - // Spawn the accounts to be able to modify their storage - tx_env.spawn_accounts([&vp_owner]); - - // Initialize VP environment from a transaction - 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) - .unwrap(); - }); - - let vp_env = vp_host_env::take(); - let mut tx_data = Tx::from_type(TxType::Raw); - tx_data.set_data(Data::new(vec![])); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!( - !validate_tx(&CTX, tx_data, vp_owner, keys_changed, verifiers) - .unwrap() - ); - } - - /// Test that a validity predicate update with a valid signature is - /// accepted. - #[test] - fn test_signed_vp_update_accepted() { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - let vp_owner = address::testing::established_address_1(); - let keypair = key::testing::keypair_1(); - let public_key = &keypair.ref_to(); - let vp_code = TestWasms::VpAlwaysTrue.read_bytes(); - let vp_hash = sha256(&vp_code); - // for the update - tx_env.store_wasm_code(vp_code); - - // Spawn the accounts to be able to modify their storage - tx_env.spawn_accounts([&vp_owner]); - tx_env.init_account_storage(&vp_owner, vec![public_key.clone()], 1); - - // Initialize VP environment from a transaction - 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) - .unwrap(); - }); - - let pks_map = AccountPublicKeysMap::from_iter(vec![public_key.clone()]); - - 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::SectionSignature(MultiSignature::new( - vec![*tx.data_sechash(), *tx.code_sechash()], - &[keypair], - &pks_map, - ))); - let signed_tx = tx.clone(); - vp_env.tx = signed_tx.clone(); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!( - validate_tx(&CTX, signed_tx, vp_owner, keys_changed, verifiers) - .unwrap() - ); - } - - prop_compose! { - /// Generates an account address and a storage key inside its storage. - fn arb_account_storage_subspace_key() - // Generate an address - (address in arb_non_internal_address()) - // Generate a storage key other than its VP key (VP cannot be - // modified directly via `write`, it has to be modified via - // `tx::update_validity_predicate`. - (storage_key in arb_account_storage_key_no_vp(address.clone()), - // Use the generated address too - address in Just(address)) - -> (Address, Key) { - (address, storage_key) - } - } - - proptest! { - /// Test that a debit of more than [`MAX_FREE_DEBIT`] tokens without a valid signature is rejected. - #[test] - fn test_unsigned_debit_over_limit_rejected(amount in (MAX_FREE_DEBIT as u64 + 1..)) { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - // Init the VP - let vp_owner = address::testing::established_address_1(); - let difficulty = testnet_pow::Difficulty::try_new(0).unwrap(); - let withdrawal_limit = token::Amount::from_uint(MAX_FREE_DEBIT as u64, 0).unwrap(); - testnet_pow::init_faucet_storage(&mut tx_env.wl_storage, &vp_owner, difficulty, withdrawal_limit.into()).unwrap(); - - let target = address::testing::established_address_2(); - let token = address::nam(); - let amount = token::Amount::from_uint(amount, 0).unwrap(); - - // Spawn the accounts to be able to modify their storage - tx_env.spawn_accounts([&vp_owner, &target, &token]); - - // Credit the tokens to the VP owner before running the transaction to - // be able to transfer from it - tx_env.credit_tokens(&vp_owner, &token, amount); - tx_env.commit_genesis(); - let amount = token::DenominatedAmount { - amount, - denom: token::NATIVE_MAX_DECIMAL_PLACES.into() - }; - - // Initialize VP environment from a transaction - vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { - // Apply transfer in a transaction - tx_host_env::token::transfer(tx::ctx(), address, &target, &token, amount, &None, &None, &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![])); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!(!validate_tx(&CTX, tx_data, vp_owner, keys_changed, verifiers).unwrap()); - } - - /// Test that a debit of less than or equal to [`MAX_FREE_DEBIT`] tokens - /// without a valid signature but with a valid PoW solution is accepted. - #[test] - fn test_unsigned_debit_under_limit_accepted(amount in (..MAX_FREE_DEBIT as u64 + 1)) { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - // Init the VP - let vp_owner = address::testing::established_address_1(); - let difficulty = testnet_pow::Difficulty::try_new(0).unwrap(); - let withdrawal_limit = token::Amount::from_uint(MAX_FREE_DEBIT as u64, 0).unwrap(); - testnet_pow::init_faucet_storage(&mut tx_env.wl_storage, &vp_owner, difficulty, withdrawal_limit.into()).unwrap(); - - let target = address::testing::established_address_2(); - let target_key = key::testing::keypair_1(); - let _public_key = target_key.ref_to(); - let token = address::nam(); - let amount = token::Amount::from_uint(amount, 0).unwrap(); - - // Spawn the accounts to be able to modify their storage - tx_env.spawn_accounts([&vp_owner, &target, &token]); - - // Credit the tokens to the VP owner before running the transaction to - // be able to transfer from it - tx_env.credit_tokens(&vp_owner, &token, amount); - // write the denomination of NAM into storage - storage_api::token::write_denom(&mut tx_env.wl_storage, &token, token::NATIVE_MAX_DECIMAL_PLACES.into()).unwrap(); - tx_env.commit_genesis(); - - // Construct a PoW solution like a client would - let challenge = testnet_pow::Challenge::new(&mut tx_env.wl_storage, &vp_owner, target.clone()).unwrap(); - let solution = challenge.solve(); - let solution_bytes = solution.try_to_vec().unwrap(); - - let amount = token::DenominatedAmount { - amount, - denom: token::NATIVE_MAX_DECIMAL_PLACES.into(), - }; - - // Initialize VP environment from a transaction - vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { - // Don't call `Solution::invalidate_if_valid` - this is done by the - // shell's finalize_block. - let valid = solution.validate(tx::ctx(), address, target.clone()).unwrap(); - assert!(valid); - // Apply transfer in a transaction - tx_host_env::token::transfer(tx::ctx(), address, &target, &token, amount, &None, &None, &None).unwrap(); - }); - - let mut vp_env = vp_host_env::take(); - // This is set by the protocol when the wrapper tx has a valid PoW - 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.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash(), *tx_data.code_sechash()], &target_key))); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!(validate_tx(&CTX, tx_data, vp_owner, keys_changed, verifiers).unwrap()); - } - - /// Test that a signed tx that performs arbitrary storage writes or - /// deletes to the account is accepted. - #[test] - fn test_signed_arb_storage_write( - (vp_owner, storage_key) in arb_account_storage_subspace_key(), - // Generate bytes to write. If `None`, delete from the key instead - storage_value in any::>>(), - ) { - // Initialize a tx environment - let mut tx_env = TestTxEnv::default(); - - // Init the VP - let difficulty = testnet_pow::Difficulty::try_new(0).unwrap(); - let withdrawal_limit = token::Amount::from_uint(MAX_FREE_DEBIT as u64, 0).unwrap(); - testnet_pow::init_faucet_storage(&mut tx_env.wl_storage, &vp_owner, difficulty, withdrawal_limit.into()).unwrap(); - - let keypair = key::testing::keypair_1(); - let public_key = &keypair.ref_to(); - - // Spawn all the accounts in the storage key to be able to modify - // their storage - let storage_key_addresses = storage_key.find_addresses(); - tx_env.spawn_accounts(storage_key_addresses); - - tx_env.init_account_storage(&vp_owner, vec![public_key.clone()], 1); - - // Initialize VP environment from a transaction - vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |_address| { - // Write or delete some data in the transaction - if let Some(value) = &storage_value { - tx::ctx().write(&storage_key, value).unwrap(); - } else { - tx::ctx().delete(&storage_key).unwrap(); - } - }); - - let pks_map = AccountPublicKeysMap::from_iter(vec![public_key.clone()]); - - 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::SectionSignature(MultiSignature::new( - vec![*tx.data_sechash(), *tx.code_sechash()], - &[keypair], - &pks_map, - ))); - let signed_tx = tx.clone(); - vp_env.tx = signed_tx.clone(); - let keys_changed: BTreeSet = - vp_env.all_touched_storage_keys(); - let verifiers: BTreeSet
= BTreeSet::default(); - vp_host_env::set(vp_env); - assert!(validate_tx(&CTX, signed_tx, vp_owner, keys_changed, verifiers).unwrap()); - } - } -} diff --git a/wasm_for_tests/tx_memory_limit.wasm b/wasm_for_tests/tx_memory_limit.wasm index 94ed240378..10933a03a2 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 68c6723579..adb1e921ec 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 0d7b20da7f..490b84969a 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 b2cfea8633..729d9e9f50 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 fb483a0b84..3a6da643bf 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 39b20ef813..cffb764ed0 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 a0fb758ae9..5d600d185f 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 003fc115be..7ae138c050 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 a18626d71e..c2058b5cd6 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 98fcac06a2..4b388a3984 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 33b7c719f3..e735ba11b7 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 9867e71009..771165a1d5 100755 Binary files a/wasm_for_tests/vp_read_storage_key.wasm and b/wasm_for_tests/vp_read_storage_key.wasm differ