You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
## Background
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
## Changes
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 <[email protected]>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert van Eerdewijk <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>
This PR refactors the REVM implementation in `pallet-revive`, reducing technical debt and decoupling it from specific REVM versions. This enables easier integration with other projects, such as Foundry, with dependencies limited to REVM's [`Bytecode`](https://docs.rs/revm/latest/revm/bytecode/struct.Bytecode.html).
6
+
7
+
**Background:**
8
+
Many of REVM's generics and trait abstractions were unused or ignored to avoid bugs. The pallet interacts with the host via the `Ext` trait, rendering other REVM abstractions unnecessary.
9
+
10
+
Previously unused REVM components included:
11
+
- `Host` trait: Unused, relied on the `DummyHost` mock.
12
+
- Gas field: Not used, as the pallet uses its own accounting.
13
+
- Methods from `InputsTr`: Most methods unused or had panic implementations.
14
+
- `Spec`: Only maintaining the latest fork per runtime.
15
+
16
+
**Key Changes:**
17
+
- Interpreter: Now a minimal struct with only necessary fields.
18
+
- Stack: Uses `sp_core::U256` for better integration.
19
+
- Memory: Simplified to needed methods only.
20
+
- Instructions: Rewritten with simple signatures, using match statements instead of function pointer tables. Gas charging uses `EVMGas` wrapped in `Token<T>`. The interpreter loop has been significantly simplified.
0 commit comments