Skip to content

Commit 0c44b87

Browse files
michaelneuderneraty
authored andcommitted
remove black listing and add fee recipient diff checking
Squashed from michaelneuder/builder#2
1 parent e311c80 commit 0c44b87

File tree

4 files changed

+22
-154
lines changed

4 files changed

+22
-154
lines changed

builder/service.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error {
156156

157157
var validator *blockvalidation.BlockValidationAPI
158158
if cfg.DryRun {
159-
var accessVerifier *blockvalidation.AccessVerifier
160-
if cfg.ValidationBlocklist != "" {
161-
accessVerifier, err = blockvalidation.NewAccessVerifierFromFile(cfg.ValidationBlocklist)
162-
if err != nil {
163-
return fmt.Errorf("failed to load validation blocklist %w", err)
164-
}
165-
}
166-
validator = blockvalidation.NewBlockValidationAPI(backend, accessVerifier)
159+
validator = blockvalidation.NewBlockValidationAPI(backend)
167160
}
168161

169162
// TODO: move to proper flags

cmd/geth/config.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
173173
// Configure log filter RPC API.
174174
filterSystem := utils.RegisterFilterAPI(stack, backend, &cfg.Eth)
175175

176-
bvConfig := blockvalidationapi.BlockValidationConfig{}
177-
if ctx.IsSet(utils.BuilderBlockValidationBlacklistSourceFilePath.Name) {
178-
bvConfig.BlacklistSourceFilePath = ctx.String(utils.BuilderBlockValidationBlacklistSourceFilePath.Name)
179-
}
180-
181-
if err := blockvalidationapi.Register(stack, eth, bvConfig); err != nil {
176+
if err := blockvalidationapi.Register(stack, eth); err != nil {
182177
utils.Fatalf("Failed to register the Block Validation API: %v", err)
183178
}
184179

core/blockchain.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,6 +2502,8 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
25022502
// and dangling prefetcher, without defering each and holding on live refs.
25032503
defer statedb.StopPrefetcher()
25042504

2505+
balanceBefore := statedb.GetBalance(feeRecipient)
2506+
25052507
receipts, _, usedGas, err := bc.processor.Process(block, statedb, vmConfig)
25062508
if err != nil {
25072509
return err
@@ -2515,6 +2517,17 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
25152517
return err
25162518
}
25172519

2520+
// First just check the balance delta to see if it matches.
2521+
balanceAfter := statedb.GetBalance(feeRecipient)
2522+
feeRecipientDiff := new(big.Int).Sub(balanceAfter, balanceBefore)
2523+
2524+
// If diff is sufficiently large, just return success.
2525+
if feeRecipientDiff.Cmp(expectedProfit) >= 0 {
2526+
return nil
2527+
}
2528+
log.Warn(fmt.Sprintf("fee recipient diff %s is less than expected %s. checking for last transaction", feeRecipientDiff.String(), expectedProfit.String()))
2529+
2530+
// Flashbots logic for last transaction checks.
25182531
if len(receipts) == 0 {
25192532
return errors.New("no proposer payment receipt")
25202533
}

eth/block-validation/api.go

Lines changed: 7 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"math/big"
8-
"os"
97

108
capellaapi "github.com/attestantio/go-builder-client/api/capella"
119
"github.com/attestantio/go-eth2-client/spec/phase0"
1210
"github.com/ethereum/go-ethereum/beacon/engine"
1311
"github.com/ethereum/go-ethereum/common"
1412
"github.com/ethereum/go-ethereum/core/types"
15-
"github.com/ethereum/go-ethereum/core/vm"
1613
"github.com/ethereum/go-ethereum/eth"
17-
"github.com/ethereum/go-ethereum/eth/tracers/logger"
1814
"github.com/ethereum/go-ethereum/log"
1915
"github.com/ethereum/go-ethereum/node"
2016
"github.com/ethereum/go-ethereum/rpc"
@@ -23,50 +19,6 @@ import (
2319
boostTypes "github.com/flashbots/go-boost-utils/types"
2420
)
2521

26-
type BlacklistedAddresses []common.Address
27-
28-
type AccessVerifier struct {
29-
blacklistedAddresses map[common.Address]struct{}
30-
}
31-
32-
func (a *AccessVerifier) verifyTraces(tracer *logger.AccessListTracer) error {
33-
log.Trace("x", "tracer.AccessList()", tracer.AccessList())
34-
for _, accessTuple := range tracer.AccessList() {
35-
// TODO: should we ignore common.Address{}?
36-
if _, found := a.blacklistedAddresses[accessTuple.Address]; found {
37-
log.Info("bundle accesses blacklisted address", "address", accessTuple.Address)
38-
return fmt.Errorf("blacklisted address %s in execution trace", accessTuple.Address.String())
39-
}
40-
}
41-
42-
return nil
43-
}
44-
45-
func (a *AccessVerifier) isBlacklisted(addr common.Address) error {
46-
if _, present := a.blacklistedAddresses[addr]; present {
47-
return fmt.Errorf("transaction from blacklisted address %s", addr.String())
48-
}
49-
return nil
50-
}
51-
52-
func (a *AccessVerifier) verifyTransactions(signer types.Signer, txs types.Transactions) error {
53-
for _, tx := range txs {
54-
from, err := signer.Sender(tx)
55-
if err == nil {
56-
if _, present := a.blacklistedAddresses[from]; present {
57-
return fmt.Errorf("transaction from blacklisted address %s", from.String())
58-
}
59-
}
60-
to := tx.To()
61-
if to != nil {
62-
if _, present := a.blacklistedAddresses[*to]; present {
63-
return fmt.Errorf("transaction to blacklisted address %s", to.String())
64-
}
65-
}
66-
}
67-
return nil
68-
}
69-
7022
func verifyWithdrawals(withdrawals types.Withdrawals, expectedWithdrawalsRoot common.Hash, isShanghai bool) error {
7123
if !isShanghai {
7224
// Reject payload attributes with withdrawals before shanghai
@@ -83,62 +35,26 @@ func verifyWithdrawals(withdrawals types.Withdrawals, expectedWithdrawalsRoot co
8335
return nil
8436
}
8537

86-
func NewAccessVerifierFromFile(path string) (*AccessVerifier, error) {
87-
bytes, err := os.ReadFile(path)
88-
if err != nil {
89-
return nil, err
90-
}
91-
92-
var ba BlacklistedAddresses
93-
if err := json.Unmarshal(bytes, &ba); err != nil {
94-
return nil, err
95-
}
96-
97-
blacklistedAddresses := make(map[common.Address]struct{}, len(ba))
98-
for _, address := range ba {
99-
blacklistedAddresses[address] = struct{}{}
100-
}
101-
102-
return &AccessVerifier{
103-
blacklistedAddresses: blacklistedAddresses,
104-
}, nil
105-
}
106-
107-
type BlockValidationConfig struct {
108-
BlacklistSourceFilePath string
109-
}
110-
11138
// Register adds catalyst APIs to the full node.
112-
func Register(stack *node.Node, backend *eth.Ethereum, cfg BlockValidationConfig) error {
113-
var accessVerifier *AccessVerifier
114-
if cfg.BlacklistSourceFilePath != "" {
115-
var err error
116-
accessVerifier, err = NewAccessVerifierFromFile(cfg.BlacklistSourceFilePath)
117-
if err != nil {
118-
return err
119-
}
120-
}
121-
39+
func Register(stack *node.Node, backend *eth.Ethereum) error {
12240
stack.RegisterAPIs([]rpc.API{
12341
{
12442
Namespace: "flashbots",
125-
Service: NewBlockValidationAPI(backend, accessVerifier),
43+
Service: NewBlockValidationAPI(backend),
12644
},
12745
})
12846
return nil
12947
}
13048

13149
type BlockValidationAPI struct {
132-
eth *eth.Ethereum
133-
accessVerifier *AccessVerifier
50+
eth *eth.Ethereum
13451
}
13552

13653
// NewConsensusAPI creates a new consensus api for the given backend.
13754
// The underlying blockchain needs to have a valid terminal total difficulty set.
138-
func NewBlockValidationAPI(eth *eth.Ethereum, accessVerifier *AccessVerifier) *BlockValidationAPI {
55+
func NewBlockValidationAPI(eth *eth.Ethereum) *BlockValidationAPI {
13956
return &BlockValidationAPI{
140-
eth: eth,
141-
accessVerifier: accessVerifier,
57+
eth: eth,
14258
}
14359
}
14460

@@ -179,37 +95,12 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV1(params *BuilderBlockV
17995
feeRecipient := common.BytesToAddress(params.Message.ProposerFeeRecipient[:])
18096
expectedProfit := params.Message.Value.BigInt()
18197

182-
var vmconfig vm.Config
183-
var tracer *logger.AccessListTracer = nil
184-
if api.accessVerifier != nil {
185-
if err := api.accessVerifier.isBlacklisted(block.Coinbase()); err != nil {
186-
return err
187-
}
188-
if err := api.accessVerifier.isBlacklisted(feeRecipient); err != nil {
189-
return err
190-
}
191-
if err := api.accessVerifier.verifyTransactions(types.LatestSigner(api.eth.BlockChain().Config()), block.Transactions()); err != nil {
192-
return err
193-
}
194-
isPostMerge := true // the call is PoS-native
195-
timestamp := params.BuilderSubmitBlockRequest.ExecutionPayload.Timestamp
196-
precompiles := vm.ActivePrecompiles(api.eth.APIBackend.ChainConfig().Rules(new(big.Int).SetUint64(params.ExecutionPayload.BlockNumber), isPostMerge, timestamp))
197-
tracer = logger.NewAccessListTracer(nil, common.Address{}, common.Address{}, precompiles)
198-
vmconfig = vm.Config{Tracer: tracer, Debug: true}
199-
}
200-
201-
err = api.eth.BlockChain().ValidatePayload(block, feeRecipient, expectedProfit, params.RegisteredGasLimit, vmconfig)
98+
err = api.eth.BlockChain().ValidatePayload(block, feeRecipient, expectedProfit, params.RegisteredGasLimit, *api.eth.BlockChain().GetVMConfig())
20299
if err != nil {
203100
log.Error("invalid payload", "hash", payload.BlockHash.String(), "number", payload.BlockNumber, "parentHash", payload.ParentHash.String(), "err", err)
204101
return err
205102
}
206103

207-
if api.accessVerifier != nil && tracer != nil {
208-
if err := api.accessVerifier.verifyTraces(tracer); err != nil {
209-
return err
210-
}
211-
}
212-
213104
log.Info("validated block", "hash", block.Hash(), "number", block.NumberU64(), "parentHash", block.ParentHash())
214105
return nil
215106
}
@@ -278,36 +169,12 @@ func (api *BlockValidationAPI) ValidateBuilderSubmissionV2(params *BuilderBlockV
278169
feeRecipient := common.BytesToAddress(params.Message.ProposerFeeRecipient[:])
279170
expectedProfit := params.Message.Value.ToBig()
280171

281-
var vmconfig vm.Config
282-
var tracer *logger.AccessListTracer = nil
283-
if api.accessVerifier != nil {
284-
if err := api.accessVerifier.isBlacklisted(block.Coinbase()); err != nil {
285-
return err
286-
}
287-
if err := api.accessVerifier.isBlacklisted(feeRecipient); err != nil {
288-
return err
289-
}
290-
if err := api.accessVerifier.verifyTransactions(types.LatestSigner(api.eth.BlockChain().Config()), block.Transactions()); err != nil {
291-
return err
292-
}
293-
isPostMerge := true // the call is PoS-native
294-
precompiles := vm.ActivePrecompiles(api.eth.APIBackend.ChainConfig().Rules(new(big.Int).SetUint64(params.ExecutionPayload.BlockNumber), isPostMerge, params.ExecutionPayload.Timestamp))
295-
tracer = logger.NewAccessListTracer(nil, common.Address{}, common.Address{}, precompiles)
296-
vmconfig = vm.Config{Tracer: tracer, Debug: true}
297-
}
298-
299-
err = api.eth.BlockChain().ValidatePayload(block, feeRecipient, expectedProfit, params.RegisteredGasLimit, vmconfig)
172+
err = api.eth.BlockChain().ValidatePayload(block, feeRecipient, expectedProfit, params.RegisteredGasLimit, *api.eth.BlockChain().GetVMConfig())
300173
if err != nil {
301174
log.Error("invalid payload", "hash", payload.BlockHash.String(), "number", payload.BlockNumber, "parentHash", payload.ParentHash.String(), "err", err)
302175
return err
303176
}
304177

305-
if api.accessVerifier != nil && tracer != nil {
306-
if err := api.accessVerifier.verifyTraces(tracer); err != nil {
307-
return err
308-
}
309-
}
310-
311178
log.Info("validated block", "hash", block.Hash(), "number", block.NumberU64(), "parentHash", block.ParentHash())
312179
return nil
313180
}

0 commit comments

Comments
 (0)