Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payment validation #158

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading