Skip to content

Commit

Permalink
tests: revive evm test cases (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 authored Jan 10, 2024
1 parent 5853329 commit 8ed5d24
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 11 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/evm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: EVM Test

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
evm-test:
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: EVM Test
env:
CGO_CFLAGS: "-O -D__BLST_PORTABLE__"
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
ANDROID_HOME: "" # Skip android test
run: |
git submodule update --init --depth 1 --recursive
go mod download
cd tests
sed -i -e 's/\/\/ bt.skipLoad/bt.skipLoad/g' block_test.go
bash -x run-evm-tests.sh
1 change: 0 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
ANDROID_HOME: "" # Skip android test
run: |
git submodule update --init --depth 1 --recursive
go mod download
make test
11 changes: 11 additions & 0 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
)
Expand All @@ -31,6 +32,16 @@ import (
// - gas limit check
// - basefee check
func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Header) error {
if config.Parlia == nil {
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit
if !config.IsLondon(parent.Number) {
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
}
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
return err
}
}
// Verify the header is not malformed
if header.BaseFee == nil {
return errors.New("header is missing baseFee")
Expand Down
8 changes: 8 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func (b *BlockGen) AddUncle(h *types.Header) {
h.GasLimit = parent.GasLimit
if b.config.IsLondon(h.Number) {
h.BaseFee = eip1559.CalcBaseFee(b.config, parent)
if b.config.Parlia == nil && !b.config.IsLondon(parent.Number) {
parentGasLimit := parent.GasLimit * b.config.ElasticityMultiplier()
h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
}
}
b.uncles = append(b.uncles, h)
}
Expand Down Expand Up @@ -386,6 +390,10 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
}
if chain.Config().IsLondon(header.Number) {
header.BaseFee = eip1559.CalcBaseFee(chain.Config(), parent.Header())
if chain.Config().Parlia == nil && !chain.Config().IsLondon(parent.Number()) {
parentGasLimit := parent.GasLimit() * chain.Config().ElasticityMultiplier()
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
}
}
return header
}
Expand Down
8 changes: 4 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,10 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
// Set baseFee and GasLimit if we are on an EIP-1559 chain
if w.chainConfig.IsLondon(header.Number) {
header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent)
// if !w.chainConfig.IsLondon(parent.Number) {
// parentGasLimit := parent.GasLimit * w.chainConfig.ElasticityMultiplier()
// header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
// }
if w.chainConfig.Parlia == nil && !w.chainConfig.IsLondon(parent.Number) {
parentGasLimit := parent.GasLimit * w.chainConfig.ElasticityMultiplier()
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
}
}
// Run the consensus preparation with the default or customized consensus engine.
if err := w.engine.Prepare(w.chain, header); err != nil {
Expand Down
67 changes: 67 additions & 0 deletions tests/0001-diff-go-ethereum.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From a1fe21e9b999b60705b7310737f2b6bbb680969d Mon Sep 17 00:00:00 2001
From: buddh0 <[email protected]>
Date: Mon, 8 Jan 2024 17:16:29 +0800
Subject: [PATCH] diff go-ethereum

---
core/vm/contracts.go | 3 ---
core/vm/jump_table.go | 2 +-
params/protocol_params.go | 8 ++++----
3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/core/vm/contracts.go b/core/vm/contracts.go
index 482c020a6..7d9a59a92 100644
--- a/core/vm/contracts.go
+++ b/core/vm/contracts.go
@@ -78,9 +78,6 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{9}): &blake2F{},
-
- common.BytesToAddress([]byte{100}): &tmHeaderValidate{},
- common.BytesToAddress([]byte{101}): &iavlMerkleProofValidate{},
}

var PrecompiledContractsNano = map[common.Address]PrecompiledContract{
diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go
index 38a0a7653..702b18661 100644
--- a/core/vm/jump_table.go
+++ b/core/vm/jump_table.go
@@ -90,7 +90,7 @@ func newCancunInstructionSet() JumpTable {
}

func newShanghaiInstructionSet() JumpTable {
- instructionSet := newLondonInstructionSet()
+ instructionSet := newMergeInstructionSet()
enable3855(&instructionSet) // PUSH0 instruction
enable3860(&instructionSet) // Limit and meter initcode

diff --git a/params/protocol_params.go b/params/protocol_params.go
index 2b5cf8996..e14a2f414 100644
--- a/params/protocol_params.go
+++ b/params/protocol_params.go
@@ -19,7 +19,7 @@ package params
import "math/big"

const (
- GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations.
+ GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
@@ -122,9 +122,9 @@ const (
// Introduced in Tangerine Whistle (Eip 150)
CreateBySelfdestructGas uint64 = 25000

- DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
- DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
- InitialBaseFee = 0 // Initial base fee for EIP-1559 blocks.
+ DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
+ DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
+ InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.

MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions
--
2.41.0

4 changes: 1 addition & 3 deletions tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ func TestBlockchain(t *testing.T) {
bt.slow(`.*/bcWalletTest/`)

// Very slow test
bt.skipLoad(`^GeneralStateTests/VMTests/vmPerformance/.*`)
bt.skipLoad(`.*/stTimeConsuming/.*`)
// test takes a lot for time and goes easily OOM because of sha3 calculation on a huge range,
// using 4.6 TGas
bt.skipLoad(`.*randomStatetest94.json.*`)

bt.runonly(`^GeneralStateTests/Shanghai`)
bt.runonly(`^Pyspecs/shanghai/eip3.*`)

bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil)); err != nil {
t.Errorf("test in hash mode without snapshotter failed: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion tests/block_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger) er
// Wrap the original engine within the beacon-engine
engine := beacon.New(ethash.NewFaker())

cache := &core.CacheConfig{TrieCleanLimit: 0, StateScheme: scheme}
cache := &core.CacheConfig{TrieCleanLimit: 0, TriesInMemory: 128, StateScheme: scheme}
if snapshotter {
cache.SnapshotLimit = 1
cache.SnapshotWait = true
Expand Down
14 changes: 14 additions & 0 deletions tests/run-evm-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

cd ..
git apply tests/0001-diff-go-ethereum.patch
cd tests
go test -run . -v >test.log
PASS=`cat test.log |grep "PASS:" |wc -l`
cat test.log|grep FAIL > fail.log
FAIL=`cat fail.log |grep "FAIL:" |wc -l`
echo "PASS",$PASS,"FAIL",$FAIL
if [ $FAIL -ne 0 ]
then
cat fail.log
fi
2 changes: 0 additions & 2 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func TestState(t *testing.T) {
st.fails(`stEIP4844-blobtransactions/opcodeBlobhashOutOfRange.json`, "test has incorrect state root")
st.fails(`stEIP4844-blobtransactions/opcodeBlobhBounds.json`, "test has incorrect state root")

st.runonly(`^Shanghai`)

// For Istanbul, older tests were moved into LegacyTests
for _, dir := range []string{
filepath.Join(baseDir, "EIPTests", "StateTests"),
Expand Down

0 comments on commit 8ed5d24

Please sign in to comment.