Skip to content

Commit 9f56c97

Browse files
authored
Merge of #4832
2 parents e56bba9 + 0b72a14 commit 9f56c97

File tree

17 files changed

+593
-69
lines changed

17 files changed

+593
-69
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- Closes #4714
2+
- When dry-running, dummy signatures are used in
3+
txs
4+
- Validation does not perform signature checks when dry-running
5+
6+
I have tested that the gas estimation hasn't changed between dry-running
7+
with signatures and with dummies. It is curious however that in both cases there is a small discrepancy between dry-running and the actual tx.
8+
([\#4714](https://github.com/namada-net/namada/issues/4714))

crates/apps_lib/src/cli.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7849,15 +7849,10 @@ pub mod args {
78497849
))
78507850
.conflicts_with(DRY_RUN_TX.name),
78517851
)
7852-
.arg(
7853-
DEVICE_TRANSPORT
7854-
.def()
7855-
.help(wrap!(
7856-
"Select transport for hardware wallet from \"hid\" \
7857-
(default) or \"tcp\"."
7858-
))
7859-
.conflicts_with(DRY_RUN_TX.name),
7860-
)
7852+
.arg(DEVICE_TRANSPORT.def().help(wrap!(
7853+
"Select transport for hardware wallet from \"hid\" (default) \
7854+
or \"tcp\"."
7855+
)))
78617856
.arg(
78627857
MEMO_OPT
78637858
.def()

crates/core/src/key/common.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,17 @@ impl super::SigScheme for SigScheme {
516516
_ => Err(VerifySigError::MismatchedScheme),
517517
}
518518
}
519+
520+
fn mock(keypair: &SecretKey) -> Self::Signature {
521+
match keypair {
522+
SecretKey::Ed25519(kp) => {
523+
Signature::Ed25519(ed25519::SigScheme::mock(kp))
524+
}
525+
SecretKey::Secp256k1(kp) => {
526+
Signature::Secp256k1(secp256k1::SigScheme::mock(kp))
527+
}
528+
}
529+
}
519530
}
520531

521532
#[cfg(test)]

crates/core/src/key/ed25519.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ impl super::SigScheme for SigScheme {
402402
Ok(())
403403
}
404404
}
405+
406+
fn mock(_: &Self::SecretKey) -> Self::Signature {
407+
Signature(ed25519_consensus::Signature::from([0; 64]))
408+
}
405409
}
406410

407411
#[cfg(feature = "arbitrary")]

crates/core/src/key/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ pub trait SigScheme: Eq + Ord + Debug + Serialize + Default {
268268
) -> Result<(), VerifySigError> {
269269
Self::verify_signature_with_hasher::<Sha256Hasher>(pk, data, sig)
270270
}
271+
272+
/// Provide a dummy signature
273+
fn mock(keypair: &Self::SecretKey) -> Self::Signature;
271274
}
272275

273276
/// Public key hash derived from `common::Key` borsh encoded bytes (hex string

crates/core/src/key/secp256k1.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,17 @@ impl super::SigScheme for SigScheme {
602602
Ok(())
603603
}
604604
}
605+
606+
fn mock(_: &Self::SecretKey) -> Self::Signature {
607+
Signature(
608+
k256::ecdsa::Signature::from_scalars(
609+
k256::Scalar::ONE,
610+
k256::Scalar::ONE,
611+
)
612+
.unwrap(),
613+
RecoveryId::from_byte(0).unwrap(),
614+
)
615+
}
605616
}
606617

607618
#[cfg(feature = "arbitrary")]

crates/node/src/bench_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ impl BenchShellInner {
285285
&mut self.inner.vp_wasm_cache,
286286
&mut self.inner.tx_wasm_cache,
287287
run::GasMeterKind::MutGlobal,
288+
false,
288289
)
289290
.unwrap()
290291
}

crates/node/src/dry_run_tx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ where
3030
CA: 'static + WasmCacheAccess + Sync,
3131
{
3232
let tx = Tx::try_from_bytes(&request.data[..]).into_storage_result()?;
33-
tx.validate_tx().into_storage_result()?;
3433

3534
let gas_scale = parameters::get_gas_scale(&state)?;
3635
let height = state.in_mem().get_block_height().0;
@@ -59,6 +58,7 @@ where
5958
&tx_gas_meter,
6059
&mut shell_params,
6160
None,
61+
true,
6262
)
6363
.into_storage_result()?;
6464

