带有EIP712的坚固标志



我读了智能合约,很困惑。正如课程告诉我们的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("x19x01", 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);
}

我很困惑ABI如何使用EIP712Domain?(EIP712Domain不是全局变量(是evm的EIP712Domainexist方法,因此它可以理解。。。还是存在其他合同?

在您所展示的上下文中,EIP712Domain不是函数或公共属性。它也不是Solidity全局变量。

它只是在delegateBySig()函数中签名的字符串消息的一部分。


ABI代表";应用二进制接口";它是一个包含编码参数的规范(根据规范(。以及您可能熟悉的表示函数定义的JSON。

这个函数的作用是:

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

如果使用参数keccak256(bytes(name))getChainId()address(this)调用EIP712Domain()函数,它将生成与事务数据相同的二进制输出。