Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/evm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ specification itself are tracked in the root

## Unreleased

### Fixed

- The executor now runs with the Prague hardfork instead of Shanghai, so
bytecode from current `solc` (which uses `MCOPY`, `TLOAD` and `TSTORE`)
executes.

## 0.1.0-preview.0 — 2026-09-21

The version scheme changed: prerelease versions are now `preview.<n>`, and
Expand Down
28 changes: 28 additions & 0 deletions packages/evm/src/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ const returnValueCode = "602a60005260206000f3";
// RETURN => f3
const constructorCode = "65602a600055006000526006601af3";

// mcopy: PUSH1 0x2a PUSH1 0x00 MSTORE
// PUSH1 0x20 PUSH1 0x00 PUSH1 0x20 MCOPY
// PUSH1 0x20 PUSH1 0x20 RETURN
// Copies a word from offset 0 to offset 0x20 and returns it.
const mcopyCode = "602a600052" + "602060006020" + "5e" + "60206020f3";

// transient: PUSH1 0x2a PUSH1 0x01 TSTORE
// PUSH1 0x01 TLOAD PUSH1 0x00 MSTORE
// PUSH1 0x20 PUSH1 0x00 RETURN
// Stores 42 in transient slot 1, loads it and returns it.
const transientCode = "602a60015d" + "60015c600052" + "60206000f3";

describe("Executor", () => {
let executor: Executor;

Expand Down Expand Up @@ -131,4 +143,20 @@ describe("Executor", () => {
expect(after).not.toEqual(before);
});
});

describe("cancun opcodes", () => {
it("executes MCOPY", async () => {
const result = await executor.executeCode(mcopyCode);
expect(result.error).toBeUndefined();
expect(result.success).toBe(true);
expect(bytesToHex(result.returnValue)).toBe("2a".padStart(64, "0"));
});

it("executes TSTORE and TLOAD", async () => {
const result = await executor.executeCode(transientCode);
expect(result.error).toBeUndefined();
expect(result.success).toBe(true);
expect(bytesToHex(result.returnValue)).toBe("2a".padStart(64, "0"));
});
});
});
12 changes: 9 additions & 3 deletions packages/evm/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import { EVM } from "@ethereumjs/evm";
import type { InterpreterStep } from "@ethereumjs/evm";
import { SimpleStateManager } from "@ethereumjs/statemanager";
import { Common, Mainnet } from "@ethereumjs/common";
import { Common, Hardfork, Mainnet } from "@ethereumjs/common";
import { Address, Account } from "@ethereumjs/util";
import { hexToBytes, bytesToHex } from "ethereum-cryptography/utils";

import type { TraceStep, TraceHandler } from "#trace";

/**
* Hardfork used for execution. Current solc targets prague by default,
* so this must be at least cancun (MCOPY, TLOAD, TSTORE, ...).
*/
const hardfork = Hardfork.Prague;

/**
* Options for executing a contract call.
*/
Expand Down Expand Up @@ -75,7 +81,7 @@ export class Executor {
constructor() {
const common = new Common({
chain: Mainnet,
hardfork: "shanghai",
hardfork,
});
this.stateManager = new SimpleStateManager();
this.evm = new EVM({
Expand Down Expand Up @@ -299,7 +305,7 @@ export class Executor {
this.evm = new EVM({
common: new Common({
chain: Mainnet,
hardfork: "shanghai",
hardfork,
}),
stateManager: this.stateManager,
});
Expand Down
Loading