Skip to content

Commit 5c5e395

Browse files
committed
2 parents b4a92df + d2b2e15 commit 5c5e395

23 files changed

+907
-133
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
go_test_short:
2424
env:
25-
FLAKY_REGEX: "ava-labs/libevm/(triedb/pathdb|eth|eth/tracers/js|eth/tracers/logger|accounts/abi/bind|accounts/keystore|eth/downloader|miner|ethclient|ethclient/gethclient|eth/catalyst)$"
25+
FLAKY_REGEX: "ava-labs/libevm/(triedb/pathdb|eth|eth/tracers/js|eth/tracers/logger|eth/tracers/internal/tracetest|accounts/abi/bind|accounts/keystore|eth/downloader|miner|ethclient|ethclient/gethclient|eth/catalyst)$"
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
@@ -43,6 +43,8 @@ jobs:
4343
defaults:
4444
run:
4545
working-directory: ./libevm/tooling
46+
env:
47+
TARGET_BRANCH: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref }}
4648
steps:
4749
- uses: actions/checkout@v4
4850
with:
@@ -51,7 +53,8 @@ jobs:
5153
uses: actions/setup-go@v5
5254
with:
5355
go-version-file: "./libevm/tooling/go.mod"
54-
- run: go test ./...
56+
- run: git branch main origin/main
57+
- run: go test -v ./... --target_branch="${{ env.TARGET_BRANCH }}"
5558

5659
go_generate:
5760
env:

.github/workflows/rename-module.yml

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ name: Rename Go module
33
on:
44
workflow_dispatch:
55
inputs:
6-
source_commit:
7-
description: "Upstream commit on which to base module renaming"
6+
source:
7+
description: "Reference or commit on which to base module renaming"
88
required: true
99
type: string
10-
default: "2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1"
10+
default: "main"
11+
branch:
12+
description: "Branch to which a commit of the changes is pushed; leave blank for auto-naming. If non-existent, the branch is created."
13+
type: string
14+
default: ""
1115

1216
jobs:
1317
rename-module:
@@ -17,71 +21,97 @@ jobs:
1721
with:
1822
fetch-depth: 0 # everything
1923

