@@ -2454,31 +2454,31 @@ func (bc *BlockChain) SetBlockValidatorAndProcessorForTesting(v Validator, p Pro
24542454// - `useBalanceDiffProfit` if set to false, proposer payment is assumed to be in the last transaction of the block
24552455// otherwise we use proposer balance changes after the block to calculate proposer payment (see details in the code)
24562456// - `excludeWithdrawals` if set to true, withdrawals to the fee recipient are excluded from the balance change
2457- func (bc * BlockChain ) ValidatePayload (block * types.Block , feeRecipient common.Address , expectedProfit * big.Int , registeredGasLimit uint64 , vmConfig vm.Config , useBalanceDiffProfit , excludeWithdrawals bool ) error {
2457+ func (bc * BlockChain ) ValidatePayload (block * types.Block , feeRecipient common.Address , expectedProfit * big.Int , registeredGasLimit uint64 , vmConfig vm.Config , useBalanceDiffProfit , excludeWithdrawals bool ) ( * uint256. Int , error ) {
24582458 header := block .Header ()
24592459 if err := bc .engine .VerifyHeader (bc , header ); err != nil {
2460- return err
2460+ return nil , err
24612461 }
24622462
24632463 current := bc .CurrentBlock ()
24642464 reorg , err := bc .forker .ReorgNeeded (current , header )
24652465 if err == nil && reorg {
2466- return errors .New ("block requires a reorg" )
2466+ return nil , errors .New ("block requires a reorg" )
24672467 }
24682468
24692469 parent := bc .GetHeader (block .ParentHash (), block .NumberU64 ()- 1 )
24702470 if parent == nil {
2471- return errors .New ("parent not found" )
2471+ return nil , errors .New ("parent not found" )
24722472 }
24732473
24742474 calculatedGasLimit := CalcGasLimit (parent .GasLimit , registeredGasLimit )
24752475 if calculatedGasLimit != header .GasLimit {
2476- return errors .New ("incorrect gas limit set" )
2476+ return nil , errors .New ("incorrect gas limit set" )
24772477 }
24782478
24792479 statedb , err := bc .StateAt (parent .Root )
24802480 if err != nil {
2481- return err
2481+ return nil , err
24822482 }
24832483
24842484 // The chain importer is starting and stopping trie prefetchers. If a bad
@@ -2491,7 +2491,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
24912491
24922492 receipts , _ , usedGas , err := bc .processor .Process (block , statedb , vmConfig )
24932493 if err != nil {
2494- return err
2494+ return nil , err
24952495 }
24962496
24972497 feeRecipientBalanceAfter := new (uint256.Int ).Set (statedb .GetBalance (feeRecipient ))
@@ -2508,24 +2508,24 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
25082508
25092509 if bc .Config ().IsShanghai (header .Number , header .Time ) {
25102510 if header .WithdrawalsHash == nil {
2511- return fmt .Errorf ("withdrawals hash is missing" )
2511+ return nil , fmt .Errorf ("withdrawals hash is missing" )
25122512 }
25132513 // withdrawals hash and withdrawals validated later in ValidateBody
25142514 } else {
25152515 if header .WithdrawalsHash != nil {
2516- return fmt .Errorf ("withdrawals hash present before shanghai" )
2516+ return nil , fmt .Errorf ("withdrawals hash present before shanghai" )
25172517 }
25182518 if block .Withdrawals () != nil {
2519- return fmt .Errorf ("withdrawals list present in block body before shanghai" )
2519+ return nil , fmt .Errorf ("withdrawals list present in block body before shanghai" )
25202520 }
25212521 }
25222522
25232523 if err := bc .validator .ValidateBody (block ); err != nil {
2524- return err
2524+ return nil , err
25252525 }
25262526
25272527 if err := bc .validator .ValidateState (block , statedb , receipts , usedGas ); err != nil {
2528- return err
2528+ return nil , err
25292529 }
25302530
25312531 // Validate proposer payment
@@ -2540,56 +2540,61 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
25402540 if feeRecipientBalanceDelta .Cmp (uint256ExpectedProfit ) > 0 {
25412541 log .Warn ("builder claimed profit is lower than calculated profit" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
25422542 }
2543- return nil
2543+ return feeRecipientBalanceDelta , nil
25442544 }
25452545 log .Warn ("proposer payment not enough, trying last tx payment validation" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
25462546 }
25472547 }
25482548
25492549 if len (receipts ) == 0 {
2550- return errors .New ("no proposer payment receipt" )
2550+ return nil , errors .New ("no proposer payment receipt" )
25512551 }
25522552
25532553 lastReceipt := receipts [len (receipts )- 1 ]
25542554 if lastReceipt .Status != types .ReceiptStatusSuccessful {
2555- return errors .New ("proposer payment not successful" )
2555+ return nil , errors .New ("proposer payment not successful" )
25562556 }
25572557 txIndex := lastReceipt .TransactionIndex
25582558 if txIndex + 1 != uint (len (block .Transactions ())) {
2559- return fmt .Errorf ("proposer payment index not last transaction in the block (%d of %d)" , txIndex , len (block .Transactions ())- 1 )
2559+ return nil , fmt .Errorf ("proposer payment index not last transaction in the block (%d of %d)" , txIndex , len (block .Transactions ())- 1 )
25602560 }
25612561
25622562 paymentTx := block .Transaction (lastReceipt .TxHash )
25632563 if paymentTx == nil {
2564- return errors .New ("payment tx not in the block" )
2564+ return nil , errors .New ("payment tx not in the block" )
25652565 }
25662566
25672567 paymentTo := paymentTx .To ()
25682568 if paymentTo == nil || * paymentTo != feeRecipient {
2569- return fmt .Errorf ("payment tx not to the proposers fee recipient (%v)" , paymentTo )
2569+ return nil , fmt .Errorf ("payment tx not to the proposers fee recipient (%v)" , paymentTo )
25702570 }
25712571
25722572 if paymentTx .Value ().Cmp (expectedProfit ) != 0 {
2573- return fmt .Errorf ("inaccurate payment %s, expected %s" , paymentTx .Value ().String (), expectedProfit .String ())
2573+ return nil , fmt .Errorf ("inaccurate payment %s, expected %s" , paymentTx .Value ().String (), expectedProfit .String ())
25742574 }
25752575
25762576 if len (paymentTx .Data ()) != 0 {
2577- return fmt .Errorf ("malformed proposer payment, contains calldata" )
2577+ return nil , fmt .Errorf ("malformed proposer payment, contains calldata" )
25782578 }
25792579
25802580 if paymentTx .GasPrice ().Cmp (block .BaseFee ()) != 0 {
2581- return fmt .Errorf ("malformed proposer payment, gas price not equal to base fee" )
2581+ return nil , fmt .Errorf ("malformed proposer payment, gas price not equal to base fee" )
25822582 }
25832583
25842584 if paymentTx .GasTipCap ().Cmp (block .BaseFee ()) != 0 && paymentTx .GasTipCap ().Sign () != 0 {
2585- return fmt .Errorf ("malformed proposer payment, unexpected gas tip cap" )
2585+ return nil , fmt .Errorf ("malformed proposer payment, unexpected gas tip cap" )
25862586 }
25872587
25882588 if paymentTx .GasFeeCap ().Cmp (block .BaseFee ()) != 0 {
2589- return fmt .Errorf ("malformed proposer payment, unexpected gas fee cap" )
2589+ return nil , fmt .Errorf ("malformed proposer payment, unexpected gas fee cap" )
25902590 }
25912591
2592- return nil
2592+ blockValue , ok := uint256 .FromBig (paymentTx .Value ())
2593+ if ! ok {
2594+ return nil , fmt .Errorf ("malformed proposer payment, value too large" )
2595+ }
2596+
2597+ return blockValue , nil
25932598}
25942599
25952600// SetTrieFlushInterval configures how often in-memory tries are persisted to disk.
0 commit comments