Skip to content

Commit

Permalink
remove check for maximum number of signatures per tx
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jun 6, 2024
1 parent 879a326 commit 743c154
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 150 deletions.
2 changes: 0 additions & 2 deletions crates/apps_lib/src/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ pub struct Parameters {
pub epochs_per_year: u64,
/// How many epochs it takes to transition to the next masp epoch
pub masp_epoch_multiplier: u64,
/// Maximum amount of signatures per transaction
pub max_signatures_per_transaction: u8,
/// Fee unshielding gas limit
pub fee_unshielding_gas_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee payment
Expand Down
2 changes: 0 additions & 2 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ impl Finalized {
implicit_vp,
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
fee_unshielding_gas_limit,
max_block_gas,
minimum_gas_price,
Expand Down Expand Up @@ -349,7 +348,6 @@ impl Finalized {
epochs_per_year,
masp_epoch_multiplier,
max_proposal_bytes,
max_signatures_per_transaction,
fee_unshielding_gas_limit,
max_block_gas,
minimum_gas_price: minimum_gas_price
Expand Down
4 changes: 0 additions & 4 deletions crates/apps_lib/src/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ pub struct ChainParams<T: TemplateValidation> {
pub epochs_per_year: u64,
/// How many epochs it takes to transition to the next masp epoch
pub masp_epoch_multiplier: u64,
/// Maximum number of signature per transaction
pub max_signatures_per_transaction: u8,
/// Max gas for block
pub max_block_gas: u64,
/// Fee unshielding gas limit
Expand All @@ -322,7 +320,6 @@ impl ChainParams<Unvalidated> {
implicit_vp,
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
max_block_gas,
fee_unshielding_gas_limit,
minimum_gas_price,
Expand Down Expand Up @@ -368,7 +365,6 @@ impl ChainParams<Unvalidated> {
implicit_vp,
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
max_block_gas,
fee_unshielding_gas_limit,
minimum_gas_price: min_gas_prices,
Expand Down
1 change: 0 additions & 1 deletion crates/apps_lib/src/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,6 @@ impl<T> Signed<T> {
AccountPublicKeysMap::from_iter(public_keys.into_iter()),
&None,
threshold,
None,
|| Ok(()),
)
.map_err(|err| err.to_string())?;
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ pub struct Parameters {
/// The multiplier for masp epochs (it requires this amount of epochs to
/// transition to the next masp epoch)
pub masp_epoch_multiplier: u64,
/// Maximum number of signature per transaction
pub max_signatures_per_transaction: u8,
/// Fee unshielding gas limit
pub fee_unshielding_gas_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee payment
Expand Down
5 changes: 0 additions & 5 deletions crates/namada/src/ledger/native_vp/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ where
let threshold =
crate::account::threshold(&self.ctx.pre(), signer)?
.unwrap_or(1);
let max_signatures_per_transaction =
crate::parameters::max_signatures_per_transaction(
&self.ctx.pre(),
)?;
let mut gas_meter = self.ctx.gas_meter.borrow_mut();
tx_data
.tx
Expand All @@ -508,7 +504,6 @@ where
public_keys_index_map,
&Some(signer.clone()),
threshold,
max_signatures_per_transaction,
|| gas_meter.consume(crate::gas::VERIFY_TX_SIG_GAS),
)
.map_err(native_vp::Error::new)?;
Expand Down
22 changes: 0 additions & 22 deletions crates/namada/src/vm/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1963,8 +1963,6 @@ pub fn vp_verify_tx_section_signature<MEM, D, H, EVAL, CA>(
signer_ptr: u64,
signer_len: u64,
threshold: u8,
max_signatures_ptr: u64,
max_signatures_len: u64,
) -> vp_host_fns::EnvResult<()>
where
MEM: VmMemory,
Expand Down Expand Up @@ -2002,22 +2000,13 @@ where
let signer = Address::try_from_slice(&signer)
.map_err(vp_host_fns::RuntimeError::EncodingError)?;

let (max_signatures, gas) = env
.memory
.read_bytes(max_signatures_ptr, max_signatures_len.try_into()?)
.map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?;
vp_host_fns::add_gas(gas_meter, gas)?;
let max_signatures = Option::<u8>::try_from_slice(&max_signatures)
.map_err(vp_host_fns::RuntimeError::EncodingError)?;

let tx = unsafe { env.ctx.tx.get() };

match tx.verify_signatures(
&hashes,
public_keys_map,
&Some(signer),
threshold,
max_signatures,
|| gas_meter.borrow_mut().consume(gas::VERIFY_TX_SIG_GAS),
) {
Ok(_) => Ok(()),
Expand Down Expand Up @@ -2136,8 +2125,6 @@ pub fn tx_verify_tx_section_signature<MEM, D, H, CA>(
public_keys_map_ptr: u64,
public_keys_map_len: u64,
threshold: u8,
max_signatures_ptr: u64,
max_signatures_len: u64,
) -> TxResult<i64>
where
MEM: VmMemory,
Expand Down Expand Up @@ -2167,14 +2154,6 @@ where

tx_charge_gas::<MEM, D, H, CA>(env, gas)?;

let (max_signatures, gas) = env
.memory
.read_bytes(max_signatures_ptr, max_signatures_len.try_into()?)
.map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?;
tx_charge_gas::<MEM, D, H, CA>(env, gas)?;
let max_signatures = Option::<u8>::try_from_slice(&max_signatures)
.map_err(TxRuntimeError::EncodingError)?;

let tx = unsafe { env.ctx.tx.get() };

let (gas_meter, sentinel) = env.ctx.gas_meter_and_sentinel();
Expand All @@ -2183,7 +2162,6 @@ where
public_keys_map,
&None,
threshold,
max_signatures,
|| gas_meter.borrow_mut().consume(gas::VERIFY_TX_SIG_GAS),
) {
Ok(_) => Ok(HostEnvResult::Success.to_i64()),
Expand Down
79 changes: 77 additions & 2 deletions crates/namada/src/vm/wasm/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
"namada_tx_set_commitment_sentinel" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_0(host_env::tx_set_commitment_sentinel)),
"namada_tx_update_masp_note_commitment_tree" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_2(host_env::tx_update_masp_note_commitment_tree)),
"namada_tx_update_validity_predicate" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_6(host_env::tx_update_validity_predicate)),
"namada_tx_verify_tx_section_signature" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_7(host_env::tx_verify_tx_section_signature)),
"namada_tx_verify_tx_section_signature" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_5(host_env::tx_verify_tx_section_signature)),
"namada_tx_write" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_4(host_env::tx_write)),
"namada_tx_write_temp" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_4(host_env::tx_write_temp)),
"namada_tx_yield_value" => Function::new_typed_with_env(wasm_store, &env, wrap_tx::_2(host_env::tx_yield_value)),
Expand Down Expand Up @@ -99,7 +99,7 @@ where
"namada_vp_read_pre" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_2(host_env::vp_read_pre)),
"namada_vp_read_temp" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_2(host_env::vp_read_temp)),
"namada_vp_result_buffer" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_1(host_env::vp_result_buffer)),
"namada_vp_verify_tx_section_signature" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_9(host_env::vp_verify_tx_section_signature)),
"namada_vp_verify_tx_section_signature" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_7(host_env::vp_verify_tx_section_signature)),
"namada_vp_yield_value" => Function::new_typed_with_env(wasm_store, &env, wrap_vp::_2(host_env::vp_yield_value)),
},
}
Expand Down Expand Up @@ -182,6 +182,34 @@ mod wrap_tx {
}
}

