eip712-codegen icon indicating copy to clipboard operation
eip712-codegen copied to clipboard

Encode `name` and `version` in EIP712Domain packet hash

Open NIC619 opened this issue 3 years ago • 2 comments

In the generated GET_EIP712DOMAIN_PACKETHASH function, name and version of EIP712Domain struct are of dynamic type (string), should they be encoded as the hash of their contents ?

function GET_EIP712DOMAIN_PACKETHASH (EIP712Domain memory _input) public pure returns (bytes32) {
    
    bytes memory encoded = abi.encode(
      EIP712DOMAIN_TYPEHASH,
      _input.name,
      _input.version,
      _input.chainId,
      _input.verifyingContract
    );
    
    return keccak256(encoded);
}

Expected:

function GET_EIP712DOMAIN_PACKETHASH (EIP712Domain memory _input) public pure returns (bytes32) {
    
    bytes memory encoded = abi.encode(
      EIP712DOMAIN_TYPEHASH,
      keccak256(bytes(_input.name)),
      keccak256(byes(_input.version)),
      _input.chainId,
      _input.verifyingContract
    );
    
    return keccak256(encoded);
}

NIC619 avatar May 25 '22 08:05 NIC619

Oh wow, that's an interesting catch! I'm actually very surprised that all the tests passed considering this variance. I'm going to need to do some extra investigation here. Thanks for reporting.

danfinlay avatar Jan 28 '23 05:01 danfinlay

Oh, it was just a commented suggested code. So we had generated some bad docs but not bad code. Relieving. I'm hoping to add a proper entry-point generator also on a per-type basis, and I'll make sure that works properly.

danfinlay avatar Jan 28 '23 20:01 danfinlay