diff --git a/.changeset/nervous-bees-whisper.md b/.changeset/nervous-bees-whisper.md new file mode 100644 index 0000000000000..bb692c1cf352f --- /dev/null +++ b/.changeset/nervous-bees-whisper.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/l2geth': patch +--- + +Return a better error message for when the nonce is too high. Previously it would return `nonce too low` for even when the nonce was too high. Now it will return `nonce too high` to the user diff --git a/.changeset/yellow-yaks-brake.md b/.changeset/yellow-yaks-brake.md new file mode 100644 index 0000000000000..61fe8c390dffa --- /dev/null +++ b/.changeset/yellow-yaks-brake.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/integration-tests': patch +--- + +Add tests for nonce too low and too high diff --git a/integration-tests/test/rpc.spec.ts b/integration-tests/test/rpc.spec.ts index 19936a2c7d296..9b70d86c4a10c 100644 --- a/integration-tests/test/rpc.spec.ts +++ b/integration-tests/test/rpc.spec.ts @@ -72,6 +72,32 @@ describe('Basic RPC tests', () => { expect(result.data).to.equal(tx.data) }) + it('should reject a transaction with a too low of nonce', async () => { + const tx = { + ...defaultTransactionFactory(), + gasPrice: await gasPriceForL2(env), + nonce: (await wallet.getTransactionCount()) - 1, + } + + const signed = await wallet.signTransaction(tx) + await expect(provider.sendTransaction(signed)).to.be.rejectedWith( + 'invalid transaction: nonce too low' + ) + }) + + it('should reject a transaction with a too high of a nonce', async () => { + const tx = { + ...defaultTransactionFactory(), + gasPrice: await gasPriceForL2(env), + nonce: (await wallet.getTransactionCount()) + 10, + } + + const signed = await wallet.signTransaction(tx) + await expect(provider.sendTransaction(signed)).to.be.rejectedWith( + 'invalid transaction: nonce too high' + ) + }) + it('should not accept a transaction with the wrong chain ID', async () => { const tx = { ...defaultTransactionFactory(), diff --git a/l2geth/core/tx_pool.go b/l2geth/core/tx_pool.go index 666cfd57a150e..c186192f5f00f 100644 --- a/l2geth/core/tx_pool.go +++ b/l2geth/core/tx_pool.go @@ -555,8 +555,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { } // Ensure the transaction adheres to nonce ordering if rcfg.UsingOVM { - if pool.currentState.GetNonce(from) != tx.Nonce() { + nonce := pool.currentState.GetNonce(from) + if nonce > tx.Nonce() { return ErrNonceTooLow + } else if nonce < tx.Nonce() { + return errors.New("nonce too high") } } else { if pool.currentState.GetNonce(from) > tx.Nonce() {