pub(super) fn _5<F, ARG0, ARG1, ARG2, ARG3, ARG4, RET, D, H, CA>(
f: F,
) -> impl Fn(
FunctionEnvMut<'_, TxVmEnv<WasmMemory, D, H, CA>>,
ARG0,
ARG1,
ARG2,
ARG3,
ARG4,
) -> RET
where
D: DB + for<'iter> DBIter<'iter> + 'static,
H: StorageHasher + 'static,
CA: WasmCacheAccess + 'static,
F: Fn(
&mut TxVmEnv<WasmMemory, D, H, CA>,
ARG0,
ARG1,
ARG2,
ARG3,
ARG4,
) -> RET,
{
move |mut env, arg0, arg1, arg2, arg3, arg4| {
f(env.data_mut(), arg0, arg1, arg2, arg3, arg4)
}
}

pub(super) fn _6<F, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, RET, D, H, CA>(
f: F,
) -> impl Fn(
Expand Down Expand Up @@ -343,6 +371,53 @@ mod wrap_vp {
}
}

pub(super) fn _7<
F,
ARG0,
ARG1,
ARG2,
ARG3,
ARG4,
ARG5,
ARG6,
RET,
D,
H,
EVAL,
CA,
>(
f: F,
) -> impl Fn(
FunctionEnvMut<'_, VpVmEnv<WasmMemory, D, H, EVAL, CA>>,
ARG0,
ARG1,
ARG2,
ARG3,
ARG4,
ARG5,
ARG6,
) -> RET
where
D: DB + for<'iter> DBIter<'iter> + 'static,
H: StorageHasher + 'static,
CA: WasmCacheAccess + 'static,
EVAL: VpEvaluator<Db = D, H = H, Eval = EVAL, CA = CA> + 'static,
F: Fn(
&mut VpVmEnv<WasmMemory, D, H, EVAL, CA>,
ARG0,
ARG1,
ARG2,
ARG3,
ARG4,
ARG5,
ARG6,
) -> RET,
{
move |mut env, arg0, arg1, arg2, arg3, arg4, arg5, arg6| {
f(env.data_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
}
}

pub(super) fn _9<
F,
ARG0,
Expand Down
1 change: 0 additions & 1 deletion crates/node/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ mod tests {
implicit_vp_code_hash: Default::default(),
epochs_per_year: 365,
masp_epoch_multiplier: 2,
max_signatures_per_transaction: 10,
fee_unshielding_gas_limit: 0,
minimum_gas_price: Default::default(),
is_native_token_transferable: true,
Expand Down
42 changes: 0 additions & 42 deletions crates/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ where
implicit_vp_code_hash,
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
minimum_gas_price,
fee_unshielding_gas_limit,
is_native_token_transferable,
Expand Down Expand Up @@ -139,13 +138,6 @@ where
let masp_epoch_multiplier_key = storage::get_masp_epoch_multiplier_key();
storage.write(&masp_epoch_multiplier_key, masp_epoch_multiplier)?;

let max_signatures_per_transaction_key =
storage::get_max_signatures_per_transaction_key();
storage.write(
&max_signatures_per_transaction_key,
max_signatures_per_transaction,
)?;

let gas_cost_key = storage::get_gas_cost_key();
storage.write(&gas_cost_key, minimum_gas_price)?;

Expand All @@ -157,17 +149,6 @@ where
Ok(())
}

/// Get the max signatures per transactio parameter
pub fn max_signatures_per_transaction<S>(
storage: &S,
) -> namada_storage::Result<Option<u8>>
where
S: StorageRead,
{
let key = storage::get_max_signatures_per_transaction_key();
storage.read(&key)
}

/// Update the max_expected_time_per_block parameter in storage. Returns the
/// parameters and gas cost.
pub fn update_max_expected_time_per_block_parameter<S>(
Expand Down Expand Up @@ -259,18 +240,6 @@ where
storage.write(&key, implicit_vp)
}

/// Update the max signatures per transaction storage parameter
pub fn update_max_signature_per_tx<S>(
storage: &mut S,
value: u8,
) -> namada_storage::Result<()>
where
S: StorageRead + StorageWrite,
{
let key = storage::get_max_signatures_per_transaction_key();
storage.write(&key, value)
}

/// Read the the epoch duration parameter from store
pub fn read_epoch_duration_parameter<S>(
storage: &S,
Expand Down Expand Up @@ -389,15 +358,6 @@ where
// read masp epoch multiplier
let masp_epoch_multiplier = read_masp_epoch_multiplier_parameter(storage)?;

// read the maximum signatures per transaction
let max_signatures_per_transaction_key =
storage::get_max_signatures_per_transaction_key();
let value: Option<u8> =
storage.read(&max_signatures_per_transaction_key)?;
let max_signatures_per_transaction: u8 = value
.ok_or(ReadError::ParametersMissing)
.into_storage_result()?;

// read gas cost
let gas_cost_key = storage::get_gas_cost_key();
let value = storage.read(&gas_cost_key)?;
Expand Down Expand Up @@ -430,7 +390,6 @@ where
implicit_vp_code_hash: Some(implicit_vp_code_hash),
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
minimum_gas_price,
fee_unshielding_gas_limit,
is_native_token_transferable,
Expand Down Expand Up @@ -476,7 +435,6 @@ where
implicit_vp_code_hash: Default::default(),
epochs_per_year: 365,
masp_epoch_multiplier: 2,
max_signatures_per_transaction: 10,
fee_unshielding_gas_limit: 0,
minimum_gas_price: Default::default(),
is_native_token_transferable: true,
Expand Down
6 changes: 0 additions & 6 deletions crates/parameters/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct Keys {
max_block_gas: &'static str,
minimum_gas_price: &'static str,
fee_unshielding_gas_limit: &'static str,
max_signatures_per_transaction: &'static str,
native_token_transferable: &'static str,
}

Expand Down Expand Up @@ -161,11 +160,6 @@ pub fn get_gas_cost_key() -> Key {
get_minimum_gas_price_key_at_addr(ADDRESS)
}

/// Storage key used for the max signatures per transaction key
pub fn get_max_signatures_per_transaction_key() -> Key {
get_max_signatures_per_transaction_key_at_addr(ADDRESS)
}

/// Helper function to retrieve the `max_block_gas` protocol parameter from
/// storage
pub fn get_max_block_gas(
Expand Down
1 change: 0 additions & 1 deletion crates/proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,6 @@ pub mod test_utils {
implicit_vp_code_hash: Some(Hash::default()),
epochs_per_year: 10000000,
masp_epoch_multiplier: 2,
max_signatures_per_transaction: 15,
fee_unshielding_gas_limit: 10000,
minimum_gas_price: BTreeMap::new(),
is_native_token_transferable: true,
Expand Down
1 change: 0 additions & 1 deletion crates/state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ mod tests {
implicit_vp_code_hash: Some(Hash::zero()),
epochs_per_year: 100,
masp_epoch_multiplier: 2,
max_signatures_per_transaction: 15,
fee_unshielding_gas_limit: 20_000,
minimum_gas_price: BTreeMap::default(),
is_native_token_transferable: true,
Expand Down
Loading

0 comments on commit 743c154

Please sign in to comment.