@@ -107,6 +107,7 @@ where
107107
&mut vp_wasm_cache,
108108
&mut tx_wasm_cache,
109109
protocol::GasMeterKind::MutGlobal,
110+
true,
110111
)
111112
.map_err(|err| err.error)
112113
.into_storage_result()?;

crates/node/src/protocol.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ where
252252
vp_wasm_cache,
253253
tx_wasm_cache,
254254
GasMeterKind::MutGlobal,
255+
false,
255256
)
256257
} else {
257258
// Governance proposal. We don't allow tx batches in this case,
@@ -270,6 +271,7 @@ where
270271
tx_wasm_cache,
271272
},
272273
GasMeterKind::MutGlobal,
274+
false,
273275
)
274276
.map_err(|e| Box::new(DispatchError::from(e)))?;
275277

@@ -328,6 +330,7 @@ where
328330
tx_gas_meter,
329331
&mut shell_params,
330332
Some(block_proposer),
333+
false,
331334
)
332335
.map_err(|e| {
333336
Box::new(Error::WrapperRunnerError(e.to_string()).into())
@@ -348,6 +351,7 @@ pub(crate) fn dispatch_inner_txs<'a, S, D, H, CA>(
348351
vp_wasm_cache: &'a mut VpCache<CA>,
349352
tx_wasm_cache: &'a mut TxCache<CA>,
350353
gas_meter_kind: GasMeterKind,
354+
dry_run: bool,
351355
) -> std::result::Result<TxResult<Error>, Box<DispatchError>>
352356
where
353357
S: 'static
@@ -384,6 +388,7 @@ where
384388
tx_wasm_cache,
385389
},
386390
gas_meter_kind,
391+
dry_run,
387392
) {
388393
Err(Error::GasError(msg)) => {
389394
// Gas error aborts the execution of the entire batch
@@ -489,6 +494,7 @@ pub(crate) fn apply_wrapper_tx<S, D, H, CA>(
489494
tx_gas_meter: &RefCell<TxGasMeter>,
490495
shell_params: &mut ShellParams<'_, S, D, H, CA>,
491496
block_proposer: Option<&Address>,
497+
dry_run: bool,
492498
) -> Result<TxResult<Error>>
493499
where
494500
S: 'static
@@ -514,7 +520,7 @@ where
514520
Some(block_proposer) => {
515521
transfer_fee(shell_params, block_proposer, tx, wrapper, tx_index)?
516522
}
517-
None => check_fees(shell_params, tx, wrapper)?,
523+
None => check_fees(shell_params, tx, wrapper, dry_run)?,
518524
};
519525

520526
// Commit tx to the block write log even in case of subsequent errors (if
@@ -627,7 +633,7 @@ where
627633
} else {
628634
// See if the first inner transaction of the batch pays the fees
629635
// with a masp unshield
630-
match try_masp_fee_payment(shell_params, tx, tx_index) {
636+
match try_masp_fee_payment(shell_params, tx, tx_index, false) {
631637
Ok(valid_batched_tx_result) => {
632638
#[cfg(not(fuzzing))]
633639
let balance = token::read_balance(
@@ -784,6 +790,7 @@ fn try_masp_fee_payment<S, D, H, CA>(
784790
}: &mut ShellParams<'_, S, D, H, CA>,
785791
tx: &Tx,
786792
tx_index: &TxIndex,
793+
dry_run: bool,
787794
) -> std::result::Result<MaspTxResult, MaspFeeError>
788795
where
789796
S: 'static
@@ -833,6 +840,7 @@ where
833840
tx_wasm_cache,
834841
},
835842
GasMeterKind::MutGlobal,
843+
dry_run,
836844
) {
837845
Ok(result) => {
838846
// NOTE: do not commit yet cause this could be exploited to get
@@ -958,6 +966,7 @@ pub fn check_fees<S, D, H, CA>(
958966
shell_params: &mut ShellParams<'_, S, D, H, CA>,
959967
tx: &Tx,
960968
wrapper: &WrapperTx,
969+
dry_run: bool,
961970
) -> Result<Option<MaspTxResult>>
962971
where
963972
S: 'static
@@ -994,6 +1003,7 @@ where
9941003
shell_params,
9951004
tx,
9961005
&TxIndex::default(),
1006+
dry_run,
9971007
)?;
9981008
let balance = token::read_balance(
9991009
shell_params.state,
@@ -1030,6 +1040,7 @@ fn apply_wasm_tx<S, D, H, CA>(
10301040
tx_index: &TxIndex,
10311041
shell_params: ShellParams<'_, S, D, H, CA>,
10321042
gas_meter_kind: GasMeterKind,
1043+
dry_run: bool,
10331044
) -> Result<BatchedTxResult>
10341045
where
10351046
S: 'static + State<D = D, H = H> + ReadConversionState + Sync,
@@ -1053,6 +1064,7 @@ where
10531064
vp_wasm_cache,
10541065
tx_wasm_cache,
10551066
gas_meter_kind,
1067+
dry_run,
10561068
)?;
10571069

10581070
let vps_result = check_vps(CheckVps {
@@ -1063,6 +1075,7 @@ where
10631075
verifiers_from_tx: &verifiers,
10641076
vp_wasm_cache,
10651077
gas_meter_kind,
1078+
dry_run,
10661079
})?;
10671080

10681081
let initialized_accounts = state.write_log().get_initialized_accounts();
@@ -1172,6 +1185,7 @@ fn execute_tx<S, D, H, CA>(
11721185
vp_wasm_cache: &mut VpCache<CA>,
11731186
tx_wasm_cache: &mut TxCache<CA>,
11741187
gas_meter_kind: GasMeterKind,
1188+
dry_run: bool,
11751189
) -> Result<BTreeSet<Address>>
11761190
where
11771191
S: State<D = D, H = H>,
@@ -1189,6 +1203,7 @@ where
11891203
vp_wasm_cache,
11901204
tx_wasm_cache,
11911205
gas_meter_kind,
1206+
dry_run,
11921207
)
11931208
.map_err(|err| match err {
11941209
wasm::run::Error::GasError(msg) => Error::GasError(msg),
@@ -1210,6 +1225,7 @@ where
12101225
verifiers_from_tx: &'a BTreeSet<Address>,
12111226
vp_wasm_cache: &'a mut VpCache<CA>,
12121227
gas_meter_kind: GasMeterKind,
1228+
dry_run: bool,
12131229
}
12141230

12151231
/// Check the acceptance of a transaction by validity predicates
@@ -1222,6 +1238,7 @@ fn check_vps<S, CA>(
12221238
verifiers_from_tx,
12231239
vp_wasm_cache,
12241240
gas_meter_kind,
1241+
dry_run,
12251242
}: CheckVps<'_, S, CA>,
12261243
) -> Result<VpsResult>
12271244
where
@@ -1241,6 +1258,7 @@ where
12411258
tx_gas_meter,
12421259
vp_wasm_cache,
12431260
gas_meter_kind,
1261+
dry_run,
12441262
)?;
12451263
tracing::debug!("Total VPs gas cost {:?}", vps_gas);
12461264

@@ -1262,6 +1280,7 @@ fn execute_vps<S, CA>(
12621280
tx_gas_meter: &TxGasMeter,
12631281
vp_wasm_cache: &mut VpCache<CA>,
12641282
gas_meter_kind: GasMeterKind,
1283+
dry_run: bool,
12651284
) -> Result<(VpsResult, namada_sdk::gas::Gas)>
12661285
where
12671286
S: 'static + ReadConversionState + State + Sync,
@@ -1298,6 +1317,7 @@ where
12981317
&verifiers,
12991318
vp_wasm_cache.clone(),
13001319
gas_meter_kind,
1320+
dry_run,
13011321
)
13021322
.map_err(|err| match err {
13031323
wasm::run::Error::GasError(msg) => {
@@ -1755,6 +1775,7 @@ mod tests {
17551775
&gas_meter,
17561776
&mut vp_cache,
17571777
GasMeterKind::MutGlobal,
1778+
false,
17581779
);
17591780
assert!(matches!(result.unwrap_err(), Error::GasError(_)));
17601781
}
@@ -1808,6 +1829,7 @@ mod tests {
18081829
&Default::default(),
18091830
vp_cache.clone(),
18101831
GasMeterKind::MutGlobal,
1832+
false,
18111833
)
18121834
.is_ok()
18131835
);
@@ -1838,6 +1860,7 @@ mod tests {
18381860
&Default::default(),
18391861
vp_cache.clone(),
18401862
GasMeterKind::MutGlobal,
1863+
false,
18411864
)
18421865
.is_err()
18431866
);

crates/node/src/shell/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ where
15191519
))))?;
15201520

15211521
fee_data_check(wrapper, minimum_gas_price, shell_params)?;
1522-
protocol::check_fees(shell_params, tx, wrapper)
1522+
protocol::check_fees(shell_params, tx, wrapper, false)
15231523
.map_err(Error::TxApply)
15241524
.map(|_| ())
15251525
}

0 commit comments

Comments
 (0)