diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 79fa6508b5..1e0e3e7bcf 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -43,7 +43,6 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/internal/ethapi" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/predicate" "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -967,8 +966,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc config.BlockOverrides.Apply(&vmctx) // Apply all relevant upgrades from [originalTime] to the block time set in the override. // Should be applied before the state overrides. - predicateBytes := predicate.GetPredicateResultBytes(vmctx.Header.Extra) - blockContext := params.NewBlockContext(vmctx.BlockNumber, vmctx.Time, predicateBytes) + blockContext := params.NewBlockContext(vmctx.BlockNumber, vmctx.Time, vmctx.Header.Extra) err = core.ApplyUpgrades(api.backend.ChainConfig(), &originalTime, blockContext, statedb) if err != nil { return nil, err diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 0e97e3f4c1..ef21c1576c 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -106,16 +106,12 @@ func makePrecompile(contract contract.StatefulPrecompiledContract) libevm.Precom if err != nil { panic(err) // Should never happen } - var predicateResultsBytes []byte - if len(header.Extra) >= DynamicFeeExtraDataSize { - predicateResultsBytes = header.Extra[DynamicFeeExtraDataSize:] - } accessableState := accessableState{ env: env, blockContext: &BlockContext{ - number: env.BlockNumber(), - time: env.BlockTime(), - predicateResultsBytes: predicateResultsBytes, + number: env.BlockNumber(), + time: env.BlockTime(), + extra: header.Extra, }, } return contract.Run(accessableState, env.Addresses().Caller, env.Addresses().Self, input, suppliedGas, env.ReadOnly()) @@ -220,16 +216,16 @@ func (a accessableState) NativeAssetCall(caller common.Address, input []byte, su } type BlockContext struct { - number *big.Int - time uint64 - predicateResultsBytes []byte + number *big.Int + time uint64 + extra []byte } -func NewBlockContext(number *big.Int, time uint64, predicateResultsBytes []byte) *BlockContext { +func NewBlockContext(number *big.Int, time uint64, extra []byte) *BlockContext { return &BlockContext{ - number: number, - time: time, - predicateResultsBytes: predicateResultsBytes, + number: number, + time: time, + extra: extra, } } @@ -241,6 +237,6 @@ func (b *BlockContext) Timestamp() uint64 { return b.time } -func (b *BlockContext) GetPredicateResultsBytes() []byte { - return b.predicateResultsBytes +func (b *BlockContext) Extra() []byte { + return b.extra } diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index 7f0cbb0f12..43af251b89 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -71,9 +71,7 @@ type ConfigurationBlockContext interface { type BlockContext interface { ConfigurationBlockContext - // GetPredicateResults returns an byte array result of verifying the predicates - // of the given block. - GetPredicateResultsBytes() []byte + Extra() []byte // Exta returns the Extra field of the block header } type Configurator interface { diff --git a/precompile/contract/mocks.go b/precompile/contract/mocks.go index 0487154b47..87677d1138 100644 --- a/precompile/contract/mocks.go +++ b/precompile/contract/mocks.go @@ -44,18 +44,18 @@ func (m *MockBlockContext) EXPECT() *MockBlockContextMockRecorder { return m.recorder } -// GetPredicateResultsBytes mocks base method. -func (m *MockBlockContext) GetPredicateResultsBytes() []byte { +// Extra mocks base method. +func (m *MockBlockContext) Extra() []byte { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPredicateResultsBytes") + ret := m.ctrl.Call(m, "Extra") ret0, _ := ret[0].([]byte) return ret0 } -// GetPredicateResultsBytes indicates an expected call of GetPredicateResultsBytes. -func (mr *MockBlockContextMockRecorder) GetPredicateResultsBytes() *gomock.Call { +// Extra indicates an expected call of Extra. +func (mr *MockBlockContextMockRecorder) Extra() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPredicateResultsBytes", reflect.TypeOf((*MockBlockContext)(nil).GetPredicateResultsBytes)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Extra", reflect.TypeOf((*MockBlockContext)(nil).Extra)) } // Number mocks base method. diff --git a/precompile/contracts/warp/contract_test.go b/precompile/contracts/warp/contract_test.go index 27fb00d56f..2260640a36 100644 --- a/precompile/contracts/warp/contract_test.go +++ b/precompile/contracts/warp/contract_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" "github.com/ava-labs/coreth/core/extstate" + "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/precompile/testutils" "github.com/ava-labs/coreth/predicate" @@ -171,7 +172,7 @@ func TestSendWarpMessage(t *testing.T) { testutils.RunPrecompileTests(t, Module, extstate.NewTestStateDB, tests) } -func toResultsBytes(txResults []byte) []byte { +func toExtra(txResults []byte) []byte { results, err := predicate.NewResultsFromMap( map[common.Hash]predicate.TxResults{ common.Hash{}: {ContractAddress: txResults}, @@ -180,7 +181,8 @@ func toResultsBytes(txResults []byte) []byte { if err != nil { panic(err) } - return results + padding := make([]byte, params.DynamicFeeExtraDataSize) + return predicate.SetPredicateResultBytes(padding, results) } func TestGetVerifiedWarpMessage(t *testing.T) { @@ -212,7 +214,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: false, @@ -242,7 +244,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -265,7 +267,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{{}, warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(set.NewBits(0).Bytes())) + mbc.EXPECT().Extra().Return(toExtra(set.NewBits(0).Bytes())) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: false, @@ -295,7 +297,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{{}, warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(set.NewBits(0, 1).Bytes())) + mbc.EXPECT().Extra().Return(toExtra(set.NewBits(0, 1).Bytes())) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -311,7 +313,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { Caller: callerAddr, InputFn: func(t testing.TB) []byte { return getVerifiedWarpMsg }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -330,7 +332,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: true, @@ -353,7 +355,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { Caller: callerAddr, InputFn: func(t testing.TB) []byte { return getVerifiedWarpMsg }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: true, @@ -382,7 +384,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)) - 1, ReadOnly: false, @@ -395,7 +397,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessage.Bytes()}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessage.Bytes())), ReadOnly: false, @@ -408,7 +410,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{predicate.PackPredicate([]byte{1, 2, 3})}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(32), ReadOnly: false, @@ -426,7 +428,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{predicate.PackPredicate(warpMessage.Bytes())}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(160), ReadOnly: false, @@ -493,7 +495,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: false, @@ -522,7 +524,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -545,7 +547,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{{}, warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(set.NewBits(0).Bytes())) + mbc.EXPECT().Extra().Return(toExtra(set.NewBits(0).Bytes())) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: false, @@ -574,7 +576,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{{}, warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(set.NewBits(0, 1).Bytes())) + mbc.EXPECT().Extra().Return(toExtra(set.NewBits(0, 1).Bytes())) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -590,7 +592,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { Caller: callerAddr, InputFn: func(t testing.TB) []byte { return getVerifiedWarpBlockHash }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: false, @@ -609,7 +611,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)), ReadOnly: true, @@ -631,7 +633,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { Caller: callerAddr, InputFn: func(t testing.TB) []byte { return getVerifiedWarpBlockHash }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost, ReadOnly: true, @@ -660,7 +662,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessagePredicateBytes}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessagePredicateBytes)) - 1, ReadOnly: false, @@ -673,7 +675,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{warpMessage.Bytes()}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(len(warpMessage.Bytes())), ReadOnly: false, @@ -686,7 +688,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{predicate.PackPredicate([]byte{1, 2, 3})}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(32), ReadOnly: false, @@ -704,7 +706,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) { state.SetPredicateStorageSlots(ContractAddress, [][]byte{predicate.PackPredicate(warpMessage.Bytes())}) }, SetupBlockContext: func(mbc *contract.MockBlockContext) { - mbc.EXPECT().GetPredicateResultsBytes().Return(toResultsBytes(noFailures)) + mbc.EXPECT().Extra().Return(toExtra(noFailures)) }, SuppliedGas: GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes*uint64(160), ReadOnly: false, diff --git a/precompile/contracts/warp/contract_warp_handler.go b/precompile/contracts/warp/contract_warp_handler.go index 95f268b93a..ddfa11df16 100644 --- a/precompile/contracts/warp/contract_warp_handler.go +++ b/precompile/contracts/warp/contract_warp_handler.go @@ -61,7 +61,8 @@ func handleWarpMessage(accessibleState contract.AccessibleState, input []byte, s warpIndex := int(warpIndexInput) // This conversion is safe even if int is 32 bits because we checked above. state := accessibleState.GetStateDB() predicateBytes, exists := state.GetPredicateStorageSlots(ContractAddress, warpIndex) - predicateResultsBytes := accessibleState.GetBlockContext().GetPredicateResultsBytes() + extra := accessibleState.GetBlockContext().Extra() + predicateResultsBytes := predicate.GetPredicateResultBytes(extra) predicateResults, err := predicate.ParseResults(predicateResultsBytes) if err != nil { // Note this should never occur as the results are parsed in the block header.