Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
remove extraneous backward slash in '\x19\x01' prefix; example tests …
Browse files Browse the repository at this point in the history
…pass
  • Loading branch information
Ryanmtate committed Oct 6, 2021
1 parent fa95585 commit b54a883
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 34 deletions.
2 changes: 2 additions & 0 deletions ethers-core/ethers-derive-eip712/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ fn impl_eip_712_macro(ast: &syn::DeriveInput) -> TokenStream {
&self.struct_hash()?[..]
].concat();

// let digest_input = &[0x19, 0x01];

return Ok(ethers_core::utils::keccak256(digest_input));

}
Expand Down
27 changes: 13 additions & 14 deletions examples/DeriveEip712Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ contract DeriveEip712Test {

bytes32 constant FOOBAR_DOMAIN_TYPEHASH =
keccak256(
// "FooBar(int256 foo,uint256 bar,bytes fizz,bytes32 buzz,string far,address out)"
"FooBar(int256 foo)"
"FooBar(int256 foo,uint256 bar,bytes fizz,bytes32 buzz,string far,address out)"
);

struct FooBar {
int256 foo;
// uint256 bar;
// bytes fizz;
// bytes32 buzz;
// string far;
// address out;
uint256 bar;
bytes fizz;
bytes32 buzz;
string far;
address out;
}

constructor() {}
Expand Down Expand Up @@ -49,12 +48,12 @@ contract DeriveEip712Test {
keccak256(
abi.encode(
typeHash(),
uint256(fooBar.foo)
// fooBar.bar,
// keccak256(fooBar.fizz),
// fooBar.buzz,
// keccak256(abi.encodePacked(fooBar.far)),
// fooBar.out
uint256(fooBar.foo),
fooBar.bar,
keccak256(fooBar.fizz),
fooBar.buzz,
keccak256(bytes(fooBar.far)),
fooBar.out
)
);
}
Expand All @@ -63,7 +62,7 @@ contract DeriveEip712Test {
return
keccak256(
abi.encodePacked(
"\\x19\\x01",
"\x19\x01",
domainSeparator(),
structHash(fooBar)
)
Expand Down
75 changes: 75 additions & 0 deletions examples/derive_eip712_abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@
"internalType": "int256",
"name": "foo",
"type": "int256"
},
{
"internalType": "uint256",
"name": "bar",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "fizz",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "buzz",
"type": "bytes32"
},
{
"internalType": "string",
"name": "far",
"type": "string"
},
{
"internalType": "address",
"name": "out",
"type": "address"
}
],
"internalType": "struct DeriveEip712Test.FooBar",
Expand All @@ -51,6 +76,31 @@
"internalType": "int256",
"name": "foo",
"type": "int256"
},
{
"internalType": "uint256",
"name": "bar",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "fizz",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "buzz",
"type": "bytes32"
},
{
"internalType": "string",
"name": "far",
"type": "string"
},
{
"internalType": "address",
"name": "out",
"type": "address"
}
],
"internalType": "struct DeriveEip712Test.FooBar",
Expand Down Expand Up @@ -95,6 +145,31 @@
"internalType": "int256",
"name": "foo",
"type": "int256"
},
{
"internalType": "uint256",
"name": "bar",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "fizz",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "buzz",
"type": "bytes32"
},
{
"internalType": "string",
"name": "far",
"type": "string"
},
{
"internalType": "address",
"name": "out",
"type": "address"
}
],
"internalType": "struct DeriveEip712Test.FooBar",
Expand Down
37 changes: 17 additions & 20 deletions examples/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use ethers_derive_eip712::*;
)]
struct FooBar {
foo: I256,
// bar: U256,
// fizz: Vec<u8>,
// buzz: [u8; 32],
// far: String,
// out: Address,
bar: U256,
fizz: Vec<u8>,
buzz: [u8; 32],
far: String,
out: Address,
}

abigen!(
Expand Down Expand Up @@ -61,31 +61,28 @@ async fn main() -> anyhow::Result<()> {

let foo_bar = FooBar {
foo: I256::from(10),
// bar: U256::from(20),
// fizz: b"fizz".to_vec(),
// buzz: keccak256("buzz"),
// far: String::from("space"),
// out: Address::from([0; 20]),
bar: U256::from(20),
fizz: b"fizz".to_vec(),
buzz: keccak256("buzz"),
far: String::from("space"),
out: Address::from([0; 20]),
};

let derived_foo_bar = deriveeip712test_mod::FooBar {
foo: foo_bar.foo.clone(),
// bar: foo_bar.bar.clone(),
// fizz: foo_bar.fizz.clone(),
// buzz: foo_bar.buzz.clone(),
// far: foo_bar.far.clone(),
// out: foo_bar.out.clone(),
bar: foo_bar.bar.clone(),
fizz: foo_bar.fizz.clone(),
buzz: foo_bar.buzz.clone(),
far: foo_bar.far.clone(),
out: foo_bar.out.clone(),
};

let sig = wallet.sign_typed_data(foo_bar.clone()).await?;

let mut r = [0; 32];
let mut s = [0; 32];
let r = <[u8; 32]>::try_from(sig.r)?;
let s = <[u8; 32]>::try_from(sig.s)?;
let v = u8::try_from(sig.v)?;

sig.r.to_big_endian(&mut r);
sig.r.to_big_endian(&mut s);

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?;
Expand Down

0 comments on commit b54a883

Please sign in to comment.