Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit fee6168

Browse files
committed
Minimal changes to upgrade libevm
1 parent 1755289 commit fee6168

File tree

12 files changed

+65
-17
lines changed

12 files changed

+65
-17
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,11 @@ func golangBindings(t *testing.T, overload bool) {
21792179
if out, err := replacer.CombinedOutput(); err != nil {
21802180
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
21812181
}
2182+
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/libevm@v0.0.0", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/libevm@v0.0.0-20250113230013-d10c4a3d1ff2")
2183+
replacer.Dir = pkg
2184+
if out, err := replacer.CombinedOutput(); err != nil {
2185+
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
2186+
}
21822187
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.22")
21832188
tidier.Dir = pkg
21842189
if out, err := tidier.CombinedOutput(); err != nil {

core/types/header_ext.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// (c) 2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package types
5+
6+
import (
7+
"io"
8+
9+
ethtypes "github.com/ava-labs/libevm/core/types"
10+
"github.com/ava-labs/libevm/rlp"
11+
)
12+
13+
// HeaderExtra is a struct that contains extra fields used by Avalanche
14+
// in the block header.
15+
type HeaderExtra struct {
16+
}
17+
18+
func (h *HeaderExtra) EncodeRLP(eth *ethtypes.Header, writer io.Writer) error {
19+
panic("not implemented")
20+
}
21+
22+
func (h *HeaderExtra) DecodeRLP(eth *ethtypes.Header, stream *rlp.Stream) error {
23+
panic("not implemented")
24+
}
25+
26+
func (h *HeaderExtra) MarshalJSON(eth *ethtypes.Header) ([]byte, error) {
27+
panic("not implemented")
28+
}
29+
30+
func (h *HeaderExtra) UnmarshalJSON(eth *ethtypes.Header, input []byte) error {
31+
panic("not implemented")
32+
}
33+
34+
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
35+
panic("not implemented")
36+
}

core/types/state_account.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ var (
4646

4747
type isMultiCoin bool
4848

49-
var IsMultiCoinPayloads = ethtypes.RegisterExtras[isMultiCoin]()
49+
var (
50+
extras = ethtypes.RegisterExtras[HeaderExtra, *HeaderExtra, isMultiCoin]()
51+
IsMultiCoinPayloads = extras.StateAccount
52+
)
5053

51-
func IsMultiCoin(a ethtypes.ExtraPayloadCarrier) bool {
52-
return bool(IsMultiCoinPayloads.FromPayloadCarrier(a))
54+
func IsMultiCoin(s ethtypes.StateOrSlimAccount) bool {
55+
return bool(extras.StateAccount.Get(s))
5356
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ require (
135135
gopkg.in/yaml.v3 v3.0.1 // indirect
136136
rsc.io/tmplfunc v0.0.3 // indirect
137137
)
138+
139+
replace github.com/ava-labs/libevm => github.com/ava-labs/libevm v0.0.0-20250207173251-c74b64536061

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
5858
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
5959
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8 h1:qN3MOBHB//Ynhgt5Vys3iVe42Sr0EWSeN18VL3ecXzE=
6060
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8/go.mod h1:2B7+E5neLvkOr2zursGhebjU26d4AfB7RazPxBs8hHg=
61-
github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 h1:CVbn0hSsPCl6gCkTCnqwuN4vtJgdVbkCqLXzYAE7qF8=
62-
github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2/go.mod h1:yBctIV/wnxXTF38h95943jvpuk4aj07TrjbpoGor6LQ=
61+
github.com/ava-labs/libevm v0.0.0-20250207173251-c74b64536061 h1:UnvonzOnq3KF8kyXbavimhbT/FMLuZuGRix2JUPGZQ4=
62+
github.com/ava-labs/libevm v0.0.0-20250207173251-c74b64536061/go.mod h1:M8TCw2g1D5GBB7hu7g1F4aot5bRHGSxnBawNVmHE9Z0=
6363
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
6464
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
6565
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=

nativeasset/contract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *NativeAssetCall) Run(accessibleState contract.AccessibleState, caller c
141141
stateDB.SubBalanceMultiCoin(caller, assetID, assetAmount)
142142
stateDB.AddBalanceMultiCoin(to, assetID, assetAmount)
143143

144-
ret, remainingGas, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying())
144+
ret, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying())
145145

146146
// When an error was returned by the EVM or when setting the creation code
147147
// above we revert to the snapshot and consume any gas remaining. Additionally

params/config_extra.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ func SetEthUpgrades(c *ChainConfig) {
5959
}
6060

6161
func GetExtra(c *ChainConfig) *extras.ChainConfig {
62-
ex := payloads.FromChainConfig(c)
62+
ex := payloads.ChainConfig.Get(c)
6363
if ex == nil {
6464
ex = &extras.ChainConfig{}
65-
payloads.SetOnChainConfig(c, ex)
65+
payloads.ChainConfig.Set(c, ex)
6666
}
6767
return ex
6868
}
@@ -75,7 +75,7 @@ func Copy(c *ChainConfig) ChainConfig {
7575

7676
// WithExtra sets the extra payload on `c` and returns the modified argument.
7777
func WithExtra(c *ChainConfig, extra *extras.ChainConfig) *ChainConfig {
78-
payloads.SetOnChainConfig(c, extra)
78+
payloads.ChainConfig.Set(c, extra)
7979
return c
8080
}
8181

params/hooks_libevm.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
"github.com/ava-labs/libevm/common"
1717
"github.com/ava-labs/libevm/core/vm"
1818
"github.com/ava-labs/libevm/libevm"
19+
"github.com/ava-labs/libevm/libevm/legacy"
1920
"github.com/holiman/uint256"
2021
"golang.org/x/exp/maps"
2122
)
2223

2324
type RulesExtra extras.Rules
2425

2526
func GetRulesExtra(r Rules) *extras.Rules {
26-
rules := payloads.PointerFromRules(&r)
27+
rules := payloads.Rules.GetPointer(&r)
2728
return (*extras.Rules)(rules)
2829
}
2930

@@ -125,7 +126,7 @@ func makePrecompile(contract contract.StatefulPrecompiledContract) libevm.Precom
125126
}
126127
return contract.Run(accessableState, env.Addresses().Caller, env.Addresses().Self, input, suppliedGas, env.ReadOnly())
127128
}
128-
return vm.NewStatefulPrecompile(run)
129+
return vm.NewStatefulPrecompile(legacy.PrecompiledStatefulContract(run).Upgrade())
129130
}
130131

131132
func (r RulesExtra) PrecompileOverride(addr common.Address) (libevm.PrecompiledContract, bool) {
@@ -171,7 +172,7 @@ func (a accessableState) GetSnowContext() *snow.Context {
171172
return GetExtra(a.env.ChainConfig()).SnowCtx
172173
}
173174

174-
func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, _ error) {
175+
func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, err error) {
175176
return a.env.Call(addr, input, gas, value, opts...)
176177
}
177178

precompile/contract/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type AccessibleState interface {
6161
GetBlockContext() BlockContext
6262
GetSnowContext() *snow.Context
6363
GetChainConfig() precompileconfig.ChainConfig
64-
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, _ error)
64+
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, _ error)
6565
}
6666

6767
// ConfigurationBlockContext defines the interface required to configure a precompile.

precompile/contract/mocks.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)