Skip to content

Conversation

@lexnv
Copy link
Contributor

@lexnv lexnv commented Aug 19, 2025

This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks from storage via runtime APIs and establishes proper Ethereum ↔ Substrate block hash mappings.

Key Changes

Block Hash Mapping Infrastructure

  • New database table: eth_to_substrate_blocks maps Ethereum block hashes to Substrate block hashes and block numbers
  • Bidirectional lookups: Support for both ETH→Substrate and Substrate→ETH hash resolution with backward compatibility fallbacks
  • Block pruning: Updated to remove stale mappings alongside transaction and log data

Pallet Changes

  • Genesis block initialization: Added block_storage::on_finalize_build_eth_block() call in BuildGenesisConfig to properly build and store block 0

Testing

  • Added comprehensive tests for block hash mapping operations
  • Ethereum vs Substrate hash resolution tests
  • Fork handling in block pruning tests
  • Log filtering with Ethereum block hash tests
  • TransactionInfo deserialization from JSON Value tests

Implementation Details

The implementation uses a runtime API approach where the RPC layer queries the runtime for Ethereum blocks and hashes, which are then mapped to Substrate block hashes in the local SQLite database. This provides:

  1. Backward compatibility: Falls back to treating hashes as Substrate hashes when no mapping exists
  2. Efficient lookups: Database indices on both Ethereum and Substrate block hashes
  3. Automatic cleanup: Block mappings are pruned alongside transaction and log data
  4. Genesis block handling: Block 0 is built during genesis using the block storage infrastructure

Builds upon: #9418
Part of: paritytech/contract-issues#139

@lexnv lexnv self-assigned this Aug 19, 2025
@lexnv lexnv requested review from athei, lrubasze and pgherveou August 19, 2025 10:29
Copy link
Contributor

@lrubasze lrubasze left a comment

Choose a reason for hiding this comment

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

Really nice work don here!

lexnv added 24 commits August 22, 2025 11:48
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
…lock-storage

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Contributor

@pgherveou pgherveou left a comment

Choose a reason for hiding this comment

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

