diff --git a/core/blockchain.go b/core/blockchain.go index ad2613079..2dc578056 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -29,7 +29,6 @@ import ( "sync/atomic" "time" - "github.com/google/uuid" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/common/mclock" @@ -50,6 +49,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" + "github.com/google/uuid" ) var ( @@ -2498,7 +2498,7 @@ func (bc *BlockChain) SetBlockValidatorAndProcessorForTesting(v Validator, p Pro func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Address, expectedProfit *big.Int, registeredGasLimit uint64, vmConfig vm.Config, start time.Time, requestId uuid.UUID) error { header := block.Header() if err := bc.engine.VerifyHeader(bc, header, true); err != nil { - log.Debug("VerifyHeader failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) + log.Debug("VerifyHeader failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) return err } else { log.Debug("VerifyHeader succeeded", "time_elapsed", time.Since(start), "requestId", requestId) @@ -2515,7 +2515,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad parent := bc.GetHeader(block.ParentHash(), block.NumberU64()-1) if parent == nil { - log.Debug("GetHeader(Parent) failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) + log.Debug("GetHeader(Parent) failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) return errors.New("parent not found") } else { log.Debug("GetHeader(Parent) succeeded", "time_elapsed", time.Since(start), "requestId", requestId) @@ -2553,7 +2553,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad log.Debug("Execute transactions succeeded", "time_elapsed", time.Since(start), "requestId", requestId) } - err = nil; + err = nil if bc.Config().IsShanghai(header.Time) { if header.WithdrawalsHash == nil { err = fmt.Errorf("withdrawals hash is missing") @@ -2569,12 +2569,11 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad } if err != nil { log.Debug("Check Withdrawal hash failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) - return err; + return err } else { log.Debug("Check Withdrawal hash succeeded", "time_elapsed", time.Since(start), "requestId", requestId) } - if err := bc.validator.ValidateBody(block); err != nil { log.Debug("ValidateBody failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) return err @@ -2593,7 +2592,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad balanceAfter := statedb.GetBalance(feeRecipient) feeRecipientDiff := new(big.Int).Sub(balanceAfter, balanceBefore) - err = CheckProposerPayment(expectedProfit, feeRecipient,feeRecipientDiff, receipts, block) + err = CheckProposerPayment(expectedProfit, feeRecipient, feeRecipientDiff, receipts, block) if err != nil { log.Debug("CheckProposerPayment failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) return err diff --git a/eth/block-validation/api.go b/eth/block-validation/api.go index 58baf9004..7295ee671 100644 --- a/eth/block-validation/api.go +++ b/eth/block-validation/api.go @@ -15,9 +15,9 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" - "github.com/google/uuid" boostTypes "github.com/flashbots/go-boost-utils/types" + "github.com/google/uuid" ) // Register adds catalyst APIs to the full node. @@ -92,8 +92,6 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV return nil } - - type BuilderBlockValidationRequestV2 struct { capellaapi.SubmitBlockRequest RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` @@ -140,7 +138,6 @@ func CompareMessageAndBlock(params *BuilderBlockValidationRequestV2, block *type return nil } - func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockValidationRequestV2) error { start := time.Now() requestId := uuid.New() @@ -187,4 +184,3 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockV log.Info("validated block", "hash", block.Hash(), "number", block.NumberU64(), "parentHash", block.ParentHash(), "time_elapsed", time.Since(start), "requestId", requestId) return nil } - diff --git a/eth/block-validation/api_test.go b/eth/block-validation/api_test.go index eb3d487cf..d1fdcac77 100644 --- a/eth/block-validation/api_test.go +++ b/eth/block-validation/api_test.go @@ -1,7 +1,6 @@ package blockvalidation import ( - "encoding/json" "errors" "math/big" "os" @@ -25,7 +24,6 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/ethconfig" - "github.com/ethereum/go-ethereum/eth/tracers/logger" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" @@ -59,7 +57,7 @@ func TestValidateBuilderSubmissionV1(t *testing.T) { ethservice.Merger().ReachTTD() defer n.Close() - api := NewBlockValidationAPI(ethservice, nil) + api := NewBlockValidationAPI(ethservice) parent := preMergeBlocks[len(preMergeBlocks)-1] api.eth.APIBackend.Miner().SetEtherbase(testValidatorAddr) @@ -123,25 +121,6 @@ func TestValidateBuilderSubmissionV1(t *testing.T) { blockRequest.ExecutionPayload.GasLimit -= 1 updatePayloadHash(t, blockRequest) - // TODO: test with contract calling blacklisted address - // Test tx from blacklisted address - api.accessVerifier = &AccessVerifier{ - blacklistedAddresses: map[common.Address]struct{}{ - testAddr: {}, - }, - } - require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "transaction from blacklisted address 0x71562b71999873DB5b286dF957af199Ec94617F7") - - // Test tx to blacklisted address - api.accessVerifier = &AccessVerifier{ - blacklistedAddresses: map[common.Address]struct{}{ - {0x16}: {}, - }, - } - require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "transaction to blacklisted address 0x1600000000000000000000000000000000000000") - - api.accessVerifier = nil - blockRequest.Message.GasUsed = 10 require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "incorrect GasUsed 10, expected 119990") blockRequest.Message.GasUsed = execData.GasUsed @@ -173,7 +152,7 @@ func TestValidateBuilderSubmissionV2(t *testing.T) { ethservice.Merger().ReachTTD() defer n.Close() - api := NewBlockValidationAPI(ethservice, nil) + api := NewBlockValidationAPI(ethservice) parent := preMergeBlocks[len(preMergeBlocks)-1] api.eth.APIBackend.Miner().SetEtherbase(testValidatorAddr) @@ -256,25 +235,6 @@ func TestValidateBuilderSubmissionV2(t *testing.T) { blockRequest.ExecutionPayload.GasLimit -= 1 updatePayloadHashV2(t, blockRequest) - // TODO: test with contract calling blacklisted address - // Test tx from blacklisted address - api.accessVerifier = &AccessVerifier{ - blacklistedAddresses: map[common.Address]struct{}{ - testAddr: {}, - }, - } - require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "transaction from blacklisted address 0x71562b71999873DB5b286dF957af199Ec94617F7") - - // Test tx to blacklisted address - api.accessVerifier = &AccessVerifier{ - blacklistedAddresses: map[common.Address]struct{}{ - {0x16}: {}, - }, - } - require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "transaction to blacklisted address 0x1600000000000000000000000000000000000000") - - api.accessVerifier = nil - blockRequest.Message.GasUsed = 10 require.ErrorContains(t, api.ValidateBuilderSubmissionV2(blockRequest), "incorrect GasUsed 10, expected 119996") blockRequest.Message.GasUsed = execData.GasUsed @@ -394,48 +354,6 @@ func assembleBlock(api *BlockValidationAPI, parentHash common.Hash, params *engi return nil, errors.New("payload did not resolve") } -func TestBlacklistLoad(t *testing.T) { - file, err := os.CreateTemp(".", "blacklist") - require.NoError(t, err) - defer os.Remove(file.Name()) - - av, err := NewAccessVerifierFromFile(file.Name()) - require.Error(t, err) - require.Nil(t, av) - - ba := BlacklistedAddresses{common.Address{0x13}, common.Address{0x14}} - bytes, err := json.MarshalIndent(ba, "", " ") - require.NoError(t, err) - err = os.WriteFile(file.Name(), bytes, 0644) - require.NoError(t, err) - - av, err = NewAccessVerifierFromFile(file.Name()) - require.NoError(t, err) - require.NotNil(t, av) - require.EqualValues(t, av.blacklistedAddresses, map[common.Address]struct{}{ - {0x13}: {}, - {0x14}: {}, - }) - - require.NoError(t, av.verifyTraces(logger.NewAccessListTracer(nil, common.Address{}, common.Address{}, nil))) - - acl := types.AccessList{ - types.AccessTuple{ - Address: common.Address{0x14}, - }, - } - tracer := logger.NewAccessListTracer(acl, common.Address{}, common.Address{}, nil) - require.ErrorContains(t, av.verifyTraces(tracer), "blacklisted address 0x1400000000000000000000000000000000000000 in execution trace") - - acl = types.AccessList{ - types.AccessTuple{ - Address: common.Address{0x15}, - }, - } - tracer = logger.NewAccessListTracer(acl, common.Address{}, common.Address{}, nil) - require.NoError(t, av.verifyTraces(tracer)) -} - func ExecutableDataToExecutionPayload(data *engine.ExecutableData) (*boostTypes.ExecutionPayload, error) { transactionData := make([]hexutil.Bytes, len(data.Transactions)) for i, tx := range data.Transactions {