Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Update Order Hash Algo to be EIP712 Compliant #276

Merged
merged 9 commits into from Nov 9, 2018

Conversation

felix2feng
Copy link
Contributor

@felix2feng felix2feng commented Nov 9, 2018

This is the first PR to start building abstracting out signatures.

  • EIP712 File mostly taken from 0x
  • Also included changes required in set-protocol-utils which has already been merged.

pure
returns (bytes32)
{
return EIP712Library.hashEIP712Message(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the order hash now is doubly hashed with the EIP712 Domain

pure
returns(bytes32)
{
// Hash the order parameters
return keccak256(
abi.encodePacked(
EIP712_ORDER_SCHEMA_HASH, // EIP 712 order schema 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.

Note that the order hash now includes the schema hash

Copy link
Contributor

@asoong asoong left a comment

Choose a reason for hiding this comment

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

LGTM

/* ============ Constants ============ */

// EIP191 header for EIP712 prefix
string constant internal EIP191_HEADER = "\x19\x01";
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these are being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, it is being represented in the assembly on line 88.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it's not used, remove?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or leave it in a comment where it's being used

* @param hashStruct The EIP712 hash struct.
* @return EIP712 hash applied to this EIP712 Domain.
*/
function hashEIP712Message(bytes32 hashStruct)
Copy link
Contributor

Choose a reason for hiding this comment

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

Put parameter on its own line

{
bytes32 eip712DomainHash = EIP712_DOMAIN_HASH;

// Assembly for more efficient computing:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove


mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000) // EIP191 header
mstore(add(memPtr, 2), eip712DomainHash) // EIP712 domain hash
mstore(add(memPtr, 34), hashStruct) // Hash of struct
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does 34 come from? domain hash plus header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its 2 (previous) + 32 bytes

*
* @return bytes32 Hash of the EIP712 Set Protocol Domain
*/
function getEIP712DomainHash() internal view returns (bytes32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Signature does not match our other function signatures. Standardize

// Hash for the EIP712 Order Schema
bytes32 constant public EIP712_ORDER_SCHEMA_HASH = keccak256(
abi.encodePacked(
"IssuanceOrder(",
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened to adding the coreAddress?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Domain Separator schema fields are all optional. The address is a good way to delineate further between dapps, but isn't really required. It also adds unnecessary complexity atm.

*
* @return bytes32 Hash of the Issuance Order Schema
*/
function getEIP712OrderSchemaHash() internal view returns (bytes32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update me!

limitations under the License.
*/

pragma solidity 0.4.24;
Copy link
Contributor

Choose a reason for hiding this comment

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

.25? Might need to rebase

});

describe('#getEIP712DomainHash', async () => {
const expectedEIP712Hash: Bytes = '0xa8dcc602486c63f3c678c9b3c5d615c4d6ab4b7d51868af6881272b5d8bb31ff';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you show how this was generated? Is it from a method in utils?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was done in a round-about way. Used the contracts to generate the hash, then updated utils (and its associated unit tests)

it('should return the correct hash', async () => {
const expectedHash = '0x5686079a65f95107943e531f6f7f755044148600233246c75fdce6e59c85cae5';
const returnedHash = await subject();
expect(returnedHash).to.equal(expectedHash);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

const hash = await subject()

const expectedHash = blah
assert hash = expectedHash

@coveralls
Copy link

coveralls commented Nov 9, 2018

Pull Request Test Coverage Report for Build 2694

  • 8 of 8 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 2685: 0.0%
Covered Lines: 564
Relevant Lines: 564

💛 - Coveralls

@felix2feng felix2feng merged commit 78078e5 into master Nov 9, 2018
@felix2feng felix2feng deleted the felix/signature-abstraction branch November 9, 2018 21:38
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.

None yet

3 participants