-
Notifications
You must be signed in to change notification settings - Fork 795
derive-eip712: initial implementation of eip712 derive macro #481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments/questions/recommendations
f050b90
to
4fd6df0
Compare
@gakonst @mattsse Looking to finish up on the example and tests today and open for a review. One last issue I am battling is with the Able to confirm
function encodeEip712(FooBar memory fooBar) public pure returns (bytes32) {
return
keccak256(
abi.encodePacked(
"\\x19\\x01",
domainSeparator(),
structHash(fooBar)
)
);
}
let domain_separator = contract.domain_separator().call().await?;
let type_hash = contract.type_hash().call().await?;
let struct_hash = contract.struct_hash(derived_foo_bar.clone()).call().await?;
let encoded = contract
.encode_eip_712(derived_foo_bar.clone())
.call()
.await?;
let verify = contract
.verify_foo_bar(wallet.address(), derived_foo_bar, r, s, v)
.call()
.await?;
assert_eq!(
domain_separator,
FooBar::domain_separator()?,
"domain separator does not match contract domain separator!"
);
assert_eq!(
type_hash,
FooBar::type_hash()?,
"type hash does not match contract struct type hash!"
);
assert_eq!(
struct_hash,
foo_bar.clone().struct_hash()?,
"struct hash does not match contract struct struct hash!"
);
assert_eq!(
encoded,
foo_bar.encode_eip712()?,
"Encoded value does not match!"
); |
hmm,
but this would mean that abi.encodePacked(
"\\x19\\x01",
domainSeparator(),
structHash(fooBar)
) is not identical to let digest_input = [
&[0x19, 0x01],
&Self::domain_separator()?[..],
&self.struct_hash()?[..]
].concat(); and since the values (domainSeparator, structHash) are identical (ensured by the test), this would indicate |
I think |
Great news! The problem was much simpler. Let it be known that Going to open this up for review after resolving merge conflicts. |
922fcbd
to
b54a883
Compare
does &[x19, x01][..] do? |
This commit provides an initial implementation for a derive macro to encode typed data according to EIP-712, https://eips.ethereum.org/EIPS/eip-712 Additionally, this commit introduces a new signer trait method: async fn sign_typed_data<T: Eip712 + Send + Sync>( &self, payload: &T, ) -> Result<Signature, Self::Error>; And implements the new method for each of the signers (wallet, ledger, aws). Additionally, these changes include using `WalletError` for the Wallet signer error type At the moment, derive does not recurse the primary type to find nested Eip712 structs. This is something that is noted in the source and currently responds with an error regarding custom types. A subsequent PR should be opened once this issue becomes needed. For the moment, the current implementation should satisfy non-nested, basic struct types.
…tant for domain type hash
b54a883
to
714e2fb
Compare
Finding some issues in the signer methods, so let's hold off from merging until can confirm correctness. |
1ff35c6
to
8b3ce45
Compare
8b3ce45
to
6cb3fed
Compare
2803a3c
to
568babc
Compare
try using 'sign_message'
568babc
to
909c491
Compare
Was able to manually test 909c491 is working for sign typed data and recoverable inside solidity with I have not tested AWS signer, and would love if someone who has a setup can check it out. |
Also still open to comments for possibly relocating files to enable re-exportation of the derive macro. I agree current user experience is not great with having to add another dependency. But doing will require some re-working of the file struct so we are not hitting a circular dependency. |
Thanks to @sebastinez for helping test ledger signer! |
@mattsse @Ryanmtate I think the best way to resolve the cyclical dependency is for us to make an I'm OK with merging as-is now, and we can resolve the deps in a follow-up PR |
second that, |
Just need to fix the solc version to be the same one as the one installed in CI. The WASM test is also seemingly failing, is this a flake? |
weird, only the http provider wasm test fails due to a 400 |
@Ryanmtate need to enable abi encoder v2 i think |
🎉 |
kudos @Ryanmtate! 🥳 |
This commit provides an initial implementation for a derive macro
to encode typed data according to EIP-712, https://eips.ethereum.org/EIPS/eip-712
Additionally, this commit introduces a new signer trait method:
And implements the new method for each of the signers (wallet, ledger,
aws).
At the moment, derive does not recurse the primary type to find nested
Eip712 structs. In the future, a field helper attribute
#[eip712]
could beused to denote a nested field and handle the proper encoding for the field.
Motivation
#16
Solution
This implementation is based on the proposed solution in #16 .
PR Checklist