Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Contract eth_signTypedData#176

Merged
loredanacirstea merged 6 commits intoraiden-network:masterfrom
loredanacirstea:contract-eth_signTypedData
Nov 25, 2017
Merged

Contract eth_signTypedData#176
loredanacirstea merged 6 commits intoraiden-network:masterfrom
loredanacirstea:contract-eth_signTypedData

Conversation

@loredanacirstea
Copy link
Copy Markdown
Contributor

@loredanacirstea loredanacirstea commented Nov 24, 2017

fixes #139 (EIP712 proposal)
fixes #140 (gas cost)
fixes #86 (string concatenations -> ugly code)

  • use eth_signTypedData-based logic for balance proof messages instead of personal_sign
  • remove string concatenation code used to recreate balance proof messages inside the contract
  • add & fix tests

Reasons for not supporting both EIP712 & previous logic for verifying the balance proof:

  • we remove code that is harder to follow and that could hide potential vulnerabilities
  • we avoid having to introduce another parameter for specifying which verifyBalanceProof function to use when closing a channel.

Other reasons for implementing EIP712:

  • high gas cost for closing a channel; e.g. cooperative close 194k gas

Populus gas cost estimations now, with eth_signTypedData-based logic (might be higher in real life):
test_close_by_receiver 60149
test_close_by_sender 69928 (cooperative close)
test_close_by_sender_challenge_settle_by_receiver 108124
test_close_by_sender_challenge_settle_by_sender 103498

Be aware that:


// Hash the prefixed message string
bytes32 prefixed_message_hash = keccak256(prefixed_message);
var message_hash = keccak256(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you and me both know that this should be kept in sync with the function, but just add a comment here for future maintainers that these hashed strings should be in sync with this function's parameters

returns (address)
{
var hash = keccak256(
keccak256('address Address', 'uint32 Value', 'uint192 Value2'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same coment here

names e.g. ('receiver', 'block_created', 'balance')
data e.g. ('0x5601ea8445a5d96eeebf89a67c4199fbb7a43fbb', 3000, 1000)
"""
assert len(types) == len(data) == len(names), 'Check argument length.'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the assert message should not read like a comment, but like an error message. So something like:
'Argument tuple length mismatch'

from utils.sign import eth_signed_typed_data_message

def balance_proof_hash(receiver, block, balance):
return eth_signed_typed_data_message(('address', ('uint', 32), ('uint', 192)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Style:

   return eth_signed_typed_data_message(
       ('address', ('uint', 32), ('uint', 192)),
       ('receiver', 'block_created', 'balance'),
       (receiver, block, balance)
)


contract_verified_address = contract.call().verifyBalanceProof(
receiver, open_block_number,
balance, balance_msg_sig)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

style: Close parentheses in its own line. Each arg in its own line

web3.testing.mine(30)
verified_address = ecverify_test_contract.call().verify_ecrecover_output(hash_prefixed_message, r, s, v)
verified_address = ecverify_test_contract.call().verify_ecrecover_output(balance_message_hash, r, s, v)
# assert address == verified_address
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove commented line

balance_msg_sig, addr = sign.check(balance_message_hash, tester.k0)
assert addr == A

# r = signed_message[:32];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove commented lines

@LefterisJP
Copy link
Copy Markdown
Contributor

Left some comments. Once addressed this looks good.

Finally, getting rid of those ugly string concatenations :)

@loredanacirstea
Copy link
Copy Markdown
Contributor Author

Comments addressed

@loredanacirstea loredanacirstea merged commit a911f42 into raiden-network:master Nov 25, 2017
@loredanacirstea loredanacirstea deleted the contract-eth_signTypedData branch November 25, 2017 18:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

2 participants