24+
- run: git fetch --tags https://github.com/ethereum/go-ethereum.git
25+
26+
- run: git checkout ${{ inputs.source }}
27+
28+
- name: References pointing to source
29+
# NOTE: This step assumes that the source has been checked out, which
30+
# might not hold if reordered.
31+
run: |
32+
git branch --points-at HEAD;
33+
git tag --points-at HEAD;
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version-file: "go.mod"
39+
40+
- name: Detect Go module
41+
id: go
42+
run: |
43+
echo "MODULE=$(go list -m)" >> "$GITHUB_OUTPUT";
44+
echo "MODULE_SUFFIX=$(go list -m | cut -b 12-)" >> "$GITHUB_OUTPUT"; # Strip github.com/
45+
46+
- name: Validate Go module
47+
if: ${{ steps.go.outputs.MODULE != 'github.com/ava-labs/libevm' && steps.go.outputs.MODULE != 'github.com/ethereum/go-ethereum' }}
48+
run: echo "Unexpected Go module ${{ steps.go.outputs.MODULE }}" && exit 1;
49+
2050
- name: Set variables
2151
id: vars
22-
# Including hashes of both the source commit and the workflow file makes
23-
# this idempotent.
2452
env:
25-
WORKFLOW_HASH: ${{ hashFiles('.github/workflows/rename-module.yml') }}
53+
# `cond && ifTrue || ifFalse` is effectively a ternary operator, based on short-circuiting Boolean logic (assumes `ifTrue` is truthy)
54+
RENAME_TO: ${{ steps.go.outputs.MODULE_SUFFIX == 'ava-labs/libevm' && 'ethereum/go-ethereum' || 'ava-labs/libevm' }}
2655
run: |
56+
echo "RENAME_FROM=${{ steps.go.outputs.MODULE_SUFFIX}}" >> "$GITHUB_OUTPUT";
57+
echo "RENAME_TO=${RENAME_TO}" >> "$GITHUB_OUTPUT";
2758
echo "WORKFLOW_HASH=${WORKFLOW_HASH}" >> "$GITHUB_OUTPUT";
28-
echo "DEST_BRANCH=auto-rename-module_source-${{ inputs.source_commit }}_workflow-${WORKFLOW_HASH}-${{ github.ref_name }}" \
59+
echo "SOURCE_COMMIT=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT";
60+
echo "AUTO_BRANCH_NAME=auto/rename-module/to=${RENAME_TO}/src=$(git rev-parse HEAD)/workflow_sha=${{ github.workflow_sha }}/run=${{ github.run_id }}" \
2961
>> "$GITHUB_OUTPUT";
3062
31-
- name: Fetch tags from ethereum/go-ethereum
32-
run: git fetch --tags https://github.com/ethereum/go-ethereum.git
33-
34-
- name: Tags pointing to source commit
35-
run: git tag --points-at ${{ inputs.source_commit }}
36-
37-
- name: Check out source commit
38-
run: git checkout ${{ inputs.source_commit }}
39-
40-
- name: Globally update module name
63+
- name: Globally rename module from ${{ steps.vars.outputs.RENAME_FROM }} to ${{ steps.vars.outputs.RENAME_TO }}
4164
run: |
42-
go mod edit -module github.com/ava-labs/libevm;
65+
go mod edit -module github.com/${{ steps.vars.outputs.RENAME_TO }};
4366
find . \
4467
-iname '*.go' \
4568
-o -iname '*.txt' \
4669
-o -iname '*.go.tpl' \
47-
-o -iname '*.proto' | xargs \
48-
sed -i -E 's|(["`]github\.com/)ethereum/go-ethereum|\1ava-labs/libevm|g';
70+
-o -iname '*.proto' \
71+
-not -wholename '*/libevm/tooling/*' | xargs \
72+
sed -i -E 's|(["`]github\.com/)${{ steps.vars.outputs.RENAME_FROM }}|\1${{ steps.vars.outputs.RENAME_TO }}|g';
4973
5074
- name: Remnant references
5175
run: |
5276
find . -type f | \
53-
xargs grep -In github.com/ethereum/go-ethereum | \
54-
grep -v "https://github.com/ethereum/go-ethereum"
55-
56-
- name: Set up Go
57-
uses: actions/setup-go@v5
58-
with:
59-
go-version-file: "go.mod"
77+
xargs grep -In github.com/${{ steps.vars.outputs.RENAME_FROM }} | \
78+
grep -v "https://github.com/${{ steps.vars.outputs.RENAME_FROM }}"
6079
6180
- name: Smoke tests
62-
# `go list` shows us the module name and grep will non-zero exit on mismatch
81+
# `go list -m` shows us the module name and grep will non-zero exit on mismatch
6382
# `go build` is a rudimentary but broad test of correctness
6483
# The explicitly tested packages are edge cases:
6584
# - bind generates tests and a go.mod on the fly
6685
# - rlpgen has testdata with imports that need updating
6786
run: |
68-
go list . | grep ava-labs/libevm;
87+
go list -m | grep github.com/${{ steps.vars.outputs.RENAME_TO }};
6988
go build ./...;
7089
go test ./accounts/abi/bind ./rlp/rlpgen
7190
72-
- name: Create new branch
91+
- name: Set branch name
92+
id: branch
7393
env:
74-
BRANCH: ${{ steps.vars.outputs.DEST_BRANCH }}
94+
BRANCH: ${{ inputs.branch || steps.vars.outputs.AUTO_BRANCH_NAME }}
95+
run: echo "NAME=${BRANCH}" >> "$GITHUB_OUTPUT";
96+
97+
- name: Check out branch (create if non-existent)
98+
env:
99+
BRANCH: ${{ steps.branch.outputs.NAME }}
75100
run: |
76-
git checkout -b "${BRANCH}";
77-
git push origin "${BRANCH}";
101+
git checkout "${BRANCH}" 2>/dev/null || \
102+
(git checkout -b "${BRANCH}" && git push origin "${BRANCH}");
78103
79-
- name: Commit to new branch
104+
- name: Commit to branch
80105
uses: planetscale/ghcommit-action@d4176bfacef926cc2db351eab20398dfc2f593b5 # v0.2.0
81106
env:
82107
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
83108
with:
84109
# WARNING: mirror any change to the commit_message value below in libevm-delta.yml
85-
commit_message: "[AUTO] rename Go module + update internal import paths\n\nWorkflow: ${{ steps.vars.outputs.WORKFLOW_HASH }} on branch ${{ github.ref_name }}"
110+
commit_message: |
111+
[AUTO] rename Go module to ${{ steps.vars.outputs.RENAME_TO }}
112+
113+
Source: ${{ steps.vars.outputs.SOURCE_COMMIT }} (${{ inputs.source }})
114+
Workflow: ${{ github.workflow_sha }} (${{ github.workflow_ref }})
115+
Run ID: ${{ github.run_id }}
86116
repo: ${{ github.repository }}
87-
branch: ${{ steps.vars.outputs.DEST_BRANCH }}
117+
branch: ${{ steps.branch.outputs.NAME }}

