Skip to content

Commit

Permalink
refactor for new account nonce limit
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed Aug 5, 2022
1 parent 35a04e5 commit ce09fe0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions contracts/Create.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ contract Create {
bytes1 len = bytes1(0x94);

/**
* @dev The theoretical limit for an account nonce is uint64; see e.g. here:
* https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction.go#L280.
* @dev The theoretical allowed limit, based on EIP-2681, for an account nonce is 2**64-2:
* https://eips.ethereum.org/EIPS/eip-2681.
*/
if (nonce > type(uint64).max) revert InvalidNonceValue(address(this));
if (nonce > type(uint64).max - 1) revert InvalidNonceValue(address(this));

/**
* @dev The integer zero is treated as an empty byte string and therefore has only one
Expand Down
12 changes: 6 additions & 6 deletions test/Create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,25 @@ contract("Create", function (accounts) {
);
});

it("computes the correct contract address - case 10: nonce <= uint64", async function () {
setNonce(this.factory.address, new BN(0xffffffffffffffffn));
it("computes the correct contract address - case 10: nonce < uint64", async function () {
setNonce(this.factory.address, new BN(0xfffffffffffffffen));
const onChainComputed = await this.factory.computeAddress(
this.factory.address,
0xffffffffffffffffn
0xfffffffffffffffen
);
const from = Address.fromString(this.factory.address);
const offChainComputed = Address.generate(
from,
new BN(0xffffffffffffffffn)
new BN(0xfffffffffffffffen)
);
expect(onChainComputed).to.equal(
web3.utils.toChecksumAddress(offChainComputed.toString("hex"))
);
});

it("reverts if the nonce is larger than type(uint64).max", async function () {
it("reverts if the nonce is larger than type(uint64).max - 1", async function () {
await expectRevertCustomError(
this.factory.computeAddress(this.factory.address, 0xffffffffffffffffan),
this.factory.computeAddress(this.factory.address, 0xffffffffffffffffn),
`InvalidNonceValue("${this.factory.address}")`
);
});
Expand Down

0 comments on commit ce09fe0

Please sign in to comment.