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

Message and Intents are now hashed as per EIP712 #566

Merged
merged 15 commits into from
Dec 21, 2018

Conversation

schemar
Copy link
Contributor

@schemar schemar commented Dec 20, 2018

The Message, StakeIntent, and RedeemIntent now have a new structure and
different fields that are part of the hash. Stake and redeem intent now
consist of amount, beneficiary, and (originating) gateway address. The
Message has as first parameter a hash which is not specific to staking
or redeeming.
All three pre-images now include a type hash as per EIP712.

This means that I was able to remove a lot of stake/redeem specific code
for message hashing. A message's hash is now generated regardless of the
kind of intent it holds.

I added a method storeMessage which creates a message hash and stores
the message at the hash in the mapping. The reason was to circumvent a
"stack too deep" error which prevented me from creating the hash
directly in confirm stake/redeem intent.

I restructured the tests in an effort to make them more easily
understandable. I spent quite some time wrapping my head around the
construct.

I did not add the domain separator yet, as the hashes are never signed
or the signature proven/verified.

⚠️ Please check that the new logic of how and what is hashed
still guarantees correctness and prevents fraud when relaying the
messages ⚠️

Fixes #415

The Message, StakeIntent, and RedeemIntent now have a new structure and
different fields that are part of the hash. Stake and redeem intent now
consist of amount, beneficiary, and (originating) gateway address. The
Message has as first parameter a hash which is not specific to staking
or redeeming.
All three pre-images now include a type hash as per EIP712.

This means that I was able to remove a lot of stake/redeem specific code
for message hashing. A message's hash is now generated regardless of the
kind of intent it holds.

I added a method `storeMessage` which creates a message hash and stores
the message at the hash in the mapping. The reason was to circumvent a
"stack too deep" error which prevented me from creating the hash
directly in confirm stake/redeem intent.

I restructured the tests in an effort to make them more easily
understandable. I spent quite some time wrapping my head around the
construct.

I did not add the domain separator yet, as the hashes are never signed
or the signature proven/verified.

:warning: Please check that the new logic of how and what is hashed
still guarantees correctness and prevents fraud when relaying the
messages :warning:

Fixes OpenST#415
intentHash,
_stakerNonce,
_gasPrice,
_gasLimit
_gasLimit,
_staker,
Copy link
Contributor

@benjaminbollen benjaminbollen Dec 20, 2018

Choose a reason for hiding this comment

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

a message now has a sender address?
correction: it already did. I'll review tomorrow as well, but don't wait for me as I'll be traveling.

Copy link
Contributor

@deepesh-kn deepesh-kn left a comment

Choose a reason for hiding this comment

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

👍 Nice.
Just a few comments.

In general, we should align everyone on JS style guide. One set of IDEs are adding spaces in the new line and {abc: abc} and another set of IDEs are removing it. We should fix this for all.

contracts/gateway/GatewayBase.sol Show resolved Hide resolved
contracts/lib/MessageBus.sol Outdated Show resolved Hide resolved
contracts/lib/MessageBus.sol Outdated Show resolved Hide resolved
test/gateway/eip20_cogateway/helpers/co_gateway_utils.js Outdated Show resolved Hide resolved
test/gateway/eip20_cogateway/helpers/co_gateway_utils.js Outdated Show resolved Hide resolved
/** Maps messageHash to the Message object. */
mapping(bytes32 => MessageBus.Message) messages;
mapping(bytes32 => MessageBus.Message) internal messages;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be public? Any issue if it will be public?
In one of the other open PR, its changed to public

test/test_lib/utils.js Outdated Show resolved Hide resolved
test/test_lib/message_bus.js Show resolved Hide resolved
contracts/gateway/EIP20CoGateway.sol Show resolved Hide resolved
contracts/gateway/EIP20Gateway.sol Show resolved Hide resolved
Copy link
Contributor Author

@schemar schemar left a comment

Choose a reason for hiding this comment

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

Addressed the feedback in code and comments. Still fixing some tests, but please have a look.

contracts/gateway/EIP20CoGateway.sol Show resolved Hide resolved
contracts/gateway/EIP20Gateway.sol Show resolved Hide resolved
contracts/gateway/GatewayBase.sol Show resolved Hide resolved
contracts/lib/MessageBus.sol Outdated Show resolved Hide resolved
contracts/lib/MessageBus.sol Outdated Show resolved Hide resolved
test/gateway/eip20_cogateway/helpers/co_gateway_utils.js Outdated Show resolved Hide resolved
test/gateway/eip20_cogateway/helpers/co_gateway_utils.js Outdated Show resolved Hide resolved
test/lib/messagebus/messagebus_utils.js Outdated Show resolved Hide resolved
test/test_lib/message_bus.js Show resolved Hide resolved
test/test_lib/utils.js Outdated Show resolved Hide resolved
Copy link
Contributor

@0xsarvesh 0xsarvesh left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 🤖 🙌
Only 3 minors comments.
This is a big PR, it was very hard to follow changes. 😢

contracts/gateway/GatewayBase.sol Outdated Show resolved Hide resolved
contracts/lib/MessageBus.sol Outdated Show resolved Hide resolved
@@ -670,7 +641,7 @@ library MockMessageBus {
{
messageHash_ = keccak256(
abi.encode(
_messageTypeHash,
// TODO: add type hash
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😱 Fixed
However, I had to add a header to the MessageBus library. Any better ideas?

/cc @deepesh-kn

Copy link
Contributor Author

@schemar schemar left a comment

Choose a reason for hiding this comment

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

Thanks I made some changes and added some comments.

⚠️ Important:

  1. The MockMessageBus was missing the typehash as part of the message hash (/cc @deepesh-kn)
  2. I am not certain about the MessageBus methods confirm... and progress.... There are offsets and indexes that may be wrong (inbox/outbox confusion).

image

contracts/gateway/GatewayBase.sol Outdated Show resolved Hide resolved
@@ -670,7 +641,7 @@ library MockMessageBus {
{
messageHash_ = keccak256(
abi.encode(
_messageTypeHash,
// TODO: add type hash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😱 Fixed
However, I had to add a header to the MessageBus library. Any better ideas?

/cc @deepesh-kn

Copy link
Contributor Author

@schemar schemar left a comment

Choose a reason for hiding this comment

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

image

@schemar schemar merged commit 8fbf0b4 into OpenST:develop Dec 21, 2018
@schemar schemar deleted the eip712_hashing branch December 21, 2018 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants