Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
de2a301
Allow txs with no chain id to be executed on pallet-revive
0xOmarA Nov 29, 2025
bb198a9
Formatting
0xOmarA Nov 29, 2025
89fb643
Update the fix implementation
0xOmarA Nov 29, 2025
bb01922
Add tests for Nick's method deployment
0xOmarA Nov 29, 2025
5943759
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Nov 29, 2025
abca514
Update the commit hash of the revive-differential-tests (#10397)
0xOmarA Nov 29, 2025
8d5a721
Add an RPC flag for allowing unprotected transactions
0xOmarA Dec 2, 2025
07cafdf
Merge branch 'master' into 0xOmarA/allow-no-chain-id-txs
athei Dec 17, 2025
ba08030
Fix compilation
athei Dec 17, 2025
a3d9df4
Merge branch 'master' into 0xOmarA/allow-no-chain-id-txs
athei Dec 24, 2025
1473631
Remove un-needed test
0xOmarA Jan 6, 2026
95e1161
Add a comment to contract_deployment_with_nick_method_works
0xOmarA Jan 6, 2026
6095c96
Merge remote-tracking branch 'origin/master' into 0xOmarA/allow-no-ch…
0xOmarA Jan 6, 2026
61626bb
Merge branch 'master' into 0xOmarA/allow-no-chain-id-txs
athei Jan 6, 2026
bb6e801
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Jan 6, 2026
180b343
Add missing crates to PRdoc
athei Jan 6, 2026
37eb1a9
Move rpc flag to revive-eth-rpc
0xOmarA Jan 6, 2026
866afcd
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Jan 6, 2026
fa26f93
Update prdoc/pr_10476.prdoc
athei Jan 6, 2026
f302fea
Merge branch 'master' into 0xOmarA/allow-no-chain-id-txs
athei Jan 6, 2026
e58123f
Fix prdoc
athei Jan 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions prdoc/pr_10476.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
title: Allow for "Nick's Method" style deployments
doc:
- audience: Runtime Dev
description: "# Description\n\nThis pull request allows for \u201C[Nick\u2019s Method](https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7)\u201D\
\ style of deploying contracts which was requested in https://github.com/paritytech/contract-issues/issues/225\
\ and was attempted to be solved in https://github.com/paritytech/contract-issues/issues/99.\n\
\nThe \u201CNick Method\u201D style of contract deployment is a very useful concept\
\ to use when we wish to deploy a contract on multiple chains **with the same\
\ address**. It allows us to do that by constructing a deployment transaction\
\ that can be executed on any chain, thus allowing us to get the same address\
\ for the contract\u2019s deployment on any chain.\n\nAdditionally, this method\
\ allows for the contracts to be deployed trustlessly, meaning that if any actor\
\ (regardless of whether they\u2019re honest or not) follow the same method for\
\ deploying the contract then they\u2019d get the same address across all chains.\
\ This allows anyone in the Polkadot ecosystem to take existing contracts that\
\ use this method of deployment (e.g., `Multicall3` and the ERC-1820 registry)\
\ and deploy them on Polkadot and there\u2019s already trust that the code is\
\ the same.\n\nIn order to be able to use the same transaction across multiple\
\ chains transaction authors need to:\n\n- Not include a chain id.\n- Include\
\ a high gas limit so that the transaction works on (almost) all chains.\n\nAs\
\ mentioned in https://github.com/paritytech/contract-issues/issues/225, this\
\ pattern is already being used in a number of contracts. Most notably, `Multicall3`\
\ and the ERC-1820 Registry.\n\nBefore this PR this method didn\u2019t work in\
\ revive since the chain id was an absolute must and any transaction that didn\u2019\
t include a chain id would fail with an `Invalid Transaction` error as seen below:\n\
\nhttps://github.com/paritytech/polkadot-sdk/blob/c688963f51c55b3c2a16a00a33c4a086792a1544/substrate/frame/revive/src/evm/call.rs#L71-L76\n\
\nThe above implementation misses an important detail: legacy transactions are\
\ permitted to not have the chain id set while all other non-legacy transactions\
\ do not permit that. Therefore, this part of the code was changed to the following:\n\
\n```rust\nmatch (tx.chain_id, tx.r#type.as_ref()) {\n\t(None, Some(super::Byte(TYPE_LEGACY)))\
\ => {},\n\t(Some(chain_id), ..) =>\n\t\tif chain_id != <T as Config>::ChainId::get().into()\
\ {\n\t\t\tlog::debug!(target: LOG_TARGET, \"Invalid chain_id {chain_id:?}\");\n\
\t\t\treturn Err(InvalidTransaction::Call);\n\t\t},\n\t(None, ..) => {\n\t\tlog::debug!(target:\
\ LOG_TARGET, \"Invalid chain_id None\");\n\t\treturn Err(InvalidTransaction::Call);\n\
\t},\n}\n```\n\nThe above code skips the chain id check if the transaction is\
\ of the legacy type. Otherwise, the chain id is checked. If no chain id is provided\
\ and the transaction is not of the legacy type then we error out.\n\n## Integration\n\
\nBe aware that we now allow for legacy transactions to not have the chain ID\
\ set in order to allow for \u201C[Nick\u2019s Method](https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7)\u201D\
\ style of contract deployment. Non-legacy transaction continue to require the\
\ chain id to be provided.\n\n## Review Notes\n\n- The main change that this PR\
\ makes can be found in the `substrate/frame/revive/src/evm/call.rs` file allowing\
\ for legacy contracts to not have the chain id set.\n- Two new tests were added\
\ with this PR:\n - `dry_run_contract_deployment_with_nick_method_works`\n -\
\ `contract_deployment_with_nick_method_works`\n- Both of the above tests test\
\ that \u201C[Nick\u2019s Method](https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7)\u201D\
\ can be used to deploy the singleton factory contract provided in [ERC-2470](https://eips.ethereum.org/EIPS/eip-2470)\
\ in a dry run and in an `eth_transact` call.\n- Note that the above tests needed\
\ to modify the transaction provided in the ERC to update its gas limit (since\
\ the provided gas limit was too low for our platform), **which breaks the whole\
\ idea of Nick\u2019s Method where the same transaction can be submitted to the\
\ same chain**. I suspect that https://github.com/paritytech/polkadot-sdk/pull/10393\
\ should fix this issue with the new gas scaling."
crates:
- name: pallet-revive
bump: patch
26 changes: 20 additions & 6 deletions substrate/frame/revive/src/evm/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Functionality to decode an eth transaction into an dispatchable call.

use crate::{
evm::{fees::InfoT, runtime::SetWeightLimit},
evm::{fees::InfoT, runtime::SetWeightLimit, TYPE_LEGACY},
extract_code_and_data, BalanceOf, CallOf, Config, GenericTransaction, Pallet, Weight, Zero,
LOG_TARGET, RUNTIME_PALLETS_ADDR, U256,
};
Expand Down Expand Up @@ -68,11 +68,25 @@ where
return Err(InvalidTransaction::Payment);
};