core/state_transition.libevm.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@
1616

1717
package core
1818

19+
import (
20+
"github.com/ava-labs/libevm/log"
21+
)
22+
1923
// canExecuteTransaction is a convenience wrapper for calling the
2024
// [params.RulesHooks.CanExecuteTransaction] hook.
2125
func (st *StateTransition) canExecuteTransaction() error {
2226
bCtx := st.evm.Context
2327
rules := st.evm.ChainConfig().Rules(bCtx.BlockNumber, bCtx.Random != nil, bCtx.Time)
24-
return rules.Hooks().CanExecuteTransaction(st.msg.From, st.msg.To, st.state)
28+
if err := rules.Hooks().CanExecuteTransaction(st.msg.From, st.msg.To, st.state); err != nil {
29+
log.Debug(
30+
"Transaction execution blocked by libevm hook",
31+
"from", st.msg.From,
32+
"to", st.msg.To,
33+
"hooks", log.TypeOf(rules.Hooks()),
34+
"reason", err,
35+
)
36+
return err
37+
}
38+
return nil
2539
}

core/types/rlp_payload.libevm.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ava-labs/libevm/libevm/pseudo"
2424
"github.com/ava-labs/libevm/libevm/register"
2525
"github.com/ava-labs/libevm/libevm/testonly"
26+
"github.com/ava-labs/libevm/log"
2627
"github.com/ava-labs/libevm/rlp"
2728
)
2829

@@ -84,6 +85,12 @@ func RegisterExtras[
8485
newStateAccount: pseudo.NewConstructor[SA]().Zero,
8586
hooks: extra,
8687
})
88+
log.Info(
89+
"Registered core/types extras",
90+
"Header", log.TypeOf(pseudo.Zero[HPtr]().Value.Get()),
91+
"Block/Body", log.TypeOf(pseudo.Zero[BPtr]().Value.Get()),
92+
"StateAccount", log.TypeOf(pseudo.Zero[SA]().Value.Get()),
93+
)
8794
return extra
8895
}
8996

core/vm/contracts.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ func init() {
148148
}
149149

