Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(all): minimal changes for last libevm dependency (1) #785

Closed
wants to merge 5 commits into from
Closed
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
36 changes: 36 additions & 0 deletions core/types/header_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// (c) 2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package types

import (
"io"

ethtypes "github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/rlp"
)

// HeaderExtra is a struct that contains extra fields used by Avalanche
// in the block header.
type HeaderExtra struct {
}

func (h *HeaderExtra) EncodeRLP(eth *ethtypes.Header, writer io.Writer) error {
panic("not implemented")
}

func (h *HeaderExtra) DecodeRLP(eth *ethtypes.Header, stream *rlp.Stream) error {
panic("not implemented")
}

func (h *HeaderExtra) EncodeJSON(eth *ethtypes.Header) ([]byte, error) {
panic("not implemented")
}

func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
panic("not implemented")
}

func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
panic("not implemented")
}
13 changes: 10 additions & 3 deletions core/types/state_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ var (

type isMultiCoin bool

var IsMultiCoinPayloads = ethtypes.RegisterExtras[isMultiCoin]()
var (
extras = ethtypes.RegisterExtras[
ethtypes.NOOPHeaderHooks, *ethtypes.NOOPHeaderHooks,
ethtypes.NOOPBlockBodyHooks, *ethtypes.NOOPBlockBodyHooks,
isMultiCoin,
]()
IsMultiCoinPayloads = extras.StateAccount
)

func IsMultiCoin(a ethtypes.ExtraPayloadCarrier) bool {
return bool(IsMultiCoinPayloads.FromPayloadCarrier(a))
func IsMultiCoin(s ethtypes.StateOrSlimAccount) bool {
return bool(extras.StateAccount.Get(s))
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module github.com/ava-labs/coreth

go 1.22.8
go 1.23

toolchain go1.23.6

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8
github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2
github.com/ava-labs/libevm v1.13.14-0.2.0.rc.3
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set/v2 v2.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8 h1:qN3MOBHB//Ynhgt5Vys3iVe42Sr0EWSeN18VL3ecXzE=
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8/go.mod h1:2B7+E5neLvkOr2zursGhebjU26d4AfB7RazPxBs8hHg=
github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 h1:CVbn0hSsPCl6gCkTCnqwuN4vtJgdVbkCqLXzYAE7qF8=
github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2/go.mod h1:yBctIV/wnxXTF38h95943jvpuk4aj07TrjbpoGor6LQ=
github.com/ava-labs/libevm v1.13.14-0.2.0.rc.3 h1:1CWGo2icnX9dRqGQl7CFywYGIZWxe+ucy0w8NAsVTWE=
github.com/ava-labs/libevm v1.13.14-0.2.0.rc.3/go.mod h1:+Iol+sVQ1KyoBsHf3veyrBmHCXr3xXRWq6ZXkgVfNLU=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
2 changes: 1 addition & 1 deletion nativeasset/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *NativeAssetCall) Run(accessibleState contract.AccessibleState, caller c
stateDB.SubBalanceMultiCoin(caller, assetID, assetAmount)
stateDB.AddBalanceMultiCoin(to, assetID, assetAmount)

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

// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
Expand Down
6 changes: 3 additions & 3 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func SetEthUpgrades(c *ChainConfig) {
}

func GetExtra(c *ChainConfig) *extras.ChainConfig {
ex := payloads.FromChainConfig(c)
ex := payloads.ChainConfig.Get(c)
if ex == nil {
ex = &extras.ChainConfig{}
payloads.SetOnChainConfig(c, ex)
payloads.ChainConfig.Set(c, ex)
}
return ex
}
Expand All @@ -75,7 +75,7 @@ func Copy(c *ChainConfig) ChainConfig {

// WithExtra sets the extra payload on `c` and returns the modified argument.
func WithExtra(c *ChainConfig, extra *extras.ChainConfig) *ChainConfig {
payloads.SetOnChainConfig(c, extra)
payloads.ChainConfig.Set(c, extra)
return c
}

Expand Down
7 changes: 4 additions & 3 deletions params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/vm"
"github.com/ava-labs/libevm/libevm"
"github.com/ava-labs/libevm/libevm/legacy"
"github.com/holiman/uint256"
"golang.org/x/exp/maps"
)

type RulesExtra extras.Rules

func GetRulesExtra(r Rules) *extras.Rules {
rules := payloads.PointerFromRules(&r)
rules := payloads.Rules.GetPointer(&r)
return (*extras.Rules)(rules)
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func makePrecompile(contract contract.StatefulPrecompiledContract) libevm.Precom
}
return contract.Run(accessableState, env.Addresses().Caller, env.Addresses().Self, input, suppliedGas, env.ReadOnly())
}
return vm.NewStatefulPrecompile(run)
return vm.NewStatefulPrecompile(legacy.PrecompiledStatefulContract(run).Upgrade())
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type AccessibleState interface {
GetBlockContext() BlockContext
GetSnowContext() *snow.Context
GetChainConfig() precompileconfig.ChainConfig
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, _ error)
Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, _ error)
}

// ConfigurationBlockContext defines the interface required to configure a precompile.
Expand Down
7 changes: 3 additions & 4 deletions precompile/contract/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/eth-allowed-packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"github.com/ava-labs/libevm/ethdb/pebble"
"github.com/ava-labs/libevm/event"
"github.com/ava-labs/libevm/libevm"
"github.com/ava-labs/libevm/libevm/legacy"
"github.com/ava-labs/libevm/libevm/stateconf"
"github.com/ava-labs/libevm/log"
"github.com/ava-labs/libevm/params"
Expand Down
Loading