@@ -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
feeRecipientBalanceDelta := new (uint256.Int ).Set (statedb .GetBalance (feeRecipient ))
@@ -2507,24 +2507,24 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
2507
2507
2508
2508
if bc .Config ().IsShanghai (header .Number , header .Time ) {
2509
2509
if header .WithdrawalsHash == nil {
2510
- return fmt .Errorf ("withdrawals hash is missing" )
2510
+ return nil , fmt .Errorf ("withdrawals hash is missing" )
2511
2511
}
2512
2512
// withdrawals hash and withdrawals validated later in ValidateBody
2513
2513
} else {
2514
2514
if header .WithdrawalsHash != nil {
2515
- return fmt .Errorf ("withdrawals hash present before shanghai" )
2515
+ return nil , fmt .Errorf ("withdrawals hash present before shanghai" )
2516
2516
}
2517
2517
if block .Withdrawals () != nil {
2518
- return fmt .Errorf ("withdrawals list present in block body before shanghai" )
2518
+ return nil , fmt .Errorf ("withdrawals list present in block body before shanghai" )
2519
2519
}
2520
2520
}
2521
2521
2522
2522
if err := bc .validator .ValidateBody (block ); err != nil {
2523
- return err
2523
+ return nil , err
2524
2524
}
2525
2525
2526
2526
if err := bc .validator .ValidateState (block , statedb , receipts , usedGas ); err != nil {
2527
- return err
2527
+ return nil , err
2528
2528
}
2529
2529
2530
2530
// Validate proposer payment
@@ -2536,56 +2536,61 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
2536
2536
if feeRecipientBalanceDelta .Cmp (uint256ExpectedProfit ) > 0 {
2537
2537
log .Warn ("builder claimed profit is lower than calculated profit" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
2538
2538
}
2539
- return nil
2539
+ return feeRecipientBalanceDelta , nil
2540
2540
}
2541
2541
log .Warn ("proposer payment not enough, trying last tx payment validation" , "expected" , expectedProfit , "actual" , feeRecipientBalanceDelta )
2542
2542
}
2543
2543
}
2544
2544
2545
2545
if len (receipts ) == 0 {
2546
- return errors .New ("no proposer payment receipt" )
2546
+ return nil , errors .New ("no proposer payment receipt" )
2547
2547
}
2548
2548
2549
2549
lastReceipt := receipts [len (receipts )- 1 ]
2550
2550
if lastReceipt .Status != types .ReceiptStatusSuccessful {
2551
- return errors .New ("proposer payment not successful" )
2551
+ return nil , errors .New ("proposer payment not successful" )
2552
2552
}
2553
2553
txIndex := lastReceipt .TransactionIndex
2554
2554
if txIndex + 1 != uint (len (block .Transactions ())) {
2555
- return fmt .Errorf ("proposer payment index not last transaction in the block (%d of %d)" , txIndex , len (block .Transactions ())- 1 )
2555
+ return nil , fmt .Errorf ("proposer payment index not last transaction in the block (%d of %d)" , txIndex , len (block .Transactions ())- 1 )
2556
2556
}
2557
2557
2558
2558
paymentTx := block .Transaction (lastReceipt .TxHash )
2559
2559
if paymentTx == nil {
2560
- return errors .New ("payment tx not in the block" )
2560
+ return nil , errors .New ("payment tx not in the block" )
2561
2561
}
2562
2562
2563
2563
paymentTo := paymentTx .To ()
2564
2564
if paymentTo == nil || * paymentTo != feeRecipient {
2565
- return fmt .Errorf ("payment tx not to the proposers fee recipient (%v)" , paymentTo )
2565
+ return nil , fmt .Errorf ("payment tx not to the proposers fee recipient (%v)" , paymentTo )
2566
2566
}
2567
2567
2568
2568
if paymentTx .Value ().Cmp (expectedProfit ) != 0 {
2569
- return fmt .Errorf ("inaccurate payment %s, expected %s" , paymentTx .Value ().String (), expectedProfit .String ())
2569
+ return nil , fmt .Errorf ("inaccurate payment %s, expected %s" , paymentTx .Value ().String (), expectedProfit .String ())
2570
2570
}
2571
2571
2572
2572
if len (paymentTx .Data ()) != 0 {
2573
- return fmt .Errorf ("malformed proposer payment, contains calldata" )
2573
+ return nil , fmt .Errorf ("malformed proposer payment, contains calldata" )
2574
2574
}
2575
2575
2576
2576
if paymentTx .GasPrice ().Cmp (block .BaseFee ()) != 0 {
2577
- return fmt .Errorf ("malformed proposer payment, gas price not equal to base fee" )
2577
+ return nil , fmt .Errorf ("malformed proposer payment, gas price not equal to base fee" )
2578
2578
}
2579
2579
2580
2580
if paymentTx .GasTipCap ().Cmp (block .BaseFee ()) != 0 && paymentTx .GasTipCap ().Sign () != 0 {
2581
- return fmt .Errorf ("malformed proposer payment, unexpected gas tip cap" )
2581
+ return nil , fmt .Errorf ("malformed proposer payment, unexpected gas tip cap" )
2582
2582
}
2583
2583
2584
2584
if paymentTx .GasFeeCap ().Cmp (block .BaseFee ()) != 0 {
2585
- return fmt .Errorf ("malformed proposer payment, unexpected gas fee cap" )
2585
+ return nil , fmt .Errorf ("malformed proposer payment, unexpected gas fee cap" )
2586
2586
}
2587
2587
2588
- return nil
2588
+ blockValue , ok := uint256 .FromBig (paymentTx .Value ())
2589
+ if ! ok {
2590
+ return nil , fmt .Errorf ("malformed proposer payment, value too large" )
2591
+ }
2592
+
2593
+ return blockValue , nil
2589
2594
}
2590
2595
2591
2596
// SetTrieFlushInterval configures how often in-memory tries are persisted to disk.
0 commit comments