150150
// ActivePrecompiles returns the precompiles enabled with the current configuration.
151-
func ActivePrecompiles(rules params.Rules) (active []common.Address) {
152-
defer func() {
153-
active = rules.Hooks().ActivePrecompiles(append([]common.Address{}, active...))
154-
}()
151+
func activePrecompiles(rules params.Rules) []common.Address {
155152
switch {
156153
case rules.IsCancun:
157154
return PrecompiledAddressesCancun

core/vm/contracts.libevm.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,42 @@ import (
2121
"math/big"
2222

2323
"github.com/holiman/uint256"
24+
"golang.org/x/exp/slog"
2425

2526
"github.com/ava-labs/libevm/common"
2627
"github.com/ava-labs/libevm/core/types"
2728
"github.com/ava-labs/libevm/libevm"
29+
"github.com/ava-labs/libevm/libevm/set"
30+
"github.com/ava-labs/libevm/log"
2831
"github.com/ava-labs/libevm/params"
2932
)
3033

34+
// ActivePrecompiles returns the precompiles enabled with the current configuration.
35+
func ActivePrecompiles(rules params.Rules) []common.Address {
36+
orig := activePrecompiles(rules) // original, upstream implementation
37+
active := rules.Hooks().ActivePrecompiles(append([]common.Address{}, orig...))
38+
39+
// As all set computation is done lazily and only when debugging, there is
40+
// some duplication in favour of simplified code.
41+
log.Debug(
42+
"Overriding active precompiles",
43+
"added", log.Lazy(func() slog.Value {
44+
diff := set.From(active...).Sub(set.From(orig...))
45+
return slog.AnyValue(diff.Slice())
46+
}),
47+
"removed", log.Lazy(func() slog.Value {
48+
diff := set.From(orig...).Sub(set.From(active...))
49+
return slog.AnyValue(diff.Slice())
50+
}),
51+
"unchanged", log.Lazy(func() slog.Value {
52+
both := set.From(active...).Intersect(set.From(orig...))
53+
return slog.AnyValue(both.Slice())
54+
}),
55+
)
56+
57+
return active
58+
}
59+
3160
// evmCallArgs mirrors the parameters of the [EVM] methods Call(), CallCode(),
3261
// DelegateCall() and StaticCall(). Its fields are identical to those of the
3362
// parameters, prepended with the receiver name and call type. As

core/vm/evm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/ava-labs/libevm/common"
2424
"github.com/ava-labs/libevm/core/types"
2525
"github.com/ava-labs/libevm/crypto"
26-
"github.com/ava-labs/libevm/libevm"
26+
"github.com/ava-labs/libevm/log"
2727
"github.com/ava-labs/libevm/params"
2828
"github.com/holiman/uint256"
2929
)
@@ -40,6 +40,7 @@ type (
4040

4141
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4242
if p, override := evm.chainRules.Hooks().PrecompileOverride(addr); override {
43+
log.Debug("Overriding precompile", "address", addr, "implementation", log.TypeOf(p))
4344
return p, p != nil
4445
}
4546
var precompiles map[common.Address]PrecompiledContract
@@ -459,8 +460,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
459460
// This check MUST be placed after the caller's nonce is incremented but
460461
// before all other state-modifying behaviour, even if changes may be
461462
// reverted to the snapshot.
462-
addrs := &libevm.AddressContext{Origin: evm.Origin, Caller: caller.Address(), Self: address}
463-
gas, err := evm.chainRules.Hooks().CanCreateContract(addrs, gas, evm.StateDB)
463+
gas, err := evm.canCreateContract(caller, address, gas)
464464
if err != nil {
465465
return nil, common.Address{}, gas, err
466466
}

core/vm/evm.libevm.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2025 the libevm authors.
2+
//
3+
// The libevm additions to go-ethereum are free software: you can redistribute
4+
// them and/or modify them under the terms of the GNU Lesser General Public License
5+
// as published by the Free Software Foundation, either version 3 of the License,
6+
// or (at your option) any later version.
7+
//
8+
// The libevm additions are distributed in the hope that they will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
11+
// General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Lesser General Public License
14+
// along with the go-ethereum library. If not, see
15+
// <http://www.gnu.org/licenses/>.
16+
17+
package vm
18+
19+
import (
20+
"github.com/ava-labs/libevm/common"
21+
"github.com/ava-labs/libevm/libevm"
22+
"github.com/ava-labs/libevm/log"
23+
)
24+
25+
// canCreateContract is a convenience wrapper for calling the
26+
// [params.RulesHooks.CanCreateContract] hook.
27+
func (evm *EVM) canCreateContract(caller ContractRef, contractToCreate common.Address, gas uint64) (remainingGas uint64, _ error) {
28+
addrs := &libevm.AddressContext{Origin: evm.Origin, Caller: caller.Address(), Self: contractToCreate}
29+
gas, err := evm.chainRules.Hooks().CanCreateContract(addrs, gas, evm.StateDB)
30+
31+
// NOTE that this block only performs logging and that all paths propagate
32+
// `(gas, err)` unmodified.
33+
if err != nil {
34+
log.Debug(
35+
"Contract creation blocked by libevm hook",
36+
"origin", addrs.Origin,
37+
"caller", addrs.Caller,
38+
"contract", addrs.Self,
39+
"hooks", log.TypeOf(evm.chainRules.Hooks()),
40+
"reason", err,
41+
)
42+
}
43+
44+
return gas, err
45+
}

0 commit comments

Comments
 (0)