solidity sign with EIP712

Viewed 780

i read smart contract and confused. as the lesson tell us about ABI----

The Contract Application Binary Interface (ABI) is the standard way to interact with contracts in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interaction.
 bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

...

    function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) public {
        bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this)));
        bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
        address signatory = ecrecover(digest, v, r, s);
        require(signatory != address(0), "Comp::delegateBySig: invalid signature");
        require(nonce == nonces[signatory]++, "Comp::delegateBySig: invalid nonce");
        require(now <= expiry, "Comp::delegateBySig: signature expired");
        return _delegate(signatory, delegatee);
    }

i was very confused that how ABI can use EIP712Domain?(EIP712Domain not a global varaibles) is EIP712Domain exist method at evm so it can understand ... or exist other contract?

1 Answers

In this context that you've shown, EIP712Domain is not a function or a public property. It's also not a Solidity global variable.

It's just part of a string message that is being signed in the delegateBySig() function.


ABI stands for "application binary interface" and it's a specification that includes encoding arguments (according to the spec). As well as the JSON representing function definitions that you might be familiar with.

So what this function does:

string DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this))

It generates a binary output that would be the same as the transaction data if you were calling the EIP712Domain() function with parameters keccak256(bytes(name)), getChainId() and address(this).

Related