let chain_id = tx.chain_id.unwrap_or_default();

if chain_id != <T as Config>::ChainId::get().into() {
log::debug!(target: LOG_TARGET, "Invalid chain_id {chain_id:?}");
return Err(InvalidTransaction::Call);
// We would like to allow for transactions without a chain id to be executed through pallet
// revive. These are called unprotected transactions and they are transactions that predate
// EIP-155 which do not include a Chain ID. These transactions are still useful today in certain
// patterns in Ethereum such as "Nick's Method" for contract deployment which allows a contract
// to be deployed on all chains with the same address. This is only allowed for legacy
// transactions and isn't allowed for any other transaction type.
// * Here's a relevant EIP: https://eips.ethereum.org/EIPS/eip-2470
// * Here's Nick's article: https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a doc comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would you recommend the doc comment to go? AFAIK there is no place to add a doc comment other than functions, types, etc, so there's no place that would accept a doc comment here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked article doesn't talk about chain IDs at all. What am I missing?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Nick's method is not really talking about chain IDs at all, but for the contracts mentioned in the issue they are not using EIP2718 transaction envelope or EIP155, meaning that the contracts don't expect the chain-id as part of the RLP encode being signed.

This means that if we don't support pre-eip155 transactions (of legacy type) then we won't be able to deploy some of the contracts that use Nick's method to ensure the same address across different chains.

With type 2 transactions, the chain ID is included in the RLP encode but the v value is no longer relevant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that if we don't support pre-eip155 transactions (of legacy type) then we won't be able to deploy some of the contracts that use Nick's method to ensure the same address across different chains.

FWIW we don't have to do this hack since we have governance on Polkadot.

match (tx.chain_id, tx.r#type.as_ref()) {
(None, Some(super::Byte(TYPE_LEGACY))) => {},
(Some(chain_id), ..) =>
if chain_id != <T as Config>::ChainId::get().into() {
log::debug!(target: LOG_TARGET, "Invalid chain_id {chain_id:?}");
return Err(InvalidTransaction::Call);
},
(None, ..) => {
log::debug!(target: LOG_TARGET, "Invalid chain_id None");
return Err(InvalidTransaction::Call);
},
}

if effective_gas_price < base_fee {
Expand Down
88 changes: 88 additions & 0 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,92 @@ mod test {
_ => panic!("Expected the RuntimeCall::Contracts variant, got: {:?}", call),
}
}

#[test]
fn dry_run_contract_deployment_with_nick_method_works() {
// Arrange
let raw_transaction_bytes = alloy_core::hex!("0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470");

ExtBuilder::default().build().execute_with(|| {
let mut signed_transaction =
TransactionSigned::decode(raw_transaction_bytes.as_slice())
.expect("Invalid raw transaction bytes");
if let TransactionSigned::TransactionLegacySigned(ref mut legacy_transaction) =
signed_transaction
{
legacy_transaction.transaction_legacy_unsigned.gas =
U256::from_dec_str("3750815700000").unwrap();
}
let generic_transaction = GenericTransaction::from_signed(
signed_transaction.clone(),
Pallet::<Test>::evm_base_fee(),
None,
);

let deployer = signed_transaction
.recover_eth_address()
.expect("Failed to recover the deployer account");
Pallet::<Test>::set_evm_balance(
&deployer,
U256::from_dec_str("10000000000000000000").unwrap(),
)
.expect("Setting balance failed");

// Act
let dry_run_result = Pallet::<Test>::dry_run_eth_transact(
generic_transaction.clone(),
Default::default(),
);

// Assert
assert!(
generic_transaction.chain_id.is_none(),
"Chain Id in the generic transaction is not None"
);
let _dry_run_result = dry_run_result.expect("Dry run failed");
})
}

#[test]
fn contract_deployment_with_nick_method_works() {
// Arrange
let raw_transaction_bytes = alloy_core::hex!("0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470");

let mut signed_transaction = TransactionSigned::decode(raw_transaction_bytes.as_slice())
.expect("Invalid raw transaction bytes");
if let TransactionSigned::TransactionLegacySigned(ref mut legacy_transaction) =
signed_transaction
{
legacy_transaction.transaction_legacy_unsigned.gas =
U256::from_dec_str("3750815700000").unwrap();
}
let generic_transaction = GenericTransaction::from_signed(
signed_transaction.clone(),
ExtBuilder::default().build().execute_with(|| Pallet::<Test>::evm_base_fee()),
None,
);

let unchecked_extrinsic_builder = UncheckedExtrinsicBuilder {
tx: generic_transaction,
before_validate: None,
dry_run: None,
};

// Act
let eth_transact_result = unchecked_extrinsic_builder.check();

// Assert
let (
_encoded_len,
_function,
_extra,
generic_transaction,
_gas_required,
_signed_transaction,
) = eth_transact_result.expect("eth_transact failed");
assert!(
generic_transaction.chain_id.is_none(),
"Chain Id in the generic transaction is not None"
);
}
}
Loading