Discussion thread for EIP-4742: NONCE opcode by 0xfoobar · Pull Request #4742 · ethereum/EIPs · GitHub
Abstract
We propose an additional EVM opcode, NONCE
(0x47), which could provide novel protection against sybil attacks and expand the smart contract design space. This would return 0
for an unused externally-owned address (EOA), 0
for a smart contract address, and, for example, 2
for an EOA which has sent 3 transactions. The account.nonce opcode would exactly track the nonce of the last transaction originating from that address.
Motivation
NFT contracts commonly use checks on msg.sender
to limit sybil attacks. However, this is easily circumvented by spinning up new addresses, or even nesting address creation within a smart contract. Letting smart contracts check NONCE
would add additional costs to this, serving as a “proof of history”. While not bulletproof (as msg.sender is not), it opens up the design space to creative uses.
Specification
A new opcode, NONCE
, is introduced, with number 0x47
. The NONCE
opcode takes one argument from the stack, and pushes to the stack the nonce corresponding to that address.
The gas cost of the NONCE
is 200.
Rationale
The EVM makes several global variables available, examples include block.timestamp
, block.number
, block.difficulty
, msg.sender
, and gasleft()
. It also provides several context-dependent opcodes, such as EXTCODESIZE
, BASEFEE
, and BALANCE
Smart contracts can leverage these info for novel techniques, such as staking pool emissions, limiting flashloan attacks, or NFTs that embed blockchain state into their mint result.
It is useful to gather information about interacting addresses. NFT minting is an immediate usecase, and it follows that as much information about the underlying blockchain state should be made available to smart contracts.
Backwards Compatibility
There are no backwards compatibility concerns.
Test Cases
- The
NONCE
of an address with no transactions is0
. - The
NONCE
of an externally owned address (EOA) with one originating transaction is1
. - The
NONCE
of a smart contract, deployed after EIP 161, that has not deployed any other smart contracts is1
. - The
NONCE
of a smart contract, deployed before EIP 161, that has not deployed any other smart contracts is0
. - The
NONCE
of a smart contract, deployed after EIP 161, that has deployed one other smart contract is2
. - The
NONCE
of a smart contract, deployed before EIP 161, that has deployed one other smart contract is1
.
Implementation
Not provided yet, would need to be integrated into Ethereum clients as this is an EVM modification. However, clients already check the account nonce on each transaction to ensure validity, so exposing this data as an opcode should not add significant processing or development load.
Copyright
Copyright and related rights waived via CC0.