@@ -2454,31 +2454,31 @@ func (bc *BlockChain) SetBlockValidatorAndProcessorForTesting(v Validator, p Pro
2454
2454
// - `useBalanceDiffProfit` if set to false, proposer payment is assumed to be in the last transaction of the block
2455
2455
// otherwise we use proposer balance changes after the block to calculate proposer payment (see details in the code)
2456
2456
// - `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 ) {
2458
2458
header := block .Header ()
2459
2459
if err := bc .engine .VerifyHeader (bc , header ); err != nil {
2460
- return err
2460
+ return nil , err
2461
2461
}
2462
2462
2463
2463
current := bc .CurrentBlock ()
2464
2464
reorg , err := bc .forker .ReorgNeeded (current , header )
2465
2465
if err == nil && reorg {
2466
- return errors .New ("block requires a reorg" )
2466
+ return nil , errors .New ("block requires a reorg" )
2467
2467
}
2468
2468
2469
2469
parent := bc .GetHeader (block .ParentHash (), block .NumberU64 ()- 1 )
2470
2470
if parent == nil {
2471
- return errors .New ("parent not found" )
2471
+ return nil , errors .New ("parent not found" )
2472
2472
}
2473
2473
2474
2474
calculatedGasLimit := CalcGasLimit (parent .GasLimit , registeredGasLimit )
2475
2475
if calculatedGasLimit != header .GasLimit {
2476
- return errors .New ("incorrect gas limit set" )
2476
+ return nil , errors .New ("incorrect gas limit set" )
2477
2477
}
2478
2478
2479
2479
statedb , err := bc .StateAt (parent .Root )
2480
2480
if err != nil {
2481
- return err
2481
+ return nil , err
2482
2482
}
2483
2483
2484
2484
// 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
2491
2491
2492
2492
receipts , _ , usedGas , err := bc .processor .Process (block , statedb , vmConfig )
2493
2493
if err != nil {
2494
- return err
2494
+ return nil , err
2495
2495
}
2496
2496
2497
2497
feeRecipientBalanceAfter := new (uint256.Int ).Set (statedb .GetBalance (feeRecipient ))
@@ -2508,24 +2508,24 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
2508
2508
2509
2509
if bc .Config ().IsShanghai (header .Number , header .Time ) {
2510
2510
if header .WithdrawalsHash == nil {
2511
- return fmt .Errorf ("withdrawals hash is missing" )
2511
+ return nil , fmt .Errorf ("withdrawals hash is missing" )
2512
2512
}
2513
2513
// withdrawals hash and withdrawals validated later in ValidateBody
2514
2514
} else {
2515
2515
if header .WithdrawalsHash != nil {
2516
- return fmt .Errorf ("withdrawals hash present before shanghai" )
2516
+ return nil , fmt .Errorf ("withdrawals hash present before shanghai" )
2517
2517
}
2518
2518
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" )
2520
2520
}
2521
2521
}
2522
2522
2523
2523
if err := bc .validator .ValidateBody (block ); err != nil {
2524
- return err
2524
+ return nil , err
2525
2525
}
2526
2526
2527
2527
if err := bc .validator .ValidateState (block , statedb , receipts , usedGas ); err != nil {
2528
- return err
2528
+ return nil , err
2529
2529
}
2530
2530
2531
2531
// Validate proposer payment
@@ -2540,56 +2540,61 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
2540
2540
if feeRecipientBalanceDelta .Cmp (uint256ExpectedProfit ) > 0 {
2541
2541
log .Warn ("builder claimed profit is lower than calculated profit" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
2542
2542
}
2543
- return nil
2543
+ return feeRecipientBalanceDelta , nil
2544
2544
}
2545
2545
log .Warn ("proposer payment not enough, trying last tx payment validation" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
2546
2546
}
2547
2547
}
2548
2548
2549
2549
if len (receipts ) == 0 {
2550
- return errors .New ("no proposer payment receipt" )
2550
+ return nil , errors .New ("no proposer payment receipt" )
2551
2551
}
2552
2552
2553
2553
lastReceipt := receipts [len (receipts )- 1 ]
2554
2554
if lastReceipt .Status != types .ReceiptStatusSuccessful {
2555
- return errors .New ("proposer payment not successful" )
2555
+ return nil , errors .New ("proposer payment not successful" )
2556
2556
}
2557
2557
txIndex := lastReceipt .TransactionIndex
2558
2558
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 )
2560
2560
}
2561
2561
2562
2562
paymentTx := block .Transaction (lastReceipt .TxHash )
2563
2563
if paymentTx == nil {
2564
- return errors .New ("payment tx not in the block" )
2564
+ return nil , errors .New ("payment tx not in the block" )
2565
2565
}
2566
2566
2567
2567
paymentTo := paymentTx .To ()
2568
2568
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 )
2570
2570
}
2571
2571
2572
2572
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 ())
2574
2574
}
2575
2575
2576
2576
if len (paymentTx .Data ()) != 0 {
2577
- return fmt .Errorf ("malformed proposer payment, contains calldata" )
2577
+ return nil , fmt .Errorf ("malformed proposer payment, contains calldata" )
2578
2578
}
2579
2579
2580
2580
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" )
2582
2582
}
2583
2583
2584
2584
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" )
2586
2586
}
2587
2587
2588
2588
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" )
2590
2590
}
2591
2591
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
2593
2598
}
2594
2599
2595
2600
// SetTrieFlushInterval configures how often in-memory tries are persisted to disk.
0 commit comments