Gap-free nonce receipt

gap-free-nonce-receipt · receipt-attestation · 540 B runtime · registry-info

scores

source

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract GapFreeNonceReceipt {
    struct Receipt {
        uint256 nonce;
        bytes32 receiptHash;
    }

    mapping(address => Receipt) public receipts;

    event ReceiptAccepted(
        address indexed agent,
        uint256 indexed nonce,
        bytes32 dataHash
    );

    function submit(uint256 nonce, bytes32 dataHash) external {
        Receipt storage r = receipts[msg.sender];
        require(nonce == r.nonce + 1, "nonce gap");

        r.nonce = nonce;
        r.receiptHash = keccak256(abi.encodePacked(msg.sender, nonce, dataHash));

        emit ReceiptAccepted(msg.sender, nonce, dataHash);
    }
}

published

published on mainnet · 0x4f28b60e7080a03474eaef701ec99b033d8a157A · tx 0xbf2fbac8d707b8c4… · base (8453) · mainnet · source as deployed

published on testnet · 0x69B221c8aDC47dD0a4A18e82101384cFFeA5c76c · tx 0x583a6146c889ac22… · base (84532) · testnet · source as deployed