Skip to content

Commit

Permalink
rebase new libevm
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 27, 2024
1 parent c358ba2 commit 5827f96
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ 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/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]20240926003251-3e6dca4873c2")
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]20240927183738-d8757174b3f0")
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)
Expand Down
4 changes: 2 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (hooks) OverrideNewEVMArgs(args *vm.NewEVMArgs) *vm.NewEVMArgs {
return args
}

func (hooks) OverrideEVMResetArgs(args *vm.EVMResetArgs) *vm.EVMResetArgs {
args.StateDB = wrapStateDB(args.Rules, args.StateDB)
func (hooks) OverrideEVMResetArgs(rules params.Rules, args *vm.EVMResetArgs) *vm.EVMResetArgs {
args.StateDB = wrapStateDB(rules, args.StateDB)
return args
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/ava-labs/go-ethereum v0.0.0-20240926003251-3e6dca4873c2
replace github.com/ethereum/go-ethereum => github.com/ava-labs/go-ethereum v0.0.0-20240927183738-d8757174b3f0

// replace github.com/ethereum/go-ethereum => ../../git2/go-ethereum
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.11.12-rc.2 h1:H1C0gsTOtwMD3qrouEqry0hfoBIC//9lEiDh/AvpaaY=
github.com/ava-labs/avalanchego v1.11.12-rc.2/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8=
github.com/ava-labs/go-ethereum v0.0.0-20240926003251-3e6dca4873c2 h1:61Is8KKjZNglnTZz+oHjz87GfvNk1KSXcHDgMRb5PDQ=
github.com/ava-labs/go-ethereum v0.0.0-20240926003251-3e6dca4873c2/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/ava-labs/go-ethereum v0.0.0-20240927183738-d8757174b3f0 h1:ReturG2I8TilGLZvRdFlNVbFgs0L1Vy4P7rNL8hQkHg=
github.com/ava-labs/go-ethereum v0.0.0-20240927183738-d8757174b3f0/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
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
4 changes: 2 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,11 @@ type RulesExtra struct {
// Rules for Avalanche releases
AvalancheRules

// ActivePrecompiles maps addresses to stateful precompiled contracts that are enabled
// Precompiles maps addresses to stateful precompiled contracts that are enabled
// for this rule set.
// Note: none of these addresses should conflict with the address space used by
// any existing precompiles.
ActivePrecompiles map[common.Address]precompileconfig.Config
Precompiles map[common.Address]precompileconfig.Config
// Predicaters maps addresses to stateful precompile Predicaters
// that are enabled for this rule set.
Predicaters map[common.Address]precompileconfig.Predicater
Expand Down
2 changes: 1 addition & 1 deletion params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (r *RulesExtra) IsPrecompileEnabled(addr common.Address) bool {
if r == nil {
return false
}
_, ok := r.ActivePrecompiles[addr]
_, ok := r.Precompiles[addr]
return ok
}

Expand Down
4 changes: 2 additions & 2 deletions params/config_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func constructRulesExtra(c *gethparams.ChainConfig, r *gethparams.Rules, cEx *Ch
rules.gethrules = *r

// Initialize the stateful precompiles that should be enabled at [blockTimestamp].
rules.ActivePrecompiles = make(map[common.Address]precompileconfig.Config)
rules.Precompiles = make(map[common.Address]precompileconfig.Config)
rules.Predicaters = make(map[common.Address]precompileconfig.Predicater)
rules.AccepterPrecompiles = make(map[common.Address]precompileconfig.Accepter)
for _, module := range modules.RegisteredModules() {
if config := cEx.getActivePrecompileConfig(module.Address, timestamp); config != nil && !config.IsDisabled() {
rules.ActivePrecompiles[module.Address] = config
rules.Precompiles[module.Address] = config
if predicater, ok := config.(precompileconfig.Predicater); ok {
rules.Predicaters[module.Address] = predicater
}
Expand Down
12 changes: 8 additions & 4 deletions params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/libevm"
gethparams "github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
"golang.org/x/exp/maps"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ var PrecompiledContractsBanff = map[common.Address]contract.StatefulPrecompiledC
nativeasset.NativeAssetCallAddr: &nativeasset.DeprecatedContract{},
}

func (r RulesExtra) ExtraPrecompiles() []common.Address {
func (r RulesExtra) ActivePrecompiles(existing []common.Address) []common.Address {
var precompiles map[common.Address]contract.StatefulPrecompiledContract
switch {
case r.IsBanff:
Expand All @@ -76,7 +77,10 @@ func (r RulesExtra) ExtraPrecompiles() []common.Address {
precompiles = PrecompiledContractsApricotPhase2
}

return maps.Keys(precompiles)
var addresses []common.Address
addresses = append(addresses, maps.Keys(precompiles)...)
addresses = append(addresses, existing...)
return addresses
}

// precompileOverrideBuiltin specifies precompiles that were activated prior to the
Expand Down Expand Up @@ -139,7 +143,7 @@ func (r RulesExtra) PrecompileOverride(addr common.Address) (libevm.PrecompiledC
if p, ok := r.precompileOverrideBuiltin(addr); ok {
return p, true
}
if _, ok := r.ActivePrecompiles[addr]; !ok {
if _, ok := r.Precompiles[addr]; !ok {
return nil, false
}
module, ok := modules.GetPrecompileModuleByAddress(addr)
Expand Down Expand Up @@ -211,7 +215,7 @@ func (a accessableState) NativeAssetCall(caller common.Address, input []byte, su
stateDB.SubBalanceMultiCoin(caller, assetID, assetAmount)
stateDB.AddBalanceMultiCoin(to, assetID, assetAmount)

ret, remainingGas, err = a.env.Call(caller, to, callData, remainingGas)
ret, remainingGas, err = a.env.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
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ func (vm *VM) currentRules() params.Rules {
// network must be signed by the primary network validators.
// This is necessary when the subnet is not validating the primary network.
func (vm *VM) requirePrimaryNetworkSigners() bool {
switch c := params.GetRulesExtra(vm.currentRules()).ActivePrecompiles[warpcontract.ContractAddress].(type) {
switch c := params.GetRulesExtra(vm.currentRules()).Precompiles[warpcontract.ContractAddress].(type) {
case *warpcontract.Config:
return c.RequirePrimaryNetworkSigners
default: // includes nil due to non-presence
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +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/ethereum/go-ethereum=github.com/ava-labs/[email protected]20240925235925-a54432f28eed"
go mod edit -replace "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]20240927183738-d8757174b3f0"
go mod tidy

echo "building avalanchego"
Expand Down

0 comments on commit 5827f96

Please sign in to comment.