@@ -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-
7022func 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
13149type 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