looks good, thanks can you clean up the left over println, maybe replace that with log::trace!(target: LOG_TARGET if needed

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/18750174819
Failed job name: test-linux-stable-no-try-runtime

@lrubasze lrubasze added this pull request to the merge queue Oct 24, 2025
Merged via the queue into master with commit 47c4bbc Oct 24, 2025
266 of 268 checks passed
@lrubasze lrubasze deleted the lexnv/revive-rpc-adjustment branch October 24, 2025 08:00
sistemd added a commit that referenced this pull request Nov 24, 2025
This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks
from storage via runtime APIs and establishes proper Ethereum ↔
Substrate block hash mappings.

## Key Changes

### Block Hash Mapping Infrastructure
- **New database table**: `eth_to_substrate_blocks` maps Ethereum block
hashes to Substrate block hashes and block numbers
- **Bidirectional lookups**: Support for both ETH→Substrate and
Substrate→ETH hash resolution with backward compatibility fallbacks
- **Block pruning**: Updated to remove stale mappings alongside
transaction and log data

### Pallet Changes

- **Genesis block initialization**: Added
`block_storage::on_finalize_build_eth_block()` call in
`BuildGenesisConfig` to properly build and store block 0

## Testing

- Added comprehensive tests for block hash mapping operations
- Ethereum vs Substrate hash resolution tests
- Fork handling in block pruning tests
- Log filtering with Ethereum block hash tests
- TransactionInfo deserialization from JSON Value tests

## Implementation Details

The implementation uses a **runtime API approach** where the RPC layer
queries the runtime for Ethereum blocks and hashes, which are then
mapped to Substrate block hashes in the local SQLite database. This
provides:

1. **Backward compatibility**: Falls back to treating hashes as
Substrate hashes when no mapping exists
2. **Efficient lookups**: Database indices on both Ethereum and
Substrate block hashes
3. **Automatic cleanup**: Block mappings are pruned alongside
transaction and log data
4. **Genesis block handling**: Block 0 is built during genesis using the
block storage infrastructure

Builds upon: #9418
Part of: paritytech/contract-issues#139

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>
TorstenStueber pushed a commit that referenced this pull request Dec 4, 2025
This is a fix for the fact that `exec::Key` is exposed from within
`pallet_revive::tracing::Tracing` interface, but not from the crate
itself making custom tracers effectively unimplementable outside said
crate.

In my case it's useful for implementing custom tracers for integration
with `foundry`

Requires no downstream changes

This is a fix for the fact that `exec::Key` is exposed from within
`pallet_revive::tracing::Tracing` interface, but not from the crate
itself making custom tracers effectively unimplementable outside said
crate.

see here for one of the methods: [`exec::Key` exposed to the
implementor, despite not being exported by the
`crate`](https://github.com/paritytech/polkadot-sdk/blob/pkhry/expose_key_pallet_revive/substrate/frame/revive/src/tracing.rs#L68)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Move `to_account_id` host function to `System` pre-compile (#9455)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

cc @athei @pgherveou

---------

Co-authored-by: xermicus <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Move `blake2_128` host function to `System` pre-compile (#9454)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

I'm splitting some of the host function migrations into separate PRs, as
there are sometimes refactorings involved and this should make reviewing
easier.

cc @athei @pgherveou

[revive] move existing files to prepare evm backend introduction (#9501)

- Move exisiting files in pallet-revive to accomodate the upcoming EVM
backend
- Add solc/resolc compilation feature for fixtures
- Add `fn is_pvm` to later distinguish between pvm / evm bytecode

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

align eth-rpc response with geth (#9177)

- Update some serde encoding for eth-rpc to match serialization behavior
of Geth
- Add support for serializing / deserializing EIP7702 tx types
- Disable transaction type we don't support yet in
try_ino_unchecked_extrinsics

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[revive] revm backend (#9285)

Initial EVM support via the REVM crate to create a dual-VM system that
can execute both PolkaVM and EVM

- Added `AllowEVMBytecode: Get<bool>` to the config to enable/disable
EVM call and instantiation
- CodeInfo has been updated to add the type of bytecode (EVM / PVM).
`migration/v2.rs` takes care of migrating existing storages
- The CodeUploadDeposit is not held by a pallet account instead of being
held on the uploader, It's automatically refunded when the refcount
drops to 0 and the code is removed.
- The basic flow of uploading an EVM contract and running it should work
- instructions are copied and adapted from REVM they should be ignored
in this PR and reviewed in follow-up PR
(**reviewers** please ignore
`substrate/frame/revive/src/vm/evm/instructions/*` for now)

A basic instruction looks like this:

```rust
pub fn coinbase<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
	gas_legacy!(context.interpreter, revm_gas::BASE);
	push!(context.interpreter, context.host.beneficiary().into_word().into());
}
```

All instructions have been copied from `REVM` and updated with generic
types for pallet-revive. Two main changes are required:

Replace REVM gas calls with existing benchmarks where available:

```diff
- gas_legacy!(context.interpreter, revm_gas::BASE);
+ gas!(context.interpreter, RuntimeCosts::BlockAuthor);
```

Replace `context.host` calls with `context.extend` (set to `&mut Ext`):

```diff
- push!(context.interpreter, context.host.beneficiary().into_word().into());
+ let coinbase: Address = context.interpreter.extend.block_author().unwrap_or_default().0.into();
+ push!(context.interpreter, coinbase.into_word().into());
```

- For cases without existing benchmarks (e.g arithmetic, bitwise) , we
will keep `gas_legacy!`
- The u64 gas value are multiplied by a base cost benchmarked by
`evm_opcode`

- ### Important Rules
- All calls to `context.host` should be removed (initialized to default
values)
- All calls to `context.interpreter.gas` should be removed (except
`gas.memory` handled by `resize_memory!` macro)
- See `block_number` implementation as a reference example

The following instructions in src/vm/evm/instructions/** need to be
updated

We probably don't need to touch these implementations here, they use the
gas_legacy! macro to charge a low gas value that will be scaled with our
gas_to_weight benchmark. The only thing needed here are tests that
exercise these instructions

<details>

- [ ] **add**
- [ ] **mul**
- [ ] **sub**
- [ ] **div**
- [ ] **sdiv**
- [ ] **rem**
- [ ] **smod**
- [ ] **addmod**
- [ ] **mulmod**
- [ ] **exp**
- [ ] **signextend**

- [ ] **lt**
- [ ] **gt**
- [ ] **slt**
- [ ] **sgt**
- [ ] **eq**
- [ ] **iszero**
- [ ] **bitand**
- [ ] **bitor**
- [ ] **bitxor**
- [ ] **not**
- [ ] **byte**
- [ ] **shl**
- [ ] **shr**
- [ ] **sar**
- [ ] **clz**

- [ ] **jump**
- [ ] **jumpi**
- [ ] **jumpdest**
- [ ] **pc**
- [ ] **stop**
- [ ] **ret**
- [ ] **revert**
- [ ] **invalid**

- [ ] **mload**
- [ ] **mstore**
- [ ] **mstore8**
- [ ] **msize**
- [ ] **mcopy**

- [ ] **pop**
- [ ] **push0**
- [ ] **push**
- [ ] **dup**
- [ ] **swap**

</details>

These instructions should be updated from using gas_legacy! to gas! with
the appropriate RuntimeCost, the returned value need to be pulled from
our `&mut Ext` ctx.interpreter.extend instead of the host or input
context value

<details>

- [x] **block_number**
- [ ] **coinbase**
- [ ] **timestamp**
- [ ] **difficulty**
- [ ] **gaslimit**
- [ ] **chainid**
- [ ] **basefee**
- [ ] **blob_basefee**

- [ ] **balance**
- [ ] **extcodesize**
- [ ] **extcodecopy**
- [ ] **extcodehash**
- [ ] **blockhash**
- [ ] **sload**
- [ ] **sstore**
- [ ] **tload**
- [ ] **tstore**
- [ ] **log**
- [ ] **selfdestruct**
- [ ] **selfbalance**

- [ ] **keccak256**
- [ ] **address**
- [ ] **caller**
- [ ] **callvalue**
- [ ] **calldataload**
- [ ] **calldatasize**
- [ ] **calldatacopy**
- [ ] **codesize**
- [ ] **codecopy**
- [ ] **returndatasize**
- [ ] **returndatacopy**
- [ ] **gas**

- [ ] **origin**
- [ ] **gasprice**
- [ ] **blob_hash**

</details>

These instructions should be updated,, that's where I expect the most
code change in the instruction implementation.
See how it's done in vm/pvm module, the final result should look pretty
similar to what we are doing there with the addition of custom gas_limit
calculation that works with our gas model.

see also example code here https://github.com/paritytech/revm_example

<details>

- [ ] **create**
- [ ] **create**
- [ ] **call**
- [ ] **call_code**
- [ ] **delegate_call**
- [ ] **static_call**

</details>

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>

[pallet-revive] Expose `AccountInfo` and `ContractInfo` in the public interface (#9606)

Part of https://github.com/paritytech/polkadot-sdk/issues/9553
See https://github.com/paritytech/foundry-polkadot/issues/276

Exposes revive types to use in foundry-polkadot project.

Should not affect downstream projects.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] EVM backend: Implement tx, block system and call stack instructions (#9414)

This PR is part of the road to EVM.
- Implement call and create frames, allowing to call and instantiate
other contracts.
- Implement support for tx info, block info, system and contract
opcodes.
- The `InstructionResult` <-> `ExecError` conversion functions.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>

[pallet-revive] Update genesis config (#9557)

Update pallet-revive Genesis config
Make it possible to define accounts (contracts or EOA) that we want to
setup at Genesis

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>

[pallet-revive] Add `Pallet::set_evm_balance` (#9617)

Part of https://github.com/paritytech/polkadot-sdk/issues/9553
See https://github.com/paritytech/foundry-polkadot/issues/273

Adds a balance setter in EVM.

Should not affect downstream projects.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

[pallet-revive] EVM backend: implement various missing opcodes (#9385)

* [x] system (other PR, no tests)
* [x] block_info (other PR)
* [x] contract (other PR)
* [x] tx_info (other PR)
* [x] arithmetic
* [x] bitwise
* [x] i256 (these are not opcodes so will not test)
* [x] host (except `log()`)
* [x] memory
* [x] control (except `pc()`)
* [x] macros (these are not opcodes so will not test)
* [x] utility (these are not opcodes so will not test)
* [x] stack

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Sebastian Miasojed <sebastian.miasojed@parity.io>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sebastian Miasojed <s.miasojed@gmail.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Cyon <Sajjon@users.noreply.github.com>
Co-authored-by: Alexander Cyon <alex.cyon@parity.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Dmitry Sinyavin <dmitry.sinyavin@parity.io>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: Serban Iorga <serban@parity.io>

[pallet-revive] fix GAS_PRICE (#9679)

Currently submitting a transactio to the dev-node or kitchensink will
trigger an error when you try to submit a transaction trhough cast (or
anything using alloy) as the block gas limit on these runtime is greater
than u64::max.

This bump the GAS_PRICE to fix this issue, this will eventually be
superseeded by the new gas model

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

[pallet-revive] Properly convert `Ext::minimum_balance` value to `U256` (#9705)

The value is just cast to `U256` here, without applying the actual
conversion factor (`NativeToEthRatio`).

There are some tests that apply the same easy conversion via `Into`,
without applying the conversion factor. Those tests still succeed, but
you might want to go through those usages to not confuse people reading
the code.

@athei @pgherveou

added trace logging in EVM interpreter loop (#9561)

Added trace logging for each instruction to evm::run function.
solves https://github.com/paritytech/polkadot-sdk/issues/9575

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>

[pallet-revive] fix CodeInfo owner (#9744)

Fix CodeInfo owner, it should always be set to the origin of the
transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix tracing collect (#9736)

Tracing fixes:

- collect_trace take `self` instead of `&mut self`, to avoid reusing the
tracer state when tracing multiple transactions in a block.
- Fix issues related to call traces and the onlyTopCall config option

Fix
https://github.com/paritytech/contract-issues/issues/156https://github.com/paritytech/contract-issues/issues/156

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive-rpc: use generic RpcClient instead of ReconnectingRpcClient (#9701)

This will enable more flexible usage of the revive RPC as a library.

Needed so that we can reuse it with an in-memory RPC client for
anvil-polkadot:
https://github.com/paritytech/foundry-polkadot/issues/238

[pallet-revive] Migrate various getters to `System` pre-compile (#9517)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

Migrates:
* `own_code_hash`
* `caller_is_origin`
* `caller_is_root`
* `weight_left`
* `minimum_balance`

There are some minor other fixes in there (removing leftovers from
deprecating chain extensions, stabilizing `block_hash` in overlooked
crates, etc.).

cc @athei @pgherveou

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] fix salt endianness  (#9771)

fix <https://github.com/paritytech/polkadot-sdk/issues/9769>

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: add account_id and new_balance_with_dust runtime APIs  (#9683)

Needed for https://github.com/paritytech/foundry-polkadot/issues/240

revive-fixtures: Provide an env variable to disable compilation (#9791)

Right now `pallet-revive-fixtures` is always trying to build the
fixtures. It requires `solc` and other stuff for compilation. If you are
not requiring the fixtures, because you for example only run `cargo
check`, this pull request introduces `SKIP_PALLET_REVIVE_FIXTURES`. When
the environment variable is set, the compilation of the fixtures is
skipped. It will set the fixtures to `None` and they will panic at
runtime.

EIP-3607 added check to make sure a contract account cannot transfer funds as an EOA account (#9717)

fixes https://github.com/paritytech/polkadot-sdk/issues/9570

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Add set_storage/set_storage_var_key methods (#9759)

... to be used in polkadot foundry to make sure EVM state is in sync
with pallet-revive state.

Fixes: https://github.com/paritytech/foundry-polkadot/issues/275

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

bugfix revm set_storage gas cost (#9823)

Fixes bug in revm gasmetering where the initial charge was less than the
adjusted charge.

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet revive evm backend add tests for cross vm contract calls (#9768)

fixes https://github.com/paritytech/polkadot-sdk/issues/9576

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] update rpc metadata (#9853)

Update eth-rpc metadata files

the metadata should have been updated here
https://github.com/paritytech/polkadot-sdk/pull/9759
where a new variant was added to an enum used by the runtime api

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: allow changing immutables (#9801)

... to be used in polkadot foundry to make sure EVM state is in sync
with pallet-revive state.

Fixes: https://github.com/paritytech/foundry-polkadot/issues/277

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet_transaction_payment]: Share withdrawn tx fee credit with other pallets (#9780)

Replaces https://github.com/paritytech/polkadot-sdk/pull/9590.

The audit of #9590 showed that holding the txfee as held balance and
especially playing around with `providers` causes a lot of troubles.

This PR is a much lighter change. It keeps the original withdraw/deposit
pattern. It simply stores the withdrawn `Credit` and allows other
pallets to withdraw from it.

It is also better in terms of performance since all tx signers share a
single storage item (instead of a named hold per account).

---------

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>

`pallet-assets`: extract precompiles to a separate crate (#9796)

closes #9434

Assets pallet includes `pallet-revive` precompiles and subsequently pull
a lot of EVM related dependencies by default. This forces downstream
users that only want `pallet-assets` functionality to pull unrelated
dependencies and causes confusion (why do we have bunch of ethereum
crates in the dependency tree of `pallet-assets`?). This extracts
precompiles into its own crate

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <git@kchr.de>

pallet-revive: add custom addr recovery logic in `ReceiptExtractor` (#9878)

`ReceiptExtractor` parses blocks and associated transactions in
pallet-revive-eth-rpc and is useful for a range of Ethereum node RPCs.
When the transactions are impersonated, they are based on a fake
signature, which can't be used with the production eth address recovery
logic. The recovery logic must be customised in cases where we
impersonate transactions, so this PR adds a custom function on the
`ReceiptExtractor` which can be used to customize address recovery.

Developers using pallet-revive-eth-rpc as a lib should instantiate the
`ReceiptExtractor` with the custom constructor if impersonation usecases
must be supported.

Relevant in context of
https://github.com/paritytech/foundry-polkadot/issues/242, to implement
anvil-polkadot impersonation.

---------

Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

replace forloop solc fixture type with test-case macro (#9841)

For all tests of revm instructions replaced `for fixture_type` with
test-case macro

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Move revive fixtures into release directory (#9670)

https://github.com/paritytech/polkadot-sdk/pull/8980 did fix the
fellowship CI but it triggers a rebuild of the fixtures every single
time you run tests. Annoying during development.

Instead of rebuilding, we just move the fixtures into the
`target/release` directory where it should be cached by the fellowship
CI.

Verifying that it works here:
https://github.com/polkadot-fellows/runtimes/pull/891

Why: Re-running when the output dir changes will make it re-run every
time. Since every run changes the output dir.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Rework gas mapping (#9803)

Replacement of https://github.com/paritytech/polkadot-sdk/pull/9740.

Build on top of the new tx payment changes:
https://github.com/paritytech/polkadot-sdk/pull/9780

Started a new PR because due to the rebase on top of the new tx payment
changes this PR is substantially different and I don't want to
invalidate the existing comments on
https://github.com/paritytech/polkadot-sdk/pull/9740 which are not
implemented, yet.

This will change the weight to eth fee mapping according to [this
model](https://shade-verse-e97.notion.site/Gas-Mapping-Challenges-Revised-26c8532a7ab580db8222c2ce3023669e).

This only changes the estimate returned from the dry run and how the
weights are derived from an ethereum transaction. It does not change how
contracts observe the gas. This will be done in a follow up. More
specifically:

1. The `GAS` opcode should return the new gas. As of right now it
returns `ref_time.`
2. The `*_CALL` opcodes should use the passed `gas` parameter and decode
it into `Weight`. As of right now the parameter is ignored.

That said, even without those follow ups this PR should fix all
`InvalidTransaction` errors we are observing.

We should add a configurable divisor so that the gas_price is always at
least some gwei. That makes it easier to input the values.

---------

Signed-off-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet-revive: Bump PolkaVM (#9928)

Bumped `polkavm` to the latest version. No semantic changes in that
update.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] revm refactor (#9818)

Refactor REVM implementation in `pallet-revive`

This PR removes technical debt and eliminates tight coupling to specific
REVM versions, facilitating integration with other projects (e.g.,
Foundry). After this refactoring, we primarily depend only on REVM's
[`Bytecode`](https://docs.rs/revm/latest/revm/bytecode/struct.Bytecode.html)
struct.

Most of REVM's generic type system and trait abstractions are unused or
had to be ignored to prevent bugs. Interactions with the host in
pallet-revive are handled through the `Ext` trait, making REVM's other
abstractions unnecessary or potentially harmful.

Unused REVM abstractions included:
- **Host trait**: Unused in the pallet, we relied on the `DummyHost`
default mocked implementation
- **Gas field**: Unused, the pallet uses its own gas accounting system
- **Methods from `InputsTr`**: Unused most methods had panic
implementations since they couldn't be relied upon
- **Spec**: Unused: We only maintain the latest fork for each runtime

This refactor introduces:
- **Interpreter**: Simplified struct containing only the fields actually
needed
- **Stack**: Simplified implementation using `sp_core::*` instead of
`alloy_core::primitives::*` for better integration with the rest of the
pallet
- **Memory**: Simplified implementation providing only the methods
actually needed
- **Instructions**:
- New instructions don't rely on macros and have a simplified signature:
`Fn(&mut interpreter) -> ControlFlow<Halt>`
- Removed function pointer table lookup for instructions in favor of
match statements,
- Unified gas charging: legacy u64 gas charging is now wrapped in
`EVMGas` that implements `Token<T>` to provide the associated weight
- Removed the `InterpreterAction`, this simplify the interpreter loop
to:
```rust
loop {
	let opcode = interpreter.bytecode.opcode();
	interpreter.bytecode.relative_jump(1);
	exec_instruction(interpreter, opcode)?;
}
```
- **Error handling**: Opcode that fail return Halt::Err(DispatchError),
this remove the need from converting between InstructionResult and
`ExecError` like we were previously doing and standardize errors
generated on both backends

---------

Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Allows setting evm balance for non-existing account (#9911)

Allows calling set_evm_balance for a non-existing account on
pallet-revive.
It is needed by foundry to inject EVM accounts.

pallet-revive: Fix dry run balance check logic (#9942)

Fix fault balance check logic during dry-run:

We should not enforce that the sender has enough balance for the fees in
case no `gas` is supplied.

cc @TorstenStueber

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Allow unlimited contract size in debug mode. (#9831)

Fixes https://github.com/paritytech/contract-issues/issues/167

The main changes in this PR are:

1. Added an associated type DebugEnabled
2. Introduced a DebugSettings struct with a single boolean field
3. Added a StorageValue: pub(crate) type DebugSettingsOf<T: Config> =
StorageValue<_, DebugSettings<T>, ValueQuery>;
4. Included debug_settings in the GenesisConfig
5. Added a unit test to verify that large EVM contracts can be
instantiated.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

pallet-revive update basefee instruction (#9945)

The base fee instruction now returns the proper base price instead of a
hard coded value.

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Migrate unstable storage host functions to `Storage` pre-compile (#9603)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

Introduces a new `Storage` pre-compile and migrates:
* `clear_storage`
* `take_storage`
* `contains_storage`

The new `Storage` pre-compile is introduced, as it requires implementing
the `BuiltinPrecompile::call_with_info` function, which cannot be
implemented together with `BuiltinPrecompile::call` (implemented by the
`System` pre-compile).

I've added the `sol_utils` as I (on admittedly quick glance) couldn't
find a crate that supports those encodings (Solidity's `bytes`) without
requiring an allocator.

cc @athei @pgherveou

---------

Co-authored-by: xermicus <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

Return unified gas for `gas_left` syscalls and opcodes (#9968)

In https://github.com/paritytech/polkadot-sdk/pull/9803 we introduced
the new gas mapping. However, when contracts are querying the remaining
gas we still returned the `ref_time`. This PR changes that.

- Added a new `Stack::gas_left` function that calculates the remaining
gas as eth gas that matches the gas passed in the transaction. It
supports both the `eth_` and non `eth_` flavors of dispatchables.
- Changed the PVM syscall `ref_time_left` to return the new unified gas.
- Changes the EVM `GAS` opcode to return the new unified gas
- When calculating the consumed storage we now take into account what
was charged during the current frame
- Removed `storage_deposit_limit` from `eth_*` dispatchables. It is
always uncapped in this case and the overall limit is conveyed using the
tx credit.

Now that we can return the proper remaining gas that also includes the
storage deposit we can change the EVM `call` instruction next to take
the passed `gas` into account. Since the unified gas takes both the
txfee and the deposit into account it will be able to limit both
effectively.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

[pallet-revive] dev-node constant fee multiplier (#9939)

This will let us have stable gas cost (as long as the state of the dev
net does not change)

In mainnet neither polkadot, nor EVM chains can guarantee stable gas
since the state of the blockchain can change between two dry runs, but I
would argue that we are better off if we have stable gas cost in testing
environments as that is the standard on EVM devnet

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix exp overflow (#9991)

Update arithmetic tests, and fix potential overflow

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

 Wait for transaction receipt if instant seal is enabled (#9914)

Fixes https://github.com/paritytech/contract-issues/issues/165

The main changes in this PR are:

1. Add a new API to revive-dev-node to check whether the node has
instant seal enabled.
2. Add a new debug API to eth-rpc to check whether the node has instant
seal enabled. (optional)
3. Query and cache the node’s instant seal status during eth-rpc
initialization.
4. If instant seal is enabled, wait for the transaction receipt to be
available

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Implement the consume_all_gas syscall (#9997)

This PR implements a new API `consume_all_gas` which is required for
100% EVM `INVALID` opcode compatibility.

Since ceding of all remaining gas is handled in the EVM interpreter, I
decided to not add a return flag but make this a dedicated syscall for
consistency instead.

Didn't implement a benchmark since the first (and only) thing this does
is consuming all remaining gas anyways.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

`pallet-xcm`: extract precompiles to a separate crate (#9985)

This PR extracts the XCM precompile from `pallet-xcm` into a new
standalone crate `pallet-xcm-precompiles` to resolve an unwanted
dependency issue. Previously, the XCM precompile was implemented
directly in `pallet-xcm/src/precompiles.rs`, which required `pallet-xcm`
to depend on `pallet-revive`, introducing it as a transitive dependency
for all parachains using `pallet-xcm`.

Closes #9955

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix subxt submit & add debug statments (#10016)

- Fix subxt submit by default it's using
`author_submitAndWatchExtrinsic` even though we just want to fire and
forget
- Add debug instructions to log the signer & nonce of new eth
transactions when the node validate the transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Lower the deposit costs for child trie items (#10027)

Fixes https://github.com/paritytech/polkadot-sdk/issues/9246

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Fix incorrect `block.gaslimit` (#10026)

Fixes https://github.com/paritytech/contract-issues/issues/112

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

frame/revive: ETH block storage (#9418)

This PR constructs the Ethereum block in the following way:
- events (logs) are captured via an `environmental!` variable to reduce
reliance on pallet storage
- A maximum of 512 events is allowed per transaction, with the size of
an event capped to `self.ext.max_value_size()`
- A memory-efficient intermediate block builder is deserialized and
serialized back to the pallet storage
- The intermediate block builder builds the transaction and event root
hashes using low level RLP encoding primitives to achieve around 90%
pallet storage optimization
- For more details, see
https://github.com/paritytech/polkadot-sdk/pull/9764
- A fixup is included for 7702 transaction rlp
serialization/deserialization is added to ensure we can build the
Ethereum block hash from live Ethereum blocks.
- The maximum `CALL_PARAMS_MAX_SIZE` is increased to 512 to 244 to
accommodate the transaction added to the Eth call

This PR also includes benchmarking:
- https://github.com/paritytech/polkadot-sdk/pull/9496

- pallet storage testing and capturing of events / transactions are
added at `tests/block_hash.rs`
- incremental block storage is tested in `evm/block_hash.rs`, which
ensures RLP encoding / hash builder and identical hashes from live
ethereum blocks
- tested via RPC work

- https://github.com/paritytech/polkadot-sdk/pull/9512
- https://github.com/paritytech/polkadot-sdk/pull/9616
- https://github.com/paritytech/polkadot-sdk/pull/9452

Builds upon https://github.com/paritytech/polkadot-sdk/pull/9413

Part of: https://github.com/paritytech/contract-issues/issues/139

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] improve revive genesis config (#9988)

- Update test to make sure contracts created at genesis are callable
- make sure that contracts are brought to existence by minting e.d first

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

added baltathar, charleth, dorothy, and ethan to eth-rpc and revive-d… (#10041)

adds more funded accounts to eth-rpc and dev-node

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Increase event sizes (#10047)

Fixes https://github.com/paritytech/contract-issues/issues/140

This increases the maximum event payload size from 416 bytes to 64k.
Since https://github.com/paritytech/polkadot-sdk/pull/9418 we charge
some additional weight per byte of event payload. This makes it possible
to raise the limit while staying within our memory envelope. This
artificial weight will add 18us of weight to a maximum sized event.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: when a dry run simulates contract deployment, return the execution result data. (#10032)

Fixes https://github.com/paritytech/contract-issues/issues/177

Expose the deployed contract's runtime bytecode in eth_call responses
during simulated contract creation.

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.

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

eth-rpc add trace logs (#10065)

Add extra tracing logs for estimate_gas and send_raw_transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

pallet_revive: Raise the MaxEthExtrinsicWeight (#10089)

Fixes https://github.com/paritytech/contract-issues/issues/194

Factory extrinsics do need more weight. It is fine to raise them to
almost the full max extrinsic weight since this is still lower than the
block weight.

Also improving the error reporting during the dry run in case an
extrinsic hits this limit. No more `OutOfGas` but a more descriptive
error of how much it is overweight.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

precompiles: Enforce state mutability (#10080)

`pallet-assets-precompile`, `pallet-xcm-precompiles` and revive builtin
precompile implementations currently violate [Solidity state
mutability](https://docs.soliditylang.org/en/latest/grammar.html#syntax-rule-SolidityParser.stateMutability),
potentially introducing a new attack vector. This PR implements
corresponding checks at the function dispatch.

Could be enforced in `pallet-revive`, however:
1. Adding something like a `const MUTATES: bool` to the `Precompile`
trait won't help because whether the call is mutating or not depends on
the [Solidity function
selector.](https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector).
2. Alloy, which we are using to parse the interface definitions prior to
calling precompile implementations, doesn't provide a mapping from
function selector to its mutability
[modifier](https://docs.soliditylang.org/en/latest/cheatsheet.html#modifiers).

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive: fix alloy-consensus dependency (#10090)

Needed in order to update foundry-polkadot to the latest master:
https://github.com/paritytech/foundry-polkadot/pull/352

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Enforce single-state txpool for revive-dev-node (#10106)

Use single-state txpool for dev-node when instant-seal is selected

see https://github.com/paritytech/polkadot-sdk/issues/10104

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: Add ExportChainSpec command to revive-dev-node (#10020)

Add the `export-chain-spec` command to the revive-dev-node.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive/rpc: Adjust the RPC to utilize the ETH block from storage (#9512)

This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks
from storage via runtime APIs and establishes proper Ethereum ↔
Substrate block hash mappings.

- **New database table**: `eth_to_substrate_blocks` maps Ethereum block
hashes to Substrate block hashes and block numbers
- **Bidirectional lookups**: Support for both ETH→Substrate and
Substrate→ETH hash resolution with backward compatibility fallbacks
- **Block pruning**: Updated to remove stale mappings alongside
transaction and log data

- **Genesis block initialization**: Added
`block_storage::on_finalize_build_eth_block()` call in
`BuildGenesisConfig` to properly build and store block 0

- Added comprehensive tests for block hash mapping operations
- Ethereum vs Substrate hash resolution tests
- Fork handling in block pruning tests
- Log filtering with Ethereum block hash tests
- TransactionInfo deserialization from JSON Value tests

The implementation uses a **runtime API approach** where the RPC layer
queries the runtime for Ethereum blocks and hashes, which are then
mapped to Substrate block hashes in the local SQLite database. This
provides:

1. **Backward compatibility**: Falls back to treating hashes as
Substrate hashes when no mapping exists
2. **Efficient lookups**: Database indices on both Ethereum and
Substrate block hashes
3. **Automatic cleanup**: Block mappings are pruned alongside
transaction and log data
4. **Genesis block handling**: Block 0 is built during genesis using the
block storage infrastructure

Builds upon: https://github.com/paritytech/polkadot-sdk/pull/9418
Part of: https://github.com/paritytech/contract-issues/issues/139

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

revive-dev-node enforce --dev (#10109)

enforce --dev and default --log in revive-dev-node

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Change bahaviour of contract termination in accordance with EIP-6780 (#9699)

fixes https://github.com/paritytech/polkadot-sdk/issues/9621

Behavior of `terminate` is changed in accordance with EIP-6780 (and EVM
in general):
- `terminate` only deletes the code from storage if it is called in the
same transaction the contract was created.
- `terminate` does not destroy the contract instantly. The contract is
registered for destruction, which happens at the end of the transaction.

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Sebastian Miasojed <sebastian.miasojed@parity.io>
Co-authored-by: Sebastian Miasojed <s.miasojed@gmail.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Only enforce EIP-3607 for dispatchables (#10100)

The EIP states that contract addresses cannot be the origin of a
transaction. However, we are enforcing this rule for all contract
execution (i.e all public function on the pallet). This is a problem for
code that uses `pallet_revive` and explicitly wants to allow this.

This PR now only enforces this check for dispatchables so that all the
`bare_*` functions are unaffected.

As a drive-by a regrouped the functions on the `Pallet` so that the
public functions are no longer interleaved with the private ones. This
got mixed up when we resolved some merge conflicts.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add interface to implement mocks and pranks (#9909)

Needed for: https://github.com/paritytech/foundry-polkadot/pull/334.

In foundry-polkadot we need the ability to be able to manipulate the
`msg.sender` and the `tx.origin` that a solidity contract sees cheatcode
documentation, plus the ability to mock calls and functions.

Currently all create/call methods use the `bare_instantiate`/`bare_call`
to run things in pallet-revive, the caller then normally gets set
automatically, based on what is the call stack, but for `forge test` we
need to be able to manipulate, so that we can set it to custom values.

Additionally, for delegate_call, bare_call is used, so there is no way
to specify we are dealing with a delegate call, so the call is not
working correcly.

For both this paths, we need a way to inject this information into the
execution environment, hence I added an optional hooks interface that we
implement from foundry cheatcodes for prank and mock functionality.

- [x] Add tests to make sure the hooks functionality does not regress.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[revive] Receipts should include failed tx (#10120)

The current implementation incorrectly accumulates receipts in storage
to compute the `receipts_root`.
However, when an extrinsic fails, all storage changes are reverted
causing the receipts to be lost.

This PR updates the handling of Ethereum transactions so that they
always succeed. The transaction logic is now wrapped in a top-level
storage transaction that rolls back all state changes on failure while
still producing a valid receipt.

A new event `EthExtrinsicRevert` is emitted when an eth transaction
reverts.
eth-rpc uses this event to set the correct receipt status.

This event also serves as a replacement for ExtrinsicFailed to make
debugging failed Ethereum transactions easier in tools like Polkadot.js.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

anvil / eth-rpc - fix subscription race (#10146)

fix
https://github.com/paritytech/polkadot-sdk/issues/10139#issuecomment-3456077366

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alin Dima <alin@parity.io>

pallet_revive: Improve logging (#10157)

Just added some more information to the log output during dry_run and
transaction creation. This was helpful when debugging if the correct gas
was passed in by the client.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: make contract reverted error message more verbose (#10168)

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive-eth-rpc: derive Encode/Decode for subxt-generated types (#10169)

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive_dev_node: Always increment the timestamp by at least one second (#10160)

Fixes https://github.com/paritytech/contract-issues/issues/191

cc @albertov19

The instant seal introduces a race condition. Blocks can be build faster
than the timestamp resolution of Ethereum. Eth timestamps are only one
second granularity. If we build blocks faster it can happen that the
timestamp delta between them is zero. This is not allowed. We have to
make sure that in instant seal two blocks don't return the same
timestamp.

This PR does that by always incrementing the timestamp by at least one
second. Note that this is a dev-node only change. Production chains
won't have this problem as long as the block time is larger than 1
second.

Yes, it will produce timestamps in the future. But this seems to be the
lesser evil for this dev node. Time is subjective. But the rule to not
return duplicate timestamps is dependent on.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Add upload evm code function (#10129)

EVM Runtime Code Upload for Foundry Integration
This feature enables direct upload of EVM runtime bytecode (deployed
contract code without constructor) to the pallet-revive, supporting
Foundry's code migration functionality between REVM and pallet-revive
execution environments.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive-eth-rpc: fix blocks pruning (#10175)

We need to call prune_blocks before the insertion process.
Otherwise, if we get a fork, we won't be able to insert it into the DB
because it already exists there. In reality, we want the other fork to
be pruned instead.

Moreover, once we do get a fork we need to prune all the other
subsequent blocks of the old fork

Return the correct block difficulty from the eth-rpc (#10186)

This PR fixes an issue in the eth-rpc/pallet-revive that was causing it
to return an incorrect value for the block's difficulty or prevrandao.

In the VM/interpreter implementation we use a constant for the block
difficulty. However, the eth block construction side was unaware of this
constant being used and therefore the RPC was always returning a block
difficulty of zero.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive: Fix dust & child contract calls (#10192)

When transferring to self we should just return early as it's a noop.
Not doing so cause bug in `transfer_with_dust`

as we do
```
from.dust -= from.dust
to.dust += to.dust
```

We end up with a value of dust - planck (that we burnt from to create
dust amount) on the account

fix https://github.com/paritytech/contract-issues/issues/211

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive fix reported gas used (#10148)

Fix `gas_used` calculation introduced in #9418 to use the actual gas
instead of just `ref_time`.

With these changes we now guarantee that `tx_cost = effective_gas_price
* gas`.
Note that since we compute gas as `fee / gas_price`, this can lead to
rounding errors when the chain uses `SlowAdjustingFeeUpdate` (i.e. the
fee is not a multiple of the gas price).
The changes in this PR ensure the fee still matches by burning the
rounding remainder.

This PR also fixes how the actual fee is computed and introduces a new
`compute_actual_fee` in `Config::FeeInfo`.
The previous fee calculation was skipping the `extension_weight` in the
fee calculation.

The updated tests ensure that the tx cost reported in the receipt
matches the fees deducted from the user account:

https://github.com/paritytech/evm-test-suite/blob/460b2c9aa3a3019d3508bb5a34a2498ea86035ff/src/gas.test.ts?plain=1#L31-L61

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[v2] pallet-revive: support uploading EVM bytecode via upload_code extrinsic. (#10193)

Fixes https://github.com/paritytech/contract-issues/issues/182

Add support for EVM bytecode to the upload_code extrinsic.
Tests in issue https://github.com/paritytech/contract-issues/issues/182
send hardhat_setCode, which uses revive's upload_code API; this change
makes that flow accept and store the EVM bytecode using upload_code
extrinsic.

This PR deprecates PR:
https://github.com/paritytech/polkadot-sdk/pull/10095

Comment explaining test configuration requirements:
https://github.com/paritytech/polkadot-sdk/pull/10095#issuecomment-3456450460

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Notify when there is a new best block (#10220)

Modify the tx_notifier to send the block hash to the subscribers instead
of all transactions hashes.
Modify the send_raw_transaction to look for the transaction hash in the
transactions field of the evm block.

We need this changes in anvil-polkadot:
* https://github.com/paritytech/foundry-polkadot/pull/389
* to be able to implement some RPCs like : send_transaction_sync and the
filters logic

---------

Signed-off-by: Alexandru Cihodaru <alexandru.cihodaru@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Only fund new accounts with ED (#10233)

fixes https://github.com/paritytech/contract-issues/issues/179

In case an account is created by transferring funds to it, and after
that a contract is deployed to that account, it will receive the
existential deposit twice. This can be done using create2.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet_revive: Add dry-run timestamp override support (#10191)

This PR updates `pallet-revive` to **support overriding the block
timestamp during dry-run calls**.
The dry-run execution now uses the following configuration for
`eth_estimateGas` and `eth_call` when the block tag is `pending`:

```text
block.timestamp = max(rpc_timestamp, latest_block.timestamp + 1)
block.number = latest_block.number + 1
```

Fixes [#153](https://github.com/paritytech/contract-issues/issues/153),
[#205](https://github.com/paritytech/contract-issues/issues/205)

Downstream projects using the `ReviveApi::eth_transact` runtime API
should either provide a `timestamp` or pass `None`.

- Added dry run timestamp to `ExecConfig`.
- Added a new parameter to `ReviveApi::eth_transact` for passing the
current RPC timestamp.
- `eth_estimateGas` and `eth_call` with `pending` block tag will dry run
the transaction with the block timestamp set to `max(rpc_timestamp,
latest_block.timestamp + 1)` and block number set to
`latest_block.number + 1`.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

pallet_revive: use real storage when building the eth genesis block (#10225)

When building the eth genesis block, query the real storage items that
store the timestamp and block number instead of using the zeroed items.

If the chainspec does not customise these, they will remain zeroed.

However, anvil does customise these if requested by the user.
Needed in order to merge
https://github.com/paritytech/foundry-polkadot/pull/391

Remove outdated comment on Tracer Type (#10246)

Prestate tracer type is now supported

[pallet-revive] fix prestate tracer current address (#10239)

Fix prestate tracer not reporting the contract addresses properly.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Add eth_substrate_call extrinsic (#10159)

Fixes https://github.com/paritytech/contract-issues/issues/180

This PR introduces `eth_substrate_call`, a new extrinsic in
pallet-revive that enables Substrate runtime calls from Ethereum
transactions. This allows tools like Hardhat to invoke Substrate
extrinsics (e.g., `upload_code`) via the Ethereum RPC.

This implements a new approach for dispatching Substrate extrinsics
through the magic RUNTIME_PALLETS_ADDR address, which fixes two
shortcomings of the previous implementation:

1. Incorrect origin verification - The origin is now correctly verified
as EthTransaction.
2. Missing Ethereum transaction receipts - Receipts are now properly
generated for all Ethereum transactions.

Includes:
- New eth-rpc integration test validating end-to-end functionality
- Benchmark measuring the extrinsic overhead
- Unit tests

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] use run_instant_seal_and_finalize in dev-node (#10252)

fix finalized block production with instant-seal by using
`run_instant_seal_and_finalize` instead of `run_instant_seal`

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

make contracts create consider is_unlimited_contract_size_allowed (#10224)

While running foundry tests from
https://github.com/balancer/balancer-v3-monorepo/tree/main/pkg/pool-weighted,
found we hit this limit.

Foundry environment is configured with unlimited code size, so we need
to make sure pallet-revive respects those configurations everywhere.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add secp256r1 (0x100) precompile (#10267)

Add secp256r1 precompile (0x100)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix NextFeeMultiplier update before Revive::on_finalize (#10271)

Fix https://github.com/paritytech/polkadot-sdk/issues/10177

Store `base_fee_per_gas` and `block_gas_limit` in the EthBlockBuilderIR,
since these values are derived from the NextFeeMultiplier and we can't
read it from Revive::on_finalize since this runs (in most Runtime) after
TransactionPayment::on_finalize where the value is updated for the next
block.

also use `BlockNumberFor<T>` for the BlockHash map instead of U256. No
release have been performed yet since the introduction of that change,
so that should not require any migration.
```
	#[pallet::storage]
	pub(crate) type BlockHash<T: Config> =
		StorageMap<_, Identity, BlockNumberFor<T>, H256, ValueQuery>;
```

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Fix EVM tests to pass `data` as part of `code` (#10214)

The test code was passing the constructor argument as `data` on EVM. But
it should be passed as part of the `code`. This is different from PVM
where those are separate.

Failing to do so makes those opcodes return the wrong values when `data`
is passed to the constructor:

```
CODESIZE
CODECOPY
CALLDATASIZE
CALLDATACOPY
CALLDATALOAD
```

Further changes:

- I also added some checks to fail instantiation if `data` is non empty
when uploading new EVM bytecode.
- Return error when trying to construct EVM contract from code hash as
this does not make sense since no initcode is stored on-chain.

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix genesis eth block builder number again (#10297)

Redoes https://github.com/paritytech/polkadot-sdk/pull/10225 for the
genesis block number.

It was broken again by
https://github.com/paritytech/polkadot-sdk/pull/10271

pallet-revive: fix eth tx decoding (#10290)

Fix Ethereum transaction decoding

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] improve eth-rpc tests reliability (#10281)

Improve eth-rpc tests reliability by replacing substrate-node with
revive-dev-node, fixing nonce query in runtime_api_dry_run_addr, and
running all tests in a single tokio test function

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add hook for mocking origin (#10272)

While runing some balancer v3 tests:
https://github.com/paritytech/foundry-polkadot/issues/287#issuecomment-3502668161,
discovered we need a way to mock up the origin as well, so add hook.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive fix prestate diff tracing (#10303)

Fix prestate diff-tracing, add missing storage diff for created
contracts

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix P256Verify precompile address (#10336)

fix https://github.com/paritytech/contract-issues/issues/220

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] add tracing for selfdestruct (#10244)

Add tracing for selfdestruct

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

[pallet-revive] update evm create benchmark (#10366)

Add a benchmark for the EVM CREATE instruction.

We are currently reusing the `seal_instantiate` benchmark from PVM
instantiation, which is incorrect because instantiating an EVM contract
takes different arguments and follows a different code path than
creating a PVM contract.

This benchmark performs the following steps:

- Generates init bytecode of size i, optionally including a balance with
dust.
- Executes the init code that triggers a single benchmark opcode
returning a runtime code of the maximum allowed size
(qrevm::primitives::eip170::MAX_CODE_SIZE`).

Also fix the order of the weight function arguments, they were wrong
causing the weight to be much bigger that what it should be

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive benchmark opcode fix (#10380)

Benchmark opcode was using the invalid opcode instead of defining a new
one.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Enable force debug in revive dev node (#10383)

This change ensures that all types that implement `RuntimeDebug` are
fully displayed in log output of the revive dev node, instead of just
showing `<wasm:stripped>`.

Unfortunately, the trait `RuntimeDebugNoBound`, that we also use
frequently in pallet-revive, is not affected and will still output
`<wasm:stripped>` (it does not check for the `force-debug` feature flag,
instead it only fully outputs values when either one of the features
`std` or `try_runtime` is enabled – this is something we implement as a
general change).

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>

pallet-revive: add DebugSetting for bypassing eip-3607 (#10387)

Only works for contract accounts, not precompiles.
This is needed so that test nodes like anvil can send transactions from
contract accounts, a widely-used feature in tests

Needed for https://github.com/paritytech/foundry-polkadot/pull/423

Fix termination (#10302)

This PR fixes up termination by changing the behavior to:

- The free balance (without ed) should be send away right away to the
beneficiary and not be delayed like the contract deletion.
- The ed and storage deposit will be send away only when terminating but
to the origin (delayed).
- The scheduling of the terminate needs to be reverted if the scheduling
frame reverts.
- `SELFDESTRUCT` should be allowed inside the constructor. The issuing
contract will exist as account without code for the remainder of the
transaction.
- The `terminate` pre-compile should revert if delegate called or its
caller was delegate called. This is just my opinion but if we are
changing semantics we can might as well add some security. We are
increasing the attack surface by allowing the destruction of any
contract (not only created in the current tx).

- Storage refunds should no longer use `BestEffort`. This is necessary
to fail refunds in case some other locks (due to participation in gov
for example) prevent sending them away. This is in anticipation of new
pre-compiles.
- Moved pre-compile interfaces to sol files and made them available to
fixtures
- Added some Solidity written tests to exercise error cases

Those should all be written in Solidity to test both backends at the
same time. No more Rust fixtures.

@0xRVE can you take those over as I am ooo.

- Test that checks that scheduled deletions do properly roll back if a
frame fails
- Test that value send to a contract after scheduling for deletion is
send to the beneficiary (different from Eth where this balance is lost)
- Add tests that use `SELFDESTRUCT` to `Terminate.sol`. Need
https://github.com/paritytech/devops/issues/4508 but can be tested
locally with newest `resolc`.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alin Dima <alin@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Marian Radu <marian@parity.io>
Co-authored-by: Karol Kokoszka <karol@parity.io>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Alexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: girazoki <gorka.irazoki@gmail.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: Andrei Eres <eresav@me.com>
Co-authored-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Egor_P <egor@parity.io>
Co-authored-by: Agustín Rodriguez <agusrodriguez2456@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Thang X. Vu <zthangxv@gmail.com>
Co-authored-by: DenzelPenzel <15388928+DenzelPenzel@users.noreply.github.com>
Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
Co-authored-by: Alexander Cyon <Sajjon@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Omar <OmarAbdulla7@hotmail.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: BDevParity <bruno.devic@parity.io>

[pallet-revive] evm remove contract storage slot when writing all zero bytes (#10309)

fixes https://github.com/paritytech/contract-issues/issues/216

When an EVM contract writes an all-zero 32-byte storage word, remove the
corresponding child‑trie entry so storage-deposit accounting sees
bytes/items removed and a refund can be applied.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>

Fix assertion (#10427)

According to assertion message and comment("at least"),
`T::MaxDebugBufferLen::get() > MIN_DEBUG_BUF_SIZE` should be changed
into `T::MaxDebugBufferLen::get() >= MIN_DEBUG_BUF_SIZE`
```rust
// Debug buffer should at least be large enough to accommodate a simple error message
const MIN_DEBUG_BUF_SIZE: u32 = 256;
assert!(
	T::MaxDebugBufferLen::get() > MIN_DEBUG_BUF_SIZE,
	"Debug buffer should have minimum size of {} (current setting is {})",
	MIN_DEBUG_BUF_SIZE,
	T::MaxDebugBufferLen::get(),
);
```
For this assertion, the assertion message indicates assertion will fail
when max_storage_size > storage_size_limit, which means it requires
max_storage_size <= storage_size_limit, but assertion predicate is
`max_storage_size < storage_size_limit`. Based on the code semantics,
assertion predicate should be changed into `max_storage_size <=
storage_size_limit`.
```ru…
TorstenStueber pushed a commit that referenced this pull request Dec 5, 2025
This is a fix for the fact that `exec::Key` is exposed from within
`pallet_revive::tracing::Tracing` interface, but not from the crate
itself making custom tracers effectively unimplementable outside said
crate.

In my case it's useful for implementing custom tracers for integration
with `foundry`

Requires no downstream changes

This is a fix for the fact that `exec::Key` is exposed from within
`pallet_revive::tracing::Tracing` interface, but not from the crate
itself making custom tracers effectively unimplementable outside said
crate.

see here for one of the methods: [`exec::Key` exposed to the
implementor, despite not being exported by the
`crate`](https://github.com/paritytech/polkadot-sdk/blob/pkhry/expose_key_pallet_revive/substrate/frame/revive/src/tracing.rs#L68)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Move `to_account_id` host function to `System` pre-compile (#9455)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

cc @athei @pgherveou

---------

Co-authored-by: xermicus <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Move `blake2_128` host function to `System` pre-compile (#9454)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

I'm splitting some of the host function migrations into separate PRs, as
there are sometimes refactorings involved and this should make reviewing
easier.

cc @athei @pgherveou

[revive] move existing files to prepare evm backend introduction (#9501)

- Move exisiting files in pallet-revive to accomodate the upcoming EVM
backend
- Add solc/resolc compilation feature for fixtures
- Add `fn is_pvm` to later distinguish between pvm / evm bytecode

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

align eth-rpc response with geth (#9177)

- Update some serde encoding for eth-rpc to match serialization behavior
of Geth
- Add support for serializing / deserializing EIP7702 tx types
- Disable transaction type we don't support yet in
try_ino_unchecked_extrinsics

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[revive] revm backend (#9285)

Initial EVM support via the REVM crate to create a dual-VM system that
can execute both PolkaVM and EVM

- Added `AllowEVMBytecode: Get<bool>` to the config to enable/disable
EVM call and instantiation
- CodeInfo has been updated to add the type of bytecode (EVM / PVM).
`migration/v2.rs` takes care of migrating existing storages
- The CodeUploadDeposit is not held by a pallet account instead of being
held on the uploader, It's automatically refunded when the refcount
drops to 0 and the code is removed.
- The basic flow of uploading an EVM contract and running it should work
- instructions are copied and adapted from REVM they should be ignored
in this PR and reviewed in follow-up PR
(**reviewers** please ignore
`substrate/frame/revive/src/vm/evm/instructions/*` for now)

A basic instruction looks like this:

```rust
pub fn coinbase<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
	gas_legacy!(context.interpreter, revm_gas::BASE);
	push!(context.interpreter, context.host.beneficiary().into_word().into());
}
```

All instructions have been copied from `REVM` and updated with generic
types for pallet-revive. Two main changes are required:

Replace REVM gas calls with existing benchmarks where available:

```diff
- gas_legacy!(context.interpreter, revm_gas::BASE);
+ gas!(context.interpreter, RuntimeCosts::BlockAuthor);
```

Replace `context.host` calls with `context.extend` (set to `&mut Ext`):

```diff
- push!(context.interpreter, context.host.beneficiary().into_word().into());
+ let coinbase: Address = context.interpreter.extend.block_author().unwrap_or_default().0.into();
+ push!(context.interpreter, coinbase.into_word().into());
```

- For cases without existing benchmarks (e.g arithmetic, bitwise) , we
will keep `gas_legacy!`
- The u64 gas value are multiplied by a base cost benchmarked by
`evm_opcode`

- ### Important Rules
- All calls to `context.host` should be removed (initialized to default
values)
- All calls to `context.interpreter.gas` should be removed (except
`gas.memory` handled by `resize_memory!` macro)
- See `block_number` implementation as a reference example

The following instructions in src/vm/evm/instructions/** need to be
updated

We probably don't need to touch these implementations here, they use the
gas_legacy! macro to charge a low gas value that will be scaled with our
gas_to_weight benchmark. The only thing needed here are tests that
exercise these instructions

<details>

- [ ] **add**
- [ ] **mul**
- [ ] **sub**
- [ ] **div**
- [ ] **sdiv**
- [ ] **rem**
- [ ] **smod**
- [ ] **addmod**
- [ ] **mulmod**
- [ ] **exp**
- [ ] **signextend**

- [ ] **lt**
- [ ] **gt**
- [ ] **slt**
- [ ] **sgt**
- [ ] **eq**
- [ ] **iszero**
- [ ] **bitand**
- [ ] **bitor**
- [ ] **bitxor**
- [ ] **not**
- [ ] **byte**
- [ ] **shl**
- [ ] **shr**
- [ ] **sar**
- [ ] **clz**

- [ ] **jump**
- [ ] **jumpi**
- [ ] **jumpdest**
- [ ] **pc**
- [ ] **stop**
- [ ] **ret**
- [ ] **revert**
- [ ] **invalid**

- [ ] **mload**
- [ ] **mstore**
- [ ] **mstore8**
- [ ] **msize**
- [ ] **mcopy**

- [ ] **pop**
- [ ] **push0**
- [ ] **push**
- [ ] **dup**
- [ ] **swap**

</details>

These instructions should be updated from using gas_legacy! to gas! with
the appropriate RuntimeCost, the returned value need to be pulled from
our `&mut Ext` ctx.interpreter.extend instead of the host or input
context value

<details>

- [x] **block_number**
- [ ] **coinbase**
- [ ] **timestamp**
- [ ] **difficulty**
- [ ] **gaslimit**
- [ ] **chainid**
- [ ] **basefee**
- [ ] **blob_basefee**

- [ ] **balance**
- [ ] **extcodesize**
- [ ] **extcodecopy**
- [ ] **extcodehash**
- [ ] **blockhash**
- [ ] **sload**
- [ ] **sstore**
- [ ] **tload**
- [ ] **tstore**
- [ ] **log**
- [ ] **selfdestruct**
- [ ] **selfbalance**

- [ ] **keccak256**
- [ ] **address**
- [ ] **caller**
- [ ] **callvalue**
- [ ] **calldataload**
- [ ] **calldatasize**
- [ ] **calldatacopy**
- [ ] **codesize**
- [ ] **codecopy**
- [ ] **returndatasize**
- [ ] **returndatacopy**
- [ ] **gas**

- [ ] **origin**
- [ ] **gasprice**
- [ ] **blob_hash**

</details>

These instructions should be updated,, that's where I expect the most
code change in the instruction implementation.
See how it's done in vm/pvm module, the final result should look pretty
similar to what we are doing there with the addition of custom gas_limit
calculation that works with our gas model.

see also example code here https://github.com/paritytech/revm_example

<details>

- [ ] **create**
- [ ] **create**
- [ ] **call**
- [ ] **call_code**
- [ ] **delegate_call**
- [ ] **static_call**

</details>

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>

[pallet-revive] Expose `AccountInfo` and `ContractInfo` in the public interface (#9606)

Part of https://github.com/paritytech/polkadot-sdk/issues/9553
See https://github.com/paritytech/foundry-polkadot/issues/276

Exposes revive types to use in foundry-polkadot project.

Should not affect downstream projects.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] EVM backend: Implement tx, block system and call stack instructions (#9414)

This PR is part of the road to EVM.
- Implement call and create frames, allowing to call and instantiate
other contracts.
- Implement support for tx info, block info, system and contract
opcodes.
- The `InstructionResult` <-> `ExecError` conversion functions.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>

[pallet-revive] Update genesis config (#9557)

Update pallet-revive Genesis config
Make it possible to define accounts (contracts or EOA) that we want to
setup at Genesis

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>

[pallet-revive] Add `Pallet::set_evm_balance` (#9617)

Part of https://github.com/paritytech/polkadot-sdk/issues/9553
See https://github.com/paritytech/foundry-polkadot/issues/273

Adds a balance setter in EVM.

Should not affect downstream projects.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

[pallet-revive] EVM backend: implement various missing opcodes (#9385)

* [x] system (other PR, no tests)
* [x] block_info (other PR)
* [x] contract (other PR)
* [x] tx_info (other PR)
* [x] arithmetic
* [x] bitwise
* [x] i256 (these are not opcodes so will not test)
* [x] host (except `log()`)
* [x] memory
* [x] control (except `pc()`)
* [x] macros (these are not opcodes so will not test)
* [x] utility (these are not opcodes so will not test)
* [x] stack

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Sebastian Miasojed <sebastian.miasojed@parity.io>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sebastian Miasojed <s.miasojed@gmail.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Cyon <Sajjon@users.noreply.github.com>
Co-authored-by: Alexander Cyon <alex.cyon@parity.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Dmitry Sinyavin <dmitry.sinyavin@parity.io>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: Serban Iorga <serban@parity.io>

[pallet-revive] fix GAS_PRICE (#9679)

Currently submitting a transactio to the dev-node or kitchensink will
trigger an error when you try to submit a transaction trhough cast (or
anything using alloy) as the block gas limit on these runtime is greater
than u64::max.

This bump the GAS_PRICE to fix this issue, this will eventually be
superseeded by the new gas model

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

[pallet-revive] Properly convert `Ext::minimum_balance` value to `U256` (#9705)

The value is just cast to `U256` here, without applying the actual
conversion factor (`NativeToEthRatio`).

There are some tests that apply the same easy conversion via `Into`,
without applying the conversion factor. Those tests still succeed, but
you might want to go through those usages to not confuse people reading
the code.

@athei @pgherveou

added trace logging in EVM interpreter loop (#9561)

Added trace logging for each instruction to evm::run function.
solves https://github.com/paritytech/polkadot-sdk/issues/9575

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>

[pallet-revive] fix CodeInfo owner (#9744)

Fix CodeInfo owner, it should always be set to the origin of the
transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix tracing collect (#9736)

Tracing fixes:

- collect_trace take `self` instead of `&mut self`, to avoid reusing the
tracer state when tracing multiple transactions in a block.
- Fix issues related to call traces and the onlyTopCall config option

Fix
https://github.com/paritytech/contract-issues/issues/156https://github.com/paritytech/contract-issues/issues/156

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive-rpc: use generic RpcClient instead of ReconnectingRpcClient (#9701)

This will enable more flexible usage of the revive RPC as a library.

Needed so that we can reuse it with an in-memory RPC client for
anvil-polkadot:
https://github.com/paritytech/foundry-polkadot/issues/238

[pallet-revive] Migrate various getters to `System` pre-compile (#9517)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

Migrates:
* `own_code_hash`
* `caller_is_origin`
* `caller_is_root`
* `weight_left`
* `minimum_balance`

There are some minor other fixes in there (removing leftovers from
deprecating chain extensions, stabilizing `block_hash` in overlooked
crates, etc.).

cc @athei @pgherveou

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] fix salt endianness  (#9771)

fix <https://github.com/paritytech/polkadot-sdk/issues/9769>

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: add account_id and new_balance_with_dust runtime APIs  (#9683)

Needed for https://github.com/paritytech/foundry-polkadot/issues/240

revive-fixtures: Provide an env variable to disable compilation (#9791)

Right now `pallet-revive-fixtures` is always trying to build the
fixtures. It requires `solc` and other stuff for compilation. If you are
not requiring the fixtures, because you for example only run `cargo
check`, this pull request introduces `SKIP_PALLET_REVIVE_FIXTURES`. When
the environment variable is set, the compilation of the fixtures is
skipped. It will set the fixtures to `None` and they will panic at
runtime.

EIP-3607 added check to make sure a contract account cannot transfer funds as an EOA account (#9717)

fixes https://github.com/paritytech/polkadot-sdk/issues/9570

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Add set_storage/set_storage_var_key methods (#9759)

... to be used in polkadot foundry to make sure EVM state is in sync
with pallet-revive state.

Fixes: https://github.com/paritytech/foundry-polkadot/issues/275

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

bugfix revm set_storage gas cost (#9823)

Fixes bug in revm gasmetering where the initial charge was less than the
adjusted charge.

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet revive evm backend add tests for cross vm contract calls (#9768)

fixes https://github.com/paritytech/polkadot-sdk/issues/9576

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] update rpc metadata (#9853)

Update eth-rpc metadata files

the metadata should have been updated here
https://github.com/paritytech/polkadot-sdk/pull/9759
where a new variant was added to an enum used by the runtime api

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: allow changing immutables (#9801)

... to be used in polkadot foundry to make sure EVM state is in sync
with pallet-revive state.

Fixes: https://github.com/paritytech/foundry-polkadot/issues/277

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet_transaction_payment]: Share withdrawn tx fee credit with other pallets (#9780)

Replaces https://github.com/paritytech/polkadot-sdk/pull/9590.

The audit of #9590 showed that holding the txfee as held balance and
especially playing around with `providers` causes a lot of troubles.

This PR is a much lighter change. It keeps the original withdraw/deposit
pattern. It simply stores the withdrawn `Credit` and allows other
pallets to withdraw from it.

It is also better in terms of performance since all tx signers share a
single storage item (instead of a named hold per account).

---------

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>

`pallet-assets`: extract precompiles to a separate crate (#9796)

closes #9434

Assets pallet includes `pallet-revive` precompiles and subsequently pull
a lot of EVM related dependencies by default. This forces downstream
users that only want `pallet-assets` functionality to pull unrelated
dependencies and causes confusion (why do we have bunch of ethereum
crates in the dependency tree of `pallet-assets`?). This extracts
precompiles into its own crate

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <git@kchr.de>

pallet-revive: add custom addr recovery logic in `ReceiptExtractor` (#9878)

`ReceiptExtractor` parses blocks and associated transactions in
pallet-revive-eth-rpc and is useful for a range of Ethereum node RPCs.
When the transactions are impersonated, they are based on a fake
signature, which can't be used with the production eth address recovery
logic. The recovery logic must be customised in cases where we
impersonate transactions, so this PR adds a custom function on the
`ReceiptExtractor` which can be used to customize address recovery.

Developers using pallet-revive-eth-rpc as a lib should instantiate the
`ReceiptExtractor` with the custom constructor if impersonation usecases
must be supported.

Relevant in context of
https://github.com/paritytech/foundry-polkadot/issues/242, to implement
anvil-polkadot impersonation.

---------

Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

replace forloop solc fixture type with test-case macro (#9841)

For all tests of revm instructions replaced `for fixture_type` with
test-case macro

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Move revive fixtures into release directory (#9670)

https://github.com/paritytech/polkadot-sdk/pull/8980 did fix the
fellowship CI but it triggers a rebuild of the fixtures every single
time you run tests. Annoying during development.

Instead of rebuilding, we just move the fixtures into the
`target/release` directory where it should be cached by the fellowship
CI.

Verifying that it works here:
https://github.com/polkadot-fellows/runtimes/pull/891

Why: Re-running when the output dir changes will make it re-run every
time. Since every run changes the output dir.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Rework gas mapping (#9803)

Replacement of https://github.com/paritytech/polkadot-sdk/pull/9740.

Build on top of the new tx payment changes:
https://github.com/paritytech/polkadot-sdk/pull/9780

Started a new PR because due to the rebase on top of the new tx payment
changes this PR is substantially different and I don't want to
invalidate the existing comments on
https://github.com/paritytech/polkadot-sdk/pull/9740 which are not
implemented, yet.

This will change the weight to eth fee mapping according to [this
model](https://shade-verse-e97.notion.site/Gas-Mapping-Challenges-Revised-26c8532a7ab580db8222c2ce3023669e).

This only changes the estimate returned from the dry run and how the
weights are derived from an ethereum transaction. It does not change how
contracts observe the gas. This will be done in a follow up. More
specifically:

1. The `GAS` opcode should return the new gas. As of right now it
returns `ref_time.`
2. The `*_CALL` opcodes should use the passed `gas` parameter and decode
it into `Weight`. As of right now the parameter is ignored.

That said, even without those follow ups this PR should fix all
`InvalidTransaction` errors we are observing.

We should add a configurable divisor so that the gas_price is always at
least some gwei. That makes it easier to input the values.

---------

Signed-off-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet-revive: Bump PolkaVM (#9928)

Bumped `polkavm` to the latest version. No semantic changes in that
update.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] revm refactor (#9818)

Refactor REVM implementation in `pallet-revive`

This PR removes technical debt and eliminates tight coupling to specific
REVM versions, facilitating integration with other projects (e.g.,
Foundry). After this refactoring, we primarily depend only on REVM's
[`Bytecode`](https://docs.rs/revm/latest/revm/bytecode/struct.Bytecode.html)
struct.

Most of REVM's generic type system and trait abstractions are unused or
had to be ignored to prevent bugs. Interactions with the host in
pallet-revive are handled through the `Ext` trait, making REVM's other
abstractions unnecessary or potentially harmful.

Unused REVM abstractions included:
- **Host trait**: Unused in the pallet, we relied on the `DummyHost`
default mocked implementation
- **Gas field**: Unused, the pallet uses its own gas accounting system
- **Methods from `InputsTr`**: Unused most methods had panic
implementations since they couldn't be relied upon
- **Spec**: Unused: We only maintain the latest fork for each runtime

This refactor introduces:
- **Interpreter**: Simplified struct containing only the fields actually
needed
- **Stack**: Simplified implementation using `sp_core::*` instead of
`alloy_core::primitives::*` for better integration with the rest of the
pallet
- **Memory**: Simplified implementation providing only the methods
actually needed
- **Instructions**:
- New instructions don't rely on macros and have a simplified signature:
`Fn(&mut interpreter) -> ControlFlow<Halt>`
- Removed function pointer table lookup for instructions in favor of
match statements,
- Unified gas charging: legacy u64 gas charging is now wrapped in
`EVMGas` that implements `Token<T>` to provide the associated weight
- Removed the `InterpreterAction`, this simplify the interpreter loop
to:
```rust
loop {
	let opcode = interpreter.bytecode.opcode();
	interpreter.bytecode.relative_jump(1);
	exec_instruction(interpreter, opcode)?;
}
```
- **Error handling**: Opcode that fail return Halt::Err(DispatchError),
this remove the need from converting between InstructionResult and
`ExecError` like we were previously doing and standardize errors
generated on both backends

---------

Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Allows setting evm balance for non-existing account (#9911)

Allows calling set_evm_balance for a non-existing account on
pallet-revive.
It is needed by foundry to inject EVM accounts.

pallet-revive: Fix dry run balance check logic (#9942)

Fix fault balance check logic during dry-run:

We should not enforce that the sender has enough balance for the fees in
case no `gas` is supplied.

cc @TorstenStueber

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Allow unlimited contract size in debug mode. (#9831)

Fixes https://github.com/paritytech/contract-issues/issues/167

The main changes in this PR are:

1. Added an associated type DebugEnabled
2. Introduced a DebugSettings struct with a single boolean field
3. Added a StorageValue: pub(crate) type DebugSettingsOf<T: Config> =
StorageValue<_, DebugSettings<T>, ValueQuery>;
4. Included debug_settings in the GenesisConfig
5. Added a unit test to verify that large EVM contracts can be
instantiated.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

pallet-revive update basefee instruction (#9945)

The base fee instruction now returns the proper base price instead of a
hard coded value.

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Migrate unstable storage host functions to `Storage` pre-compile (#9603)

Part of closing https://github.com/paritytech/polkadot-sdk/issues/8572.

Introduces a new `Storage` pre-compile and migrates:
* `clear_storage`
* `take_storage`
* `contains_storage`

The new `Storage` pre-compile is introduced, as it requires implementing
the `BuiltinPrecompile::call_with_info` function, which cannot be
implemented together with `BuiltinPrecompile::call` (implemented by the
`System` pre-compile).

I've added the `sol_utils` as I (on admittedly quick glance) couldn't
find a crate that supports those encodings (Solidity's `bytes`) without
requiring an allocator.

cc @athei @pgherveou

---------

Co-authored-by: xermicus <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

Return unified gas for `gas_left` syscalls and opcodes (#9968)

In https://github.com/paritytech/polkadot-sdk/pull/9803 we introduced
the new gas mapping. However, when contracts are querying the remaining
gas we still returned the `ref_time`. This PR changes that.

- Added a new `Stack::gas_left` function that calculates the remaining
gas as eth gas that matches the gas passed in the transaction. It
supports both the `eth_` and non `eth_` flavors of dispatchables.
- Changed the PVM syscall `ref_time_left` to return the new unified gas.
- Changes the EVM `GAS` opcode to return the new unified gas
- When calculating the consumed storage we now take into account what
was charged during the current frame
- Removed `storage_deposit_limit` from `eth_*` dispatchables. It is
always uncapped in this case and the overall limit is conveyed using the
tx credit.

Now that we can return the proper remaining gas that also includes the
storage deposit we can change the EVM `call` instruction next to take
the passed `gas` into account. Since the unified gas takes both the
txfee and the deposit into account it will be able to limit both
effectively.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

[pallet-revive] dev-node constant fee multiplier (#9939)

This will let us have stable gas cost (as long as the state of the dev
net does not change)

In mainnet neither polkadot, nor EVM chains can guarantee stable gas
since the state of the blockchain can change between two dry runs, but I
would argue that we are better off if we have stable gas cost in testing
environments as that is the standard on EVM devnet

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix exp overflow (#9991)

Update arithmetic tests, and fix potential overflow

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

 Wait for transaction receipt if instant seal is enabled (#9914)

Fixes https://github.com/paritytech/contract-issues/issues/165

The main changes in this PR are:

1. Add a new API to revive-dev-node to check whether the node has
instant seal enabled.
2. Add a new debug API to eth-rpc to check whether the node has instant
seal enabled. (optional)
3. Query and cache the node’s instant seal status during eth-rpc
initialization.
4. If instant seal is enabled, wait for the transaction receipt to be
available

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

[pallet-revive] Implement the consume_all_gas syscall (#9997)

This PR implements a new API `consume_all_gas` which is required for
100% EVM `INVALID` opcode compatibility.

Since ceding of all remaining gas is handled in the EVM interpreter, I
decided to not add a return flag but make this a dedicated syscall for
consistency instead.

Didn't implement a benchmark since the first (and only) thing this does
is consuming all remaining gas anyways.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

`pallet-xcm`: extract precompiles to a separate crate (#9985)

This PR extracts the XCM precompile from `pallet-xcm` into a new
standalone crate `pallet-xcm-precompiles` to resolve an unwanted
dependency issue. Previously, the XCM precompile was implemented
directly in `pallet-xcm/src/precompiles.rs`, which required `pallet-xcm`
to depend on `pallet-revive`, introducing it as a transitive dependency
for all parachains using `pallet-xcm`.

Closes #9955

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] fix subxt submit & add debug statments (#10016)

- Fix subxt submit by default it's using
`author_submitAndWatchExtrinsic` even though we just want to fire and
forget
- Add debug instructions to log the signer & nonce of new eth
transactions when the node validate the transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Lower the deposit costs for child trie items (#10027)

Fixes https://github.com/paritytech/polkadot-sdk/issues/9246

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Fix incorrect `block.gaslimit` (#10026)

Fixes https://github.com/paritytech/contract-issues/issues/112

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

frame/revive: ETH block storage (#9418)

This PR constructs the Ethereum block in the following way:
- events (logs) are captured via an `environmental!` variable to reduce
reliance on pallet storage
- A maximum of 512 events is allowed per transaction, with the size of
an event capped to `self.ext.max_value_size()`
- A memory-efficient intermediate block builder is deserialized and
serialized back to the pallet storage
- The intermediate block builder builds the transaction and event root
hashes using low level RLP encoding primitives to achieve around 90%
pallet storage optimization
- For more details, see
https://github.com/paritytech/polkadot-sdk/pull/9764
- A fixup is included for 7702 transaction rlp
serialization/deserialization is added to ensure we can build the
Ethereum block hash from live Ethereum blocks.
- The maximum `CALL_PARAMS_MAX_SIZE` is increased to 512 to 244 to
accommodate the transaction added to the Eth call

This PR also includes benchmarking:
- https://github.com/paritytech/polkadot-sdk/pull/9496

- pallet storage testing and capturing of events / transactions are
added at `tests/block_hash.rs`
- incremental block storage is tested in `evm/block_hash.rs`, which
ensures RLP encoding / hash builder and identical hashes from live
ethereum blocks
- tested via RPC work

- https://github.com/paritytech/polkadot-sdk/pull/9512
- https://github.com/paritytech/polkadot-sdk/pull/9616
- https://github.com/paritytech/polkadot-sdk/pull/9452

Builds upon https://github.com/paritytech/polkadot-sdk/pull/9413

Part of: https://github.com/paritytech/contract-issues/issues/139

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] improve revive genesis config (#9988)

- Update test to make sure contracts created at genesis are callable
- make sure that contracts are brought to existence by minting e.d first

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

added baltathar, charleth, dorothy, and ethan to eth-rpc and revive-d… (#10041)

adds more funded accounts to eth-rpc and dev-node

---------

Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Increase event sizes (#10047)

Fixes https://github.com/paritytech/contract-issues/issues/140

This increases the maximum event payload size from 416 bytes to 64k.
Since https://github.com/paritytech/polkadot-sdk/pull/9418 we charge
some additional weight per byte of event payload. This makes it possible
to raise the limit while staying within our memory envelope. This
artificial weight will add 18us of weight to a maximum sized event.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: when a dry run simulates contract deployment, return the execution result data. (#10032)

Fixes https://github.com/paritytech/contract-issues/issues/177

Expose the deployed contract's runtime bytecode in eth_call responses
during simulated contract creation.

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.

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

eth-rpc add trace logs (#10065)

Add extra tracing logs for estimate_gas and send_raw_transaction

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>

pallet_revive: Raise the MaxEthExtrinsicWeight (#10089)

Fixes https://github.com/paritytech/contract-issues/issues/194

Factory extrinsics do need more weight. It is fine to raise them to
almost the full max extrinsic weight since this is still lower than the
block weight.

Also improving the error reporting during the dry run in case an
extrinsic hits this limit. No more `OutOfGas` but a more descriptive
error of how much it is overweight.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

precompiles: Enforce state mutability (#10080)

`pallet-assets-precompile`, `pallet-xcm-precompiles` and revive builtin
precompile implementations currently violate [Solidity state
mutability](https://docs.soliditylang.org/en/latest/grammar.html#syntax-rule-SolidityParser.stateMutability),
potentially introducing a new attack vector. This PR implements
corresponding checks at the function dispatch.

Could be enforced in `pallet-revive`, however:
1. Adding something like a `const MUTATES: bool` to the `Precompile`
trait won't help because whether the call is mutating or not depends on
the [Solidity function
selector.](https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector).
2. Alloy, which we are using to parse the interface definitions prior to
calling precompile implementations, doesn't provide a mapping from
function selector to its mutability
[modifier](https://docs.soliditylang.org/en/latest/cheatsheet.html#modifiers).

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive: fix alloy-consensus dependency (#10090)

Needed in order to update foundry-polkadot to the latest master:
https://github.com/paritytech/foundry-polkadot/pull/352

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Enforce single-state txpool for revive-dev-node (#10106)

Use single-state txpool for dev-node when instant-seal is selected

see https://github.com/paritytech/polkadot-sdk/issues/10104

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: Add ExportChainSpec command to revive-dev-node (#10020)

Add the `export-chain-spec` command to the revive-dev-node.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive/rpc: Adjust the RPC to utilize the ETH block from storage (#9512)

This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks
from storage via runtime APIs and establishes proper Ethereum ↔
Substrate block hash mappings.

- **New database table**: `eth_to_substrate_blocks` maps Ethereum block
hashes to Substrate block hashes and block numbers
- **Bidirectional lookups**: Support for both ETH→Substrate and
Substrate→ETH hash resolution with backward compatibility fallbacks
- **Block pruning**: Updated to remove stale mappings alongside
transaction and log data

- **Genesis block initialization**: Added
`block_storage::on_finalize_build_eth_block()` call in
`BuildGenesisConfig` to properly build and store block 0

- Added comprehensive tests for block hash mapping operations
- Ethereum vs Substrate hash resolution tests
- Fork handling in block pruning tests
- Log filtering with Ethereum block hash tests
- TransactionInfo deserialization from JSON Value tests

The implementation uses a **runtime API approach** where the RPC layer
queries the runtime for Ethereum blocks and hashes, which are then
mapped to Substrate block hashes in the local SQLite database. This
provides:

1. **Backward compatibility**: Falls back to treating hashes as
Substrate hashes when no mapping exists
2. **Efficient lookups**: Database indices on both Ethereum and
Substrate block hashes
3. **Automatic cleanup**: Block mappings are pruned alongside
transaction and log data
4. **Genesis block handling**: Block 0 is built during genesis using the
block storage infrastructure

Builds upon: https://github.com/paritytech/polkadot-sdk/pull/9418
Part of: https://github.com/paritytech/contract-issues/issues/139

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

revive-dev-node enforce --dev (#10109)

enforce --dev and default --log in revive-dev-node

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Change bahaviour of contract termination in accordance with EIP-6780 (#9699)

fixes https://github.com/paritytech/polkadot-sdk/issues/9621

Behavior of `terminate` is changed in accordance with EIP-6780 (and EVM
in general):
- `terminate` only deletes the code from storage if it is called in the
same transaction the contract was created.
- `terminate` does not destroy the contract instantly. The contract is
registered for destruction, which happens at the end of the transaction.

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Robert van Eerdewijk <robert@Roberts-MacBook-Pro.local>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Sebastian Miasojed <sebastian.miasojed@parity.io>
Co-authored-by: Sebastian Miasojed <s.miasojed@gmail.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Only enforce EIP-3607 for dispatchables (#10100)

The EIP states that contract addresses cannot be the origin of a
transaction. However, we are enforcing this rule for all contract
execution (i.e all public function on the pallet). This is a problem for
code that uses `pallet_revive` and explicitly wants to allow this.

This PR now only enforces this check for dispatchables so that all the
`bare_*` functions are unaffected.

As a drive-by a regrouped the functions on the `Pallet` so that the
public functions are no longer interleaved with the private ones. This
got mixed up when we resolved some merge conflicts.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add interface to implement mocks and pranks (#9909)

Needed for: https://github.com/paritytech/foundry-polkadot/pull/334.

In foundry-polkadot we need the ability to be able to manipulate the
`msg.sender` and the `tx.origin` that a solidity contract sees cheatcode
documentation, plus the ability to mock calls and functions.

Currently all create/call methods use the `bare_instantiate`/`bare_call`
to run things in pallet-revive, the caller then normally gets set
automatically, based on what is the call stack, but for `forge test` we
need to be able to manipulate, so that we can set it to custom values.

Additionally, for delegate_call, bare_call is used, so there is no way
to specify we are dealing with a delegate call, so the call is not
working correcly.

For both this paths, we need a way to inject this information into the
execution environment, hence I added an optional hooks interface that we
implement from foundry cheatcodes for prank and mock functionality.

- [x] Add tests to make sure the hooks functionality does not regress.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[revive] Receipts should include failed tx (#10120)

The current implementation incorrectly accumulates receipts in storage
to compute the `receipts_root`.
However, when an extrinsic fails, all storage changes are reverted
causing the receipts to be lost.

This PR updates the handling of Ethereum transactions so that they
always succeed. The transaction logic is now wrapped in a top-level
storage transaction that rolls back all state changes on failure while
still producing a valid receipt.

A new event `EthExtrinsicRevert` is emitted when an eth transaction
reverts.
eth-rpc uses this event to set the correct receipt status.

This event also serves as a replacement for ExtrinsicFailed to make
debugging failed Ethereum transactions easier in tools like Polkadot.js.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

anvil / eth-rpc - fix subscription race (#10146)

fix
https://github.com/paritytech/polkadot-sdk/issues/10139#issuecomment-3456077366

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alin Dima <alin@parity.io>

pallet_revive: Improve logging (#10157)

Just added some more information to the log output during dry_run and
transaction creation. This was helpful when debugging if the correct gas
was passed in by the client.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: make contract reverted error message more verbose (#10168)

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive-eth-rpc: derive Encode/Decode for subxt-generated types (#10169)

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive_dev_node: Always increment the timestamp by at least one second (#10160)

Fixes https://github.com/paritytech/contract-issues/issues/191

cc @albertov19

The instant seal introduces a race condition. Blocks can be build faster
than the timestamp resolution of Ethereum. Eth timestamps are only one
second granularity. If we build blocks faster it can happen that the
timestamp delta between them is zero. This is not allowed. We have to
make sure that in instant seal two blocks don't return the same
timestamp.

This PR does that by always incrementing the timestamp by at least one
second. Note that this is a dev-node only change. Production chains
won't have this problem as long as the block time is larger than 1
second.

Yes, it will produce timestamps in the future. But this seems to be the
lesser evil for this dev node. Time is subjective. But the rule to not
return duplicate timestamps is dependent on.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Add upload evm code function (#10129)

EVM Runtime Code Upload for Foundry Integration
This feature enables direct upload of EVM runtime bytecode (deployed
contract code without constructor) to the pallet-revive, supporting
Foundry's code migration functionality between REVM and pallet-revive
execution environments.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive-eth-rpc: fix blocks pruning (#10175)

We need to call prune_blocks before the insertion process.
Otherwise, if we get a fork, we won't be able to insert it into the DB
because it already exists there. In reality, we want the other fork to
be pruned instead.

Moreover, once we do get a fork we need to prune all the other
subsequent blocks of the old fork

Return the correct block difficulty from the eth-rpc (#10186)

This PR fixes an issue in the eth-rpc/pallet-revive that was causing it
to return an incorrect value for the block's difficulty or prevrandao.

In the VM/interpreter implementation we use a constant for the block
difficulty. However, the eth block construction side was unaware of this
constant being used and therefore the RPC was always returning a block
difficulty of zero.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive: Fix dust & child contract calls (#10192)

When transferring to self we should just return early as it's a noop.
Not doing so cause bug in `transfer_with_dust`

as we do
```
from.dust -= from.dust
to.dust += to.dust
```

We end up with a value of dust - planck (that we burnt from to create
dust amount) on the account

fix https://github.com/paritytech/contract-issues/issues/211

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

revive fix reported gas used (#10148)

Fix `gas_used` calculation introduced in #9418 to use the actual gas
instead of just `ref_time`.

With these changes we now guarantee that `tx_cost = effective_gas_price
* gas`.
Note that since we compute gas as `fee / gas_price`, this can lead to
rounding errors when the chain uses `SlowAdjustingFeeUpdate` (i.e. the
fee is not a multiple of the gas price).
The changes in this PR ensure the fee still matches by burning the
rounding remainder.

This PR also fixes how the actual fee is computed and introduces a new
`compute_actual_fee` in `Config::FeeInfo`.
The previous fee calculation was skipping the `extension_weight` in the
fee calculation.

The updated tests ensure that the tx cost reported in the receipt
matches the fees deducted from the user account:

https://github.com/paritytech/evm-test-suite/blob/460b2c9aa3a3019d3508bb5a34a2498ea86035ff/src/gas.test.ts?plain=1#L31-L61

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[v2] pallet-revive: support uploading EVM bytecode via upload_code extrinsic. (#10193)

Fixes https://github.com/paritytech/contract-issues/issues/182

Add support for EVM bytecode to the upload_code extrinsic.
Tests in issue https://github.com/paritytech/contract-issues/issues/182
send hardhat_setCode, which uses revive's upload_code API; this change
makes that flow accept and store the EVM bytecode using upload_code
extrinsic.

This PR deprecates PR:
https://github.com/paritytech/polkadot-sdk/pull/10095

Comment explaining test configuration requirements:
https://github.com/paritytech/polkadot-sdk/pull/10095#issuecomment-3456450460

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Notify when there is a new best block (#10220)

Modify the tx_notifier to send the block hash to the subscribers instead
of all transactions hashes.
Modify the send_raw_transaction to look for the transaction hash in the
transactions field of the evm block.

We need this changes in anvil-polkadot:
* https://github.com/paritytech/foundry-polkadot/pull/389
* to be able to implement some RPCs like : send_transaction_sync and the
filters logic

---------

Signed-off-by: Alexandru Cihodaru <alexandru.cihodaru@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Only fund new accounts with ED (#10233)

fixes https://github.com/paritytech/contract-issues/issues/179

In case an account is created by transferring funds to it, and after
that a contract is deployed to that account, it will receive the
existential deposit twice. This can be done using create2.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

pallet_revive: Add dry-run timestamp override support (#10191)

This PR updates `pallet-revive` to **support overriding the block
timestamp during dry-run calls**.
The dry-run execution now uses the following configuration for
`eth_estimateGas` and `eth_call` when the block tag is `pending`:

```text
block.timestamp = max(rpc_timestamp, latest_block.timestamp + 1)
block.number = latest_block.number + 1
```

Fixes [#153](https://github.com/paritytech/contract-issues/issues/153),
[#205](https://github.com/paritytech/contract-issues/issues/205)

Downstream projects using the `ReviveApi::eth_transact` runtime API
should either provide a `timestamp` or pass `None`.

- Added dry run timestamp to `ExecConfig`.
- Added a new parameter to `ReviveApi::eth_transact` for passing the
current RPC timestamp.
- `eth_estimateGas` and `eth_call` with `pending` block tag will dry run
the transaction with the block timestamp set to `max(rpc_timestamp,
latest_block.timestamp + 1)` and block number set to
`latest_block.number + 1`.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>

pallet_revive: use real storage when building the eth genesis block (#10225)

When building the eth genesis block, query the real storage items that
store the timestamp and block number instead of using the zeroed items.

If the chainspec does not customise these, they will remain zeroed.

However, anvil does customise these if requested by the user.
Needed in order to merge
https://github.com/paritytech/foundry-polkadot/pull/391

Remove outdated comment on Tracer Type (#10246)

Prestate tracer type is now supported

[pallet-revive] fix prestate tracer current address (#10239)

Fix prestate tracer not reporting the contract addresses properly.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] Add eth_substrate_call extrinsic (#10159)

Fixes https://github.com/paritytech/contract-issues/issues/180

This PR introduces `eth_substrate_call`, a new extrinsic in
pallet-revive that enables Substrate runtime calls from Ethereum
transactions. This allows tools like Hardhat to invoke Substrate
extrinsics (e.g., `upload_code`) via the Ethereum RPC.

This implements a new approach for dispatching Substrate extrinsics
through the magic RUNTIME_PALLETS_ADDR address, which fixes two
shortcomings of the previous implementation:

1. Incorrect origin verification - The origin is now correctly verified
as EthTransaction.
2. Missing Ethereum transaction receipts - Receipts are now properly
generated for all Ethereum transactions.

Includes:
- New eth-rpc integration test validating end-to-end functionality
- Benchmark measuring the extrinsic overhead
- Unit tests

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] use run_instant_seal_and_finalize in dev-node (#10252)

fix finalized block production with instant-seal by using
`run_instant_seal_and_finalize` instead of `run_instant_seal`

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

make contracts create consider is_unlimited_contract_size_allowed (#10224)

While running foundry tests from
https://github.com/balancer/balancer-v3-monorepo/tree/main/pkg/pool-weighted,
found we hit this limit.

Foundry environment is configured with unlimited code size, so we need
to make sure pallet-revive respects those configurations everywhere.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add secp256r1 (0x100) precompile (#10267)

Add secp256r1 precompile (0x100)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix NextFeeMultiplier update before Revive::on_finalize (#10271)

Fix https://github.com/paritytech/polkadot-sdk/issues/10177

Store `base_fee_per_gas` and `block_gas_limit` in the EthBlockBuilderIR,
since these values are derived from the NextFeeMultiplier and we can't
read it from Revive::on_finalize since this runs (in most Runtime) after
TransactionPayment::on_finalize where the value is updated for the next
block.

also use `BlockNumberFor<T>` for the BlockHash map instead of U256. No
release have been performed yet since the introduction of that change,
so that should not require any migration.
```
	#[pallet::storage]
	pub(crate) type BlockHash<T: Config> =
		StorageMap<_, Identity, BlockNumberFor<T>, H256, ValueQuery>;
```

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet_revive: Fix EVM tests to pass `data` as part of `code` (#10214)

The test code was passing the constructor argument as `data` on EVM. But
it should be passed as part of the `code`. This is different from PVM
where those are separate.

Failing to do so makes those opcodes return the wrong values when `data`
is passed to the constructor:

```
CODESIZE
CODECOPY
CALLDATASIZE
CALLDATACOPY
CALLDATALOAD
```

Further changes:

- I also added some checks to fail instantiation if `data` is non empty
when uploading new EVM bytecode.
- Return error when trying to construct EVM contract from code hash as
this does not make sense since no initcode is stored on-chain.

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix genesis eth block builder number again (#10297)

Redoes https://github.com/paritytech/polkadot-sdk/pull/10225 for the
genesis block number.

It was broken again by
https://github.com/paritytech/polkadot-sdk/pull/10271

pallet-revive: fix eth tx decoding (#10290)

Fix Ethereum transaction decoding

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] improve eth-rpc tests reliability (#10281)

Improve eth-rpc tests reliability by replacing substrate-node with
revive-dev-node, fixing nonce query in runtime_api_dry_run_addr, and
running all tests in a single tokio test function

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive: add hook for mocking origin (#10272)

While runing some balancer v3 tests:
https://github.com/paritytech/foundry-polkadot/issues/287#issuecomment-3502668161,
discovered we need a way to mock up the origin as well, so add hook.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive fix prestate diff tracing (#10303)

Fix prestate diff-tracing, add missing storage diff for created
contracts

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix P256Verify precompile address (#10336)

fix https://github.com/paritytech/contract-issues/issues/220

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[pallet-revive] add tracing for selfdestruct (#10244)

Add tracing for selfdestruct

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>

[pallet-revive] update evm create benchmark (#10366)

Add a benchmark for the EVM CREATE instruction.

We are currently reusing the `seal_instantiate` benchmark from PVM
instantiation, which is incorrect because instantiating an EVM contract
takes different arguments and follows a different code path than
creating a PVM contract.

This benchmark performs the following steps:

- Generates init bytecode of size i, optionally including a balance with
dust.
- Executes the init code that triggers a single benchmark opcode
returning a runtime code of the maximum allowed size
(qrevm::primitives::eip170::MAX_CODE_SIZE`).

Also fix the order of the weight function arguments, they were wrong
causing the weight to be much bigger that what it should be

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

pallet-revive benchmark opcode fix (#10380)

Benchmark opcode was using the invalid opcode instead of defining a new
one.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Enable force debug in revive dev node (#10383)

This change ensures that all types that implement `RuntimeDebug` are
fully displayed in log output of the revive dev node, instead of just
showing `<wasm:stripped>`.

Unfortunately, the trait `RuntimeDebugNoBound`, that we also use
frequently in pallet-revive, is not affected and will still output
`<wasm:stripped>` (it does not check for the `force-debug` feature flag,
instead it only fully outputs values when either one of the features
`std` or `try_runtime` is enabled – this is something we implement as a
general change).

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>

pallet-revive: add DebugSetting for bypassing eip-3607 (#10387)

Only works for contract accounts, not precompiles.
This is needed so that test nodes like anvil can send transactions from
contract accounts, a widely-used feature in tests

Needed for https://github.com/paritytech/foundry-polkadot/pull/423

Fix termination (#10302)

This PR fixes up termination by changing the behavior to:

- The free balance (without ed) should be send away right away to the
beneficiary and not be delayed like the contract deletion.
- The ed and storage deposit will be send away only when terminating but
to the origin (delayed).
- The scheduling of the terminate needs to be reverted if the scheduling
frame reverts.
- `SELFDESTRUCT` should be allowed inside the constructor. The issuing
contract will exist as account without code for the remainder of the
transaction.
- The `terminate` pre-compile should revert if delegate called or its
caller was delegate called. This is just my opinion but if we are
changing semantics we can might as well add some security. We are
increasing the attack surface by allowing the destruction of any
contract (not only created in the current tx).

- Storage refunds should no longer use `BestEffort`. This is necessary
to fail refunds in case some other locks (due to participation in gov
for example) prevent sending them away. This is in anticipation of new
pre-compiles.
- Moved pre-compile interfaces to sol files and made them available to
fixtures
- Added some Solidity written tests to exercise error cases

Those should all be written in Solidity to test both backends at the
same time. No more Rust fixtures.

@0xRVE can you take those over as I am ooo.

- Test that checks that scheduled deletions do properly roll back if a
frame fails
- Test that value send to a contract after scheduling for deletion is
send to the beneficiary (different from Eth where this balance is lost)
- Add tests that use `SELFDESTRUCT` to `Terminate.sol`. Need
https://github.com/paritytech/devops/issues/4508 but can be tested
locally with newest `resolc`.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Alin Dima <alin@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Marian Radu <marian@parity.io>
Co-authored-by: Karol Kokoszka <karol@parity.io>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Alexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: girazoki <gorka.irazoki@gmail.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Lukasz Rubaszewski <117115317+lrubasze@users.noreply.github.com>
Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: Andrei Eres <eresav@me.com>
Co-authored-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Egor_P <egor@parity.io>
Co-authored-by: Agustín Rodriguez <agusrodriguez2456@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Thang X. Vu <zthangxv@gmail.com>
Co-authored-by: DenzelPenzel <15388928+DenzelPenzel@users.noreply.github.com>
Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
Co-authored-by: Alexander Cyon <Sajjon@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Omar <OmarAbdulla7@hotmail.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: BDevParity <bruno.devic@parity.io>

[pallet-revive] evm remove contract storage slot when writing all zero bytes (#10309)

fixes https://github.com/paritytech/contract-issues/issues/216

When an EVM contract writes an all-zero 32-byte storage word, remove the
corresponding child‑trie entry so storage-deposit accounting sees
bytes/items removed and a refund can be applied.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <pgherveou@gmail.com>

Fix assertion (#10427)

According to assertion message and comment("at least"),
`T::MaxDebugBufferLen::get() > MIN_DEBUG_BUF_SIZE` should be changed
into `T::MaxDebugBufferLen::get() >= MIN_DEBUG_BUF_SIZE`
```rust
// Debug buffer should at least be large enough to accommodate a simple error message
const MIN_DEBUG_BUF_SIZE: u32 = 256;
assert!(
	T::MaxDebugBufferLen::get() > MIN_DEBUG_BUF_SIZE,
	"Debug buffer should have minimum size of {} (current setting is {})",
	MIN_DEBUG_BUF_SIZE,
	T::MaxDebugBufferLen::get(),
);
```
For this assertion, the assertion message indicates assertion will fail
when max_storage_size > storage_size_limit, which means it requires
max_storage_size <= storage_size_limit, but assertion predicate is
`max_storage_size < storage_size_limit`. Based on the code semantics,
assertion predicate should be changed into `max_storage_size <=
storage_size_limit…
TorstenStueber added a commit that referenced this pull request Dec 6, 2025
Backport all pallet-revive related changes into `unstable2507`.

These are all the changes we want to get onto the next Kusama release.
Main changes include
- EVM backend
- Ethereum block storage
- Generalized gas mapping

The complete list of PRs in this backport is
- #9482
- #9455
- #9454
- #9501
- #9177
- #9285
- #9606
- #9414
- #9557
- #9617
- #9385
- #9679
- #9705
- #9561
- #9744
- #9736
- #9701
- #9517
- #9771
- #9683
- #9791
- #9717
- #9759
- #9823
- #9768
- #9853
- #9801
- #9780
- #9796
- #9878
- #9841
- #9670
- #9865
- #9803
- #9928
- #9818
- #9911
- #9942
- #9831
- #9945
- #9603
- #9968
- #9939
- #9991
- #9914
- #9997
- #9985
- #10016
- #10027
- #10026
- #9418
- #9988
- #10041
- #10047
- #10032
- #10065
- #10089
- #10080
- #10090
- #10106
- #10020
- #9512
- #10109
- #9699
- #10100
- #9909
- #10120
- #10146
- #10157
- #10168
- #10169
- #10160
- #10129
- #10175
- #10186
- #10192
- #10148
- #10193
- #10220
- #10233
- #10191
- #10225
- #10246
- #10239
- #10159
- #10252
- #10224
- #10267
- #10271
- #10214
- #10297
- #10290
- #10281
- #10272
- #10303
- #10336
- #10244
- #10366
- #10380
- #10383
- #10387
- #10302
- #10309
- #10427
- #10385
- #10451
- #10471
- #10166
- #10510
- #10393
- #10540
- #9587
- #10071
- #10558
- #10554
- #10325

---------

Signed-off-by: xermicus <cyrill@parity.io>
Co-authored-by: Pavlo Khrystenko <45178695+pkhry@users.noreply.github.com>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: pgherveou <pgherveou@gmail.com>
Co-authored-by: Omar <OmarAbdulla7@hotmail.com>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: xermicus <cyrill@parity.io>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants