ConsenSysMesh / ConsenSysMesh/py-eip712-structs

signable_bytes() and to_message_json() throw exceptions

Open
#14 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
35
Forks
28
PR merge metrics
No merged PRs in 30d

Description

Code in question:

```py
from eip712_structs import EIP712Struct, Address, String, Uint

class Identity(EIP712Struct):
userId = Uint(256)
wallet = Address()

class Message(EIP712Struct):
actionType = String()
timestamp = Uint(256)
authorizer = Identity

class EIP712Domain(EIP712Struct):
name = String()
version = String()
chainId = Uint(256)
verifyingContract = Address()

verifying_contract_domain = EIP712Domain(
name='VerifierApp101',
version='1',
chainId=8995,
verifyingContract='0x8c1eD7e19abAa9f23c476dA86Dc1577F1Ef401f5'
)

user_identification = Identity(userId=123, wallet='0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC')
msg = Message(actionType='Action7440', timestamp=1570112162, authorizer=Identity)

print(msg.to_message_json(verifying_contract_domain))
print(msg.signable_bytes(verifying_contract_domain))
```

`msg.to_message_json(verifying_contract_domain)` throws the following exception:

```
Traceback (most recent call last):
File "submit_proof.py", line 32, in
print(msg.to_message_json(verifying_contract_domain))
File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 188, in to_message_json
return json.dumps(message, cls=BytesJSONEncoder)
File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/types.py", line 244, in default
return super(BytesJSONEncoder, self).default(o)
File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'OrderedAttributesMeta' is not JSON serializable
```

`msg.signable_bytes(verifying_contract_domain)` throws:

```
Traceback (most recent call last):
File "submit_proof.py", line 32, in
print(msg.signable_bytes(verifying_contract_domain))
File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 200, in signable_bytes
result = b'\x19\x01' + domain.hash_struct() + self.hash_struct()
File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 132, in hash_struct
return keccak(b''.join([self.type_hash(), self.encode_value()]))
File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 61, in encode_value
encoded_values.append(sub_struct.hash_struct())
TypeError: hash_struct() missing 1 required positional argument: 'self'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the example and trace struct.py through to_message_json(), signable_bytes(), hash_struct(), and encode_value(); inspect types.py for the JSON encoder involved in the first traceback. Compare the nested authorizer value with the defined user_identification instance, then establish the intended behavior and add coverage for both methods before confirming the exceptions are resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cryptography
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.