From e53ac0432265852bcc35b59d69a6c0bf450684ae Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Mon, 6 Dec 2021 16:09:40 -0800 Subject: [PATCH 1/3] itests: add nonce too low and too high cases The current behavior of the sequencer will return the error message `nonce too low` even in the case when the nonce it too high. This should be followed up with changes that fix that problem. Need to double check that it will not break any integrations. --- .changeset/yellow-yaks-brake.md | 5 +++++ integration-tests/test/rpc.spec.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .changeset/yellow-yaks-brake.md 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(), From a04b00439d799097db5d3451927cd8752b0d074e Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Mon, 6 Dec 2021 16:42:24 -0800 Subject: [PATCH 2/3] l2geth: return nonce too high error message Previously the error message `nonce too low` would be returned even when the user submitted a transaction with a nonce that was too high --- l2geth/core/tx_pool.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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() { From 3c4b99c2580dc9833ecc3b5a909b5af654b91bcf Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Mon, 6 Dec 2021 16:45:27 -0800 Subject: [PATCH 3/3] chore: add changeset --- .changeset/nervous-bees-whisper.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nervous-bees-whisper.md 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