Skip to content

Commit b6ef912

Browse files
marian-radupgherveougithub-actions[bot]
authored
pallet_revive: when a dry run simulates contract deployment, return the execution result data. (#10032)
Fixes paritytech/contract-issues#177 Expose the deployed contract's runtime bytecode in eth_call responses during simulated contract creation. The test from issue paritytech/contract-issues#177 sends an eth_call request without a destination address, while providing contract bytecode in the data field. This simulates a contract creation transaction. The test expects the RPC response to return the result of executing the init code, which is the deployed contract's runtime bytecode. While this result is not returned in actual deployments, it is expected in dry-run simulations. --------- Co-authored-by: pgherveou <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 33d8678 commit b6ef912

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

prdoc/pr_10032.prdoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
title: 'pallet_revive: when a dry run simulates contract deployment, return the execution
2+
result data.'
3+
doc:
4+
- audience: Runtime Dev
5+
description: |-
6+
Fixes https://github.com/paritytech/contract-issues/issues/177
7+
8+
Expose the deployed contract's runtime bytecode in eth_call responses during simulated contract creation.
9+
10+
The test from issue https://github.com/paritytech/contract-issues/issues/177 sends an eth_call request without a destination address, while providing contract bytecode in the data field. This simulates a contract creation transaction. The test expects the RPC response to return the result of executing the init code, which is the deployed contract's runtime bytecode. While this result is not returned in actual deployments, it is expected in dry-run simulations.
11+
crates:
12+
- name: pallet-revive
13+
bump: patch

substrate/frame/revive/src/exec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,12 @@ where
12881288
// if we are dealing with EVM bytecode
12891289
// We upload the new runtime code, and update the code
12901290
if !is_pvm {
1291-
// Only keep return data for tracing
1292-
let data = if crate::tracing::if_tracing(|_| {}).is_none() {
1291+
// Only keep return data for tracing and for dry runs.
1292+
// When a dry-run simulates contract deployment, keep the execution result's
1293+
// data.
1294+
let data = if crate::tracing::if_tracing(|_| {}).is_none() &&
1295+
!self.exec_config.is_dry_run
1296+
{
12931297
core::mem::replace(&mut output.data, Default::default())
12941298
} else {
12951299
output.data.clone()

substrate/frame/revive/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@ impl<T: Config> Pallet<T> {
16661666
call_info.encoded_len,
16671667
base_info.total_weight(),
16681668
)
1669+
.with_dry_run()
16691670
};
16701671

16711672
// emulate transaction behavior
@@ -2580,7 +2581,7 @@ macro_rules! impl_runtime_apis_plus_revive_traits {
25802581
gas_limit.unwrap_or(blockweights.max_block),
25812582
storage_deposit_limit.unwrap_or(u128::MAX),
25822583
input_data,
2583-
$crate::ExecConfig::new_substrate_tx(),
2584+
$crate::ExecConfig::new_substrate_tx().with_dry_run(),
25842585
)
25852586
}
25862587

@@ -2606,7 +2607,7 @@ macro_rules! impl_runtime_apis_plus_revive_traits {
26062607
code,
26072608
data,
26082609
salt,
2609-
$crate::ExecConfig::new_substrate_tx(),
2610+
$crate::ExecConfig::new_substrate_tx().with_dry_run(),
26102611
)
26112612
}
26122613

substrate/frame/revive/src/primitives.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,20 @@ pub struct ExecConfig {
348348
///
349349
/// It is determined when transforming `eth_transact` into a proper extrinsic.
350350
pub effective_gas_price: Option<U256>,
351+
/// Whether this configuration was created for a dry-run execution.
352+
/// Use to enable logic that should only run in dry-run mode.
353+
pub is_dry_run: bool,
351354
}
352355

353356
impl ExecConfig {
354-
/// Create a default config appropriate when the call originated from a subtrate tx.
357+
/// Create a default config appropriate when the call originated from a substrate tx.
355358
pub fn new_substrate_tx() -> Self {
356-
Self { bump_nonce: true, collect_deposit_from_hold: None, effective_gas_price: None }
359+
Self {
360+
bump_nonce: true,
361+
collect_deposit_from_hold: None,
362+
effective_gas_price: None,
363+
is_dry_run: false,
364+
}
357365
}
358366

359367
/// Create a default config appropriate when the call originated from a ethereum tx.
@@ -362,8 +370,15 @@ impl ExecConfig {
362370
bump_nonce: false,
363371
collect_deposit_from_hold: Some((encoded_len, base_weight)),
364372
effective_gas_price: Some(effective_gas_price),
373+
is_dry_run: false,
365374
}
366375
}
376+
377+
/// Set this config to be a dry-run.
378+
pub fn with_dry_run(mut self) -> Self {
379+
self.is_dry_run = true;
380+
self
381+
}
367382
}
368383

369384
/// Indicates whether the code was removed after the last refcount was decremented.

0 commit comments

Comments
 (0)