Skip to content

Commit

Permalink
Merge pull request #346 from filefilego/fix-endpoint-to-not-accept-ac…
Browse files Browse the repository at this point in the history
…count-smaller-balance

Add transaction total amount check
  • Loading branch information
iNDicat0r committed Mar 23, 2024
2 parents 720a326 + d3a3785 commit 5f13e1a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rpc/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ func (api *API) SendRawTransaction(r *http.Request, args *SendRawTransactionArgs
if err := api.bc.PutMemPool(*tx); err != nil {
return fmt.Errorf("failed to insert transaction from rpc method to mempool: %w", err)
}

fromAddr, decodeErr := hexutil.Decode(tx.From())
state, getStateErr := api.bc.GetAddressState(fromAddr)
balance, err := state.GetBalance()
fees, _ := hexutil.DecodeBig(tx.TransactionFees())
val, _ := hexutil.DecodeBig(tx.Value())
val = val.Add(val, fees)
nobalance := val.Cmp(balance) == 1
if err != nil || decodeErr != nil || getStateErr != nil || nobalance {
return errors.New("insufficient funds for gas * price + value")
}
}

payload := messages.GossipPayload{
Expand Down

0 comments on commit 5f13e1a

Please sign in to comment.