Skip to content

Commit

Permalink
Fix payment validation (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche authored May 15, 2024
1 parent c5b15c4 commit bfd3ac9
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2540,49 +2540,49 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad
}
log.Warn("proposer payment not enough, trying last tx payment validation", "expected", expectedProfit, "actual", feeRecipientBalanceDelta)
}
}

if len(receipts) == 0 {
return errors.New("no proposer payment receipt")
}
if len(receipts) == 0 {
return errors.New("no proposer payment receipt")
}

lastReceipt := receipts[len(receipts)-1]
if lastReceipt.Status != types.ReceiptStatusSuccessful {
return errors.New("proposer payment not successful")
}
txIndex := lastReceipt.TransactionIndex
if txIndex+1 != uint(len(block.Transactions())) {
return fmt.Errorf("proposer payment index not last transaction in the block (%d of %d)", txIndex, len(block.Transactions())-1)
}
lastReceipt := receipts[len(receipts)-1]
if lastReceipt.Status != types.ReceiptStatusSuccessful {
return errors.New("proposer payment not successful")
}
txIndex := lastReceipt.TransactionIndex
if txIndex+1 != uint(len(block.Transactions())) {
return fmt.Errorf("proposer payment index not last transaction in the block (%d of %d)", txIndex, len(block.Transactions())-1)
}

paymentTx := block.Transaction(lastReceipt.TxHash)
if paymentTx == nil {
return errors.New("payment tx not in the block")
}
paymentTx := block.Transaction(lastReceipt.TxHash)
if paymentTx == nil {
return errors.New("payment tx not in the block")
}

paymentTo := paymentTx.To()
if paymentTo == nil || *paymentTo != feeRecipient {
return fmt.Errorf("payment tx not to the proposers fee recipient (%v)", paymentTo)
}
paymentTo := paymentTx.To()
if paymentTo == nil || *paymentTo != feeRecipient {
return fmt.Errorf("payment tx not to the proposers fee recipient (%v)", paymentTo)
}

if paymentTx.Value().Cmp(expectedProfit) != 0 {
return fmt.Errorf("inaccurate payment %s, expected %s", paymentTx.Value().String(), expectedProfit.String())
}
if paymentTx.Value().Cmp(expectedProfit) != 0 {
return fmt.Errorf("inaccurate payment %s, expected %s", paymentTx.Value().String(), expectedProfit.String())
}

if len(paymentTx.Data()) != 0 {
return fmt.Errorf("malformed proposer payment, contains calldata")
}
if len(paymentTx.Data()) != 0 {
return fmt.Errorf("malformed proposer payment, contains calldata")
}

if paymentTx.GasPrice().Cmp(block.BaseFee()) != 0 {
return fmt.Errorf("malformed proposer payment, gas price not equal to base fee")
}
if paymentTx.GasPrice().Cmp(block.BaseFee()) != 0 {
return fmt.Errorf("malformed proposer payment, gas price not equal to base fee")
}

if paymentTx.GasTipCap().Cmp(block.BaseFee()) != 0 && paymentTx.GasTipCap().Sign() != 0 {
return fmt.Errorf("malformed proposer payment, unexpected gas tip cap")
}
if paymentTx.GasTipCap().Cmp(block.BaseFee()) != 0 && paymentTx.GasTipCap().Sign() != 0 {
return fmt.Errorf("malformed proposer payment, unexpected gas tip cap")
}

if paymentTx.GasFeeCap().Cmp(block.BaseFee()) != 0 {
return fmt.Errorf("malformed proposer payment, unexpected gas fee cap")
}
if paymentTx.GasFeeCap().Cmp(block.BaseFee()) != 0 {
return fmt.Errorf("malformed proposer payment, unexpected gas fee cap")
}

return nil
Expand Down

0 comments on commit bfd3ac9

Please sign in to comment.