Skip to content

Commit

Permalink
chore(all): minimal changes for last libevm dependency
Browse files Browse the repository at this point in the history
- Uses tip of main libevm dependency + cherry picked commit: ava-labs/libevm@d3f6a5e
- Precompile legacy gas fix (done in ava-labs/libevm@f906679)
- Added `HeaderExtra` not-implemented implementation
- Minimal changes shamelessly copied over from #746
  • Loading branch information
qdm12 committed Feb 10, 2025
1 parent 1465dc2 commit ab19679
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 17 deletions.
5 changes: 5 additions & 0 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,11 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/[email protected]", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]")
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.22")
tidier.Dir = pkg
if out, err := tidier.CombinedOutput(); err != nil {
Expand Down
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) MarshalJSON(eth *ethtypes.Header) ([]byte, error) {
panic("not implemented")
}

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

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

type isMultiCoin bool

var IsMultiCoinPayloads = ethtypes.RegisterExtras[isMultiCoin]()
var (
extras = ethtypes.RegisterExtras[ethtypes.NOOPHeaderHooks, *ethtypes.NOOPHeaderHooks, 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))
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ava-labs/libevm => github.com/ava-labs/libevm v0.0.0-20250210135835-d3f6a5e75e05
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 v0.0.0-20250210135835-d3f6a5e75e05 h1:LzpeCE04Opu8tepYoA1xxdWCYZI7J0etGcBAzABt6j0=
github.com/ava-labs/libevm v0.0.0-20250210135835-d3f6a5e75e05/go.mod h1:M8TCw2g1D5GBB7hu7g1F4aot5bRHGSxnBawNVmHE9Z0=
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
1 change: 1 addition & 0 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}"

echo "updating coreth dependency to point to ${CORETH_PATH}"
go mod edit -replace "github.com/ava-labs/coreth=${CORETH_PATH}"
go mod edit -replace "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]"
go mod tidy

echo "building avalanchego"
Expand Down

0 comments on commit ab19679

Please sign in to comment.