Use EIP712 signing scheme for bids #2808
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ExpressLaneAuction contract auction resolution methods take Bid objects as arguments which were previously expected to have the signature field populated by using the "\x19Ethereum Signed Message:..." hashing scheme applied over bid, contract, and chain details, then signed. The contracts were updated to use EIP 712 which standardizes a hashing scheme for structured data.
Briefly, EIP 712 produces the hash to be signed as follows: keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message)). The domainSeparator includes chain and contract details to prevent replay attacks, and in our code we just fetch it from the contract using domainSeparator() which internally uses the OpenZepplin library to calculate it for the contract. hashStruct encodes type information about the struct, in this case the "Bid(uint64 round,address expressLaneController,uint256 amount)" along with the data. Geth has an implementation of hashStruct that we use here.
The BidderClient generates the signature and the BidValidator uses the signature and the hash to recover the sender, so these are the places that needed to be updated. This PR also removes Bid.ToMessageBytes as this serialization format was only used for generating the data to be signed under the old scheme, and makes private ValidatedBid.bidBytes and bigIntHash() since these are only used for tiebreaking in the BidCache and nothing to do with signing.
Testing done
Bidding and auction resolution works again after updating to the new contracts.