edr icon indicating copy to clipboard operation
edr copied to clipboard

The `MemPool` should check the sum of outstanding gas costs for an account before allowing a new transaction for that account

Open Wodann opened this issue 2 years ago • 2 comments

The MemPool currently only validates that the max cost of a transaction is not larger than the balance of the sender's account. We should ensure that the sum of balances of all queued & pending transactions + sent transaction is lower the the balance of the sender's account.

Wodann avatar Aug 03 '23 21:08 Wodann

TBC with geth or other production node

alcuadrado avatar Aug 04 '23 11:08 alcuadrado

Confirmed with geth that this is a bug in EDR. Reproduction:

  1. Send 62_999 wei to some address that doesn't have balance
  2. Disable automining and set next block base fee to 1
  3. Send three transactions from that address, with gas limit of 21_000 and gas price of 1
  4. Call hardhat_mine to mine a block

Expected: the third send should be rejected because the two first transactions have a max cost of 42_000, which makes the (tentative) balance be 20_999.

Actual: the transaction is accepted. What's worse, then hardhat_mine throws an error, instead of just mining a block with the first two transactions discarding the third one.

So we have two problems here: the one in the original description, and how hardhat_mine works when the next tx to mine in the mempool is invalid.

Keep in mind though that, if we fix the first problem, then I don't know how to reproduce the second problem. But it's worth checking the mining code to improve that logic anyway.

fvictorio avatar May 16 '24 08:05 fvictorio