Contract 0x854F2CBa80dAe7989Dd5729Ed2a71A1923d43243

Contract Overview

Balance:
0 BNB
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x328a60c96c9ebed6446060cbbd674cc2abbdf93c875052bd4a992acad467c6400x60806040118558362021-08-27 22:28:5258 days 15 hrs ago0x322d9e3f049a845e9c8ed089b2bdf8f33c65a08f IN  Contract Creation0 BNB0.00428454
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Signature

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion, MIT license
/**
 *Submitted for verification at BscScan.com on 2021-08-28
*/

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

/* 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
*/

contract Signature {
    /*  Get message hash to sign
    getMessageHash(
        beneficiary address,
        amount,
        nonce,
        payment contract 
    ) take the hash

    */
    function getMessageHash(
        address _to, uint _amount, uint _nonce, address _contract
    )
        public pure returns (bytes32)
    {
        return keccak256(abi.encodePacked(_to, _amount, _nonce, _contract));
    }

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

    # using web3
    web3.personal.sign(hash, web3.eth.defaultAccount, console.log)
    */
    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 = sender address
    to = beneficiary address
    amount = weis
    nonce 
    payment address
    signature = the sign hash created before
    */
    function verify(
        address _signer,
        address _to, uint _amount, uint _nonce, address _contract,
        bytes memory signature
    )
        public pure returns (bool)
    {
        bytes32 messageHash = getMessageHash(_to, _amount, _nonce, _contract);
        bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);

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

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

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

    function splitSignature(bytes memory sig)
        public 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 ABI

[{"inputs":[{"internalType":"bytes32","name":"_messageHash","type":"bytes32"}],"name":"getEthSignedMessageHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"address","name":"_contract","type":"address"}],"name":"getMessageHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_ethSignedMessageHash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"recoverSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"splitSignature","outputs":[{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint8","name":"v","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"address","name":"_contract","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"verify","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]

608060405234801561001057600080fd5b506106cc806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80636aa404521461005c57806397aba7f9146101a1578063a7bb580314610290578063bfa4bf9a14610370578063fa540801146103fc575b600080fd5b610189600480360360c081101561007257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019064010000000081111561010357600080fd5b82018360208201111561011557600080fd5b8035906020019184600183028401116401000000008311171561013757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061043e565b60405180821515815260200191505060405180910390f35b610264600480360360408110156101b757600080fd5b8101908080359060200190929190803590602001906401000000008111156101de57600080fd5b8201836020820111156101f057600080fd5b8035906020019184600183028401116401000000008311171561021257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506104a2565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610349600480360360208110156102a657600080fd5b81019080803590602001906401000000008111156102c357600080fd5b8201836020820111156102d557600080fd5b803590602001918460018302840111640100000000831117156102f757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610526565b604051808481526020018381526020018260ff168152602001935050505060405180910390f35b6103e66004803603608081101561038657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105c1565b6040518082815260200191505060405180910390f35b6104286004803603602081101561041257600080fd5b810190808035906020019092919050505061063e565b6040518082815260200191505060405180910390f35b60008061044d878787876105c1565b9050600061045a8261063e565b90508873ffffffffffffffffffffffffffffffffffffffff1661047d82866104a2565b73ffffffffffffffffffffffffffffffffffffffff1614925050509695505050505050565b6000806000806104b185610526565b92509250925060018682858560405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015610511573d6000803e3d6000fd5b50505060206040510351935050505092915050565b600080600060418451146105a2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f696e76616c6964207369676e6174757265206c656e677468000000000000000081525060200191505060405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b600084848484604051602001808573ffffffffffffffffffffffffffffffffffffffff1660601b81526014018481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1660601b8152601401945050505050604051602081830303815290604052805190602001209050949350505050565b60008160405160200180807f19457468657265756d205369676e6564204d6573736167653a0a333200000000815250601c0182815260200191505060405160208183030381529060405280519060200120905091905056fea26469706673582212204a904984171cc77ab52208bb97a01b9a67f92a033e3e99aced599752ffbc7d6364736f6c63430007060033

Deployed ByteCode Sourcemap

384:2862:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1707:434;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;2149:263;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;2420:823;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;586:229;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1150:356;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1707:434;1887:4;1909:19;1931:47;1946:3;1951:7;1960:6;1968:9;1931:14;:47::i;:::-;1909:69;;1989:28;2020:36;2044:11;2020:23;:36::i;:::-;1989:67;;2126:7;2076:57;;:46;2090:20;2112:9;2076:13;:46::i;:::-;:57;;;2069:64;;;;1707:434;;;;;;;;:::o;2149:263::-;2258:7;2284:9;2295;2306:7;2317:26;2332:10;2317:14;:26::i;:::-;2283:60;;;;;;2363:41;2373:21;2396:1;2399;2402;2363:41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2356:48;;;;;2149:263;;;;:::o;2420:823::-;2492:9;2503;2514:7;2561:2;2547:3;:10;:16;2539:53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3001:2;2996:3;2992:12;2986:19;2981:24;;3071:2;3066:3;3062:12;3056:19;3051:24;;3178:2;3173:3;3169:12;3163:19;3160:1;3155:28;3150:33;;2614:580;;;;;:::o;586:229::-;715:7;774:3;779:7;788:6;796:9;757:49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;747:60;;;;;;740:67;;586:229;;;;;;:::o;1150:356::-;1226:7;1484:12;1431:66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1421:77;;;;;;1414:84;;1150:356;;;:::o

Swarm Source

ipfs://4a904984171cc77ab52208bb97a01b9a67f92a033e3e99aced599752ffbc7d63
Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading