Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP712 support for bytes and uint formatted as string #427

Merged
merged 2 commits into from
Jan 10, 2023

Conversation

moisses89
Copy link
Member

@moisses89 moisses89 commented Jan 9, 2023

Closes #424

Description

eip712_encode_hash is using eth-abi that doesn't support the type bytes and uint formatted as string.
Type bytes and bytesN on eth-abi only accept python bytes, this was fixed including a conversion for bytes formatted on string to python bytes.
Type uint only accept Numbers, this was fixed converting from string to python Integer.

Additional changes

  • Add test for string uint
  • Add test for string bytes

@moisses89 moisses89 requested a review from a team as a code owner January 9, 2023 15:29
@moisses89 moisses89 requested review from fmrsabino, Uxio0 and hectorgomezv and removed request for a team January 9, 2023 15:29
@coveralls
Copy link

coveralls commented Jan 9, 2023

Pull Request Test Coverage Report for Build 3882828086

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 90.31%

Totals Coverage Status
Change from base Build 3749167831: 0.0%
Covered Lines: 3523
Relevant Lines: 3901

💛 - Coveralls

@moisses89 moisses89 changed the title eip712_encode_hash encode string bytes and string uint256 Add EIP712 support for bytes and uint formatted as string Jan 10, 2023
Copy link
Contributor

@fmrsabino fmrsabino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👏 🚀

{"name": "maxByte", "type": "bytes32"},
],
}
# test string uint (chainId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this comment does not apply to this test right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, copy pasted from above, done fa4a21f

@moisses89 moisses89 merged commit d305f1f into master Jan 10, 2023
@moisses89 moisses89 deleted the add_string_uint_and_bytes_to_encode_712 branch January 10, 2023 11:26
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2023
Copy link
Member

@Uxio0 Uxio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moisses89 I think these things should be addressed in a new PR

@@ -57,6 +57,14 @@ def _encode_field(name, typ, value):
if value is None:
raise Exception(f"Missing value for field {name} of type {type}")

# Accept string bytes
if "bytes" in typ and isinstance(value, str):
value = bytes.fromhex(value.replace("0x", ""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value = HexBytes(value)

if "bytes" in typ and isinstance(value, str):
value = bytes.fromhex(value.replace("0x", ""))

# Accept string uint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should support any kind of integer, not only uint. This is a very misleading behaviour:

if "int" in typ

@@ -4,6 +4,43 @@


class TestEIP712(TestCase):
address = "0x8e12f01dae5fe7f1122dc42f2cb084f2f9e8aa03"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use checksummed addresses unless we are testing not checksummed addresses:

0x8e12f01DAE5FE7f1122Dc42f2cB084F2f9E8aA03


self.assertEqual(
eip712_encode_hash(payload).hex(),
"2950cf06416c6c20059f24a965e3baf51a24f4ef49a1e7b1a47ee13ee08cde1f",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use hex() here? I think we should be consistent, either using hex() everywhere (it looks better and more readable IMHO) or using binary representation

Copy link
Member Author

@moisses89 moisses89 Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moisses89 I think these things should be addressed in a new PR

Your suggestions sounds good for me, then I add the following PR #437
Regarding if use hex() or binary representation for test, I'd prefer hex() because as you mention is more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eip712_encode_hash encode string bytes and string uint256
4 participants