ETH Price: $3,461.46 (-1.57%)
Gas: 3 Gwei

Contract

0x8065C44FF1F3D8F38c8a16Fa4a4121c7F6Fcf4D8
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x61043361146039602022-04-17 16:58:41828 days ago1650214721IN
 Create: VerifySignaturePool02
0 ETH0.0092063732.25351688

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
VerifySignaturePool02

Compiler Version
v0.8.3+commit.8d00100c

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license
/**
 *Submitted for verification at Etherscan.io on 2022-06-30
*/

// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

/* Signature Verification

How to Sign and Verify
# Signing
1. Create message to sign
2. Hash the message
3. Sign the hash (off chain, keep your private key secret)

# Verify
1. Recreate hash from the original message
2. Recover signer from signature and hash
3. Compare recovered signer to claimed signer
*/

library VerifySignaturePool02 {
    /* 1. Unlock MetaMask account
    ethereum.enable()
    */

    /* 2. Get message hash to sign
    getMessageHash(
        0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C,
        123,
        "coffee and donuts",
        1
    )

    hash = "0xcf36ac4f97dc10d91fc2cbb20d718e94a8cbfe0f82eaedc6a4aa38946fb797cd"
    */
    function getMessageHash(
        address nft,
        uint tokenID,
        uint valuation,
        uint expireAtBlock
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(nft, tokenID, valuation, expireAtBlock));
    }

    /* 3. Sign message hash
    # using browser
    account = "copy paste account of signer here"
    ethereum.request({ method: "personal_sign", params: [account, hash]}).then(console.log)

    # using web3
    web3.personal.sign(hash, web3.eth.defaultAccount, console.log)

    Signature will be different for different accounts
    0x993dab3dd91f5c6dc28e17439be475478f5635c92a56e17e82349d3fb2f166196f466c0b4e0c146f285204f0dcb13e5ae67bc33f4b888ec32dfe0a063e8f3f781b
    */
    function getEthSignedMessageHash(bytes32 _messageHash)
        public
        pure
        returns (bytes32)
    {
        /*
        Signature is produced by signing a keccak256 hash with the following format:
        "\x19Ethereum Signed Message\n" + len(msg) + msg
        */
        return
            keccak256(
                abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash)
            );
    }

    /* 4. Verify signature
    signer = 0xB273216C05A8c0D4F0a4Dd0d7Bae1D2EfFE636dd
    to = 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C
    amount = 123
    message = "coffee and donuts"
    nonce = 1
    signature =
        0x993dab3dd91f5c6dc28e17439be475478f5635c92a56e17e82349d3fb2f166196f466c0b4e0c146f285204f0dcb13e5ae67bc33f4b888ec32dfe0a063e8f3f781b
    */
    function verify(
        address nft,
        uint tokenID,
        uint valuation,
        uint expireAtBlock,
        address _signer,
        bytes memory signature
    ) public pure returns (bool) {
        bytes32 messageHash = getMessageHash(nft, tokenID, valuation, expireAtBlock);
        bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);

        return recoverSigner(ethSignedMessageHash, signature) == _signer;
    }

    function recoverSigner(bytes32 _ethSignedMessageHash, bytes memory _signature)
        internal
        pure
        returns (address)
    {
        (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);

        return ecrecover(_ethSignedMessageHash, v, r, s);
    }

    function splitSignature(bytes memory sig)
        internal
        pure
        returns (
            bytes32 r,
            bytes32 s,
            uint8 v
        )
    {
        require(sig.length == 65, "invalid signature length");

        assembly {
            /*
            First 32 bytes stores the length of the signature

            add(sig, 32) = pointer of sig + 32
            effectively, skips first 32 bytes of signature

            mload(p) loads next 32 bytes starting at the memory address p into memory
            */

            // first 32 bytes, after the length prefix
            r := mload(add(sig, 32))
            // second 32 bytes
            s := mload(add(sig, 64))
            // final byte (first byte of the next 32 bytes)
            v := byte(0, mload(add(sig, 96)))
        }

        // implicitly return (r, s, v)
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"bytes32","name":"_messageHash","type":"bytes32"}],"name":"getEthSignedMessageHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenID","type":"uint256"},{"internalType":"uint256","name":"valuation","type":"uint256"},{"internalType":"uint256","name":"expireAtBlock","type":"uint256"}],"name":"getMessageHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenID","type":"uint256"},{"internalType":"uint256","name":"valuation","type":"uint256"},{"internalType":"uint256","name":"expireAtBlock","type":"uint256"},{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"verify","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]

61043361003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061004b5760003560e01c80630f3f9bbf14610050578063f440be0414610078578063fa54080114610099575b600080fd5b61006361005e3660046102e6565b6100ac565b60405190151581526020015b60405180910390f35b61008b6100863660046102ae565b6100f5565b60405190815260200161006f565b61008b6100a73660046103cf565b61014c565b6000806100bb888888886100f5565b905060006100c88261014c565b9050846001600160a01b03166100de82866101a0565b6001600160a01b0316149998505050505050505050565b6040516bffffffffffffffffffffffff19606086901b166020820152603481018490526054810183905260748101829052600090609401604051602081830303815290604052805190602001209050949350505050565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c016040516020818303038152906040528051906020012090505b919050565b6000806000806101af8561021f565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa15801561020a573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b600080600083516041146102795760405162461bcd60e51b815260206004820152601860248201527f696e76616c6964207369676e6174757265206c656e6774680000000000000000604482015260640160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b80356001600160a01b038116811461019b57600080fd5b600080600080608085870312156102c3578384fd5b6102cc85610297565b966020860135965060408601359560600135945092505050565b60008060008060008060c087890312156102fe578182fd5b61030787610297565b955060208701359450604087013593506060870135925061032a60808801610297565b915060a087013567ffffffffffffffff80821115610346578283fd5b818901915089601f830112610359578283fd5b81358181111561036b5761036b6103e7565b604051601f8201601f19908116603f01168101908382118183101715610393576103936103e7565b816040528281528c60208487010111156103ab578586fd5b82602086016020830137856020848301015280955050505050509295509295509295565b6000602082840312156103e0578081fd5b5035919050565b634e487b7160e01b600052604160045260246000fdfea2646970667358221220bf77a0dea2cbcc6ff0d21be1c162d5f7e56a512ed09814937cf5b2bb8614dea464736f6c63430008030033

Deployed Bytecode

0x738065c44ff1f3d8f38c8a16fa4a4121c7f6fcf4d8301460806040526004361061004b5760003560e01c80630f3f9bbf14610050578063f440be0414610078578063fa54080114610099575b600080fd5b61006361005e3660046102e6565b6100ac565b60405190151581526020015b60405180910390f35b61008b6100863660046102ae565b6100f5565b60405190815260200161006f565b61008b6100a73660046103cf565b61014c565b6000806100bb888888886100f5565b905060006100c88261014c565b9050846001600160a01b03166100de82866101a0565b6001600160a01b0316149998505050505050505050565b6040516bffffffffffffffffffffffff19606086901b166020820152603481018490526054810183905260748101829052600090609401604051602081830303815290604052805190602001209050949350505050565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c016040516020818303038152906040528051906020012090505b919050565b6000806000806101af8561021f565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa15801561020a573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b600080600083516041146102795760405162461bcd60e51b815260206004820152601860248201527f696e76616c6964207369676e6174757265206c656e6774680000000000000000604482015260640160405180910390fd5b50505060208101516040820151606090920151909260009190911a90565b80356001600160a01b038116811461019b57600080fd5b600080600080608085870312156102c3578384fd5b6102cc85610297565b966020860135965060408601359560600135945092505050565b60008060008060008060c087890312156102fe578182fd5b61030787610297565b955060208701359450604087013593506060870135925061032a60808801610297565b915060a087013567ffffffffffffffff80821115610346578283fd5b818901915089601f830112610359578283fd5b81358181111561036b5761036b6103e7565b604051601f8201601f19908116603f01168101908382118183101715610393576103936103e7565b816040528281528c60208487010111156103ab578586fd5b82602086016020830137856020848301015280955050505050509295509295509295565b6000602082840312156103e0578081fd5b5035919050565b634e487b7160e01b600052604160045260246000fdfea2646970667358221220bf77a0dea2cbcc6ff0d21be1c162d5f7e56a512ed09814937cf5b2bb8614dea464736f6c63430008030033

Deployed Bytecode Sourcemap

383:3582:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2312:458;;;;;;:::i;:::-;;:::i;:::-;;;3107:14:1;;3100:22;3082:41;;3070:2;3055:18;2312:458:0;;;;;;;;751:253;;;;;;:::i;:::-;;:::i;:::-;;;3288:25:1;;;3276:2;3261:18;751:253:0;3243:76:1;1498:433:0;;;;;;:::i;:::-;;:::i;2312:458::-;2514:4;2531:19;2553:54;2568:3;2573:7;2582:9;2593:13;2553:14;:54::i;:::-;2531:76;;2618:28;2649:36;2673:11;2649:23;:36::i;:::-;2618:67;;2755:7;-1:-1:-1;;;;;2705:57:0;:46;2719:20;2741:9;2705:13;:46::i;:::-;-1:-1:-1;;;;;2705:57:0;;;2312:458;-1:-1:-1;;;;;;;;;2312:458:0:o;751:253::-;939:56;;-1:-1:-1;;2352:2:1;2348:15;;;2344:53;939:56:0;;;2332:66:1;2414:12;;;2407:28;;;2451:12;;;2444:28;;;2488:12;;;2481:28;;;902:7:0;;2525:13:1;;939:56:0;;;;;;;;;;;;929:67;;;;;;922:74;;751:253;;;;;;:::o;1498:433::-;1842:66;;2791::1;1842::0;;;2779:79:1;2874:12;;;2867:28;;;1601:7:0;;2911:12:1;;1842:66:0;;;;;;;;;;;;1814:109;;;;;;1794:129;;1498:433;;;;:::o;2778:283::-;2907:7;2933:9;2944;2955:7;2966:26;2981:10;2966:14;:26::i;:::-;3012:41;;;;;;;;;;;;3551:25:1;;;3624:4;3612:17;;3592:18;;;3585:45;;;;3646:18;;;3639:34;;;3689:18;;;3682:34;;;2932:60:0;;-1:-1:-1;2932:60:0;;-1:-1:-1;2932:60:0;-1:-1:-1;3012:41:0;;3523:19:1;;3012:41:0;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;3012:41:0;;-1:-1:-1;;3012:41:0;;;2778:283;-1:-1:-1;;;;;;;2778:283:0:o;3069:893::-;3175:9;3199;3223:7;3266:3;:10;3280:2;3266:16;3258:53;;;;-1:-1:-1;;;3258:53:0;;3929:2:1;3258:53:0;;;3911:21:1;3968:2;3948:18;;;3941:30;4007:26;3987:18;;;3980:54;4051:18;;3258:53:0;;;;;;;;-1:-1:-1;;;3720:2:0;3711:12;;3705:19;3790:2;3781:12;;3775:19;3897:2;3888:12;;;3882:19;3705;;3879:1;3874:28;;;;;3333:580::o;14:173:1:-;82:20;;-1:-1:-1;;;;;131:31:1;;121:42;;111:2;;177:1;174;167:12;192:401;;;;;355:3;343:9;334:7;330:23;326:33;323:2;;;377:6;369;362:22;323:2;405:29;424:9;405:29;:::i;:::-;395:39;481:2;466:18;;453:32;;-1:-1:-1;532:2:1;517:18;;504:32;;583:2;568:18;555:32;;-1:-1:-1;313:280:1;-1:-1:-1;;;313:280:1:o;598:1321::-;;;;;;;804:3;792:9;783:7;779:23;775:33;772:2;;;826:6;818;811:22;772:2;854:29;873:9;854:29;:::i;:::-;844:39;;930:2;919:9;915:18;902:32;892:42;;981:2;970:9;966:18;953:32;943:42;;1032:2;1021:9;1017:18;1004:32;994:42;;1055:39;1089:3;1078:9;1074:19;1055:39;:::i;:::-;1045:49;;1145:3;1134:9;1130:19;1117:33;1169:18;1210:2;1202:6;1199:14;1196:2;;;1231:6;1223;1216:22;1196:2;1274:6;1263:9;1259:22;1249:32;;1319:7;1312:4;1308:2;1304:13;1300:27;1290:2;;1346:6;1338;1331:22;1290:2;1387;1374:16;1409:2;1405;1402:10;1399:2;;;1415:18;;:::i;:::-;1490:2;1484:9;1458:2;1544:13;;-1:-1:-1;;1540:22:1;;;1564:2;1536:31;1532:40;1520:53;;;1588:18;;;1608:22;;;1585:46;1582:2;;;1634:18;;:::i;:::-;1674:10;1670:2;1663:22;1709:2;1701:6;1694:18;1749:7;1744:2;1739;1735;1731:11;1727:20;1724:33;1721:2;;;1775:6;1767;1760:22;1721:2;1836;1831;1827;1823:11;1818:2;1810:6;1806:15;1793:46;1881:6;1876:2;1871;1863:6;1859:15;1855:24;1848:40;1907:6;1897:16;;;;;;;762:1157;;;;;;;;:::o;1924:190::-;;2036:2;2024:9;2015:7;2011:23;2007:32;2004:2;;;2057:6;2049;2042:22;2004:2;-1:-1:-1;2085:23:1;;1994:120;-1:-1:-1;1994:120:1:o;4080:127::-;4141:10;4136:3;4132:20;4129:1;4122:31;4172:4;4169:1;4162:15;4196:4;4193:1;4186:15

Swarm Source

ipfs://bf77a0dea2cbcc6ff0d21be1c162d5f7e56a512ed09814937cf5b2bb8614dea4

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.