-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Update EIP-191: Improve Comprehensibility #5804
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1fcd98
improve EIP191 Standard
YamenMerhi 0377a95
update description for EIP712
YamenMerhi 0f462d1
Update EIPS/eip-191.md
YamenMerhi 20cbd13
update example code snippet
YamenMerhi f7acb2a
remove external links and update naming
YamenMerhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,12 @@ We propose the following format for `signed_data` | |
``` | ||
0x19 <1 byte version> <version specific data> <data to sign>. | ||
``` | ||
Version `0` has `<20 byte address>` for the version specific data, and the `address` is the intended validator. In the case of a Multisig wallet, that is the wallet's own address . | ||
|
||
The initial `0x19` byte is intended to ensure that the `signed_data` is not valid [RLP](https://github.com/ethereum/wiki/wiki/RLP) | ||
The initial `0x19` byte is intended to ensure that the `signed_data` is not valid RLP. | ||
|
||
> For a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding. | ||
|
||
That means that any `signed_data` cannot be one RLP-structure, but a 1-byte `RLP` payload followed by something else. Thus, any ERC-191 `signed_data` can never be an Ethereum transaction. | ||
That means that any `signed_data` cannot be one RLP-structure, but a 1-byte `RLP` payload followed by something else. Thus, any EIP-191 `signed_data` can never be an Ethereum transaction. | ||
|
||
Additionally, `0x19` has been chosen because since ethereum/go-ethereum#2940 , the following is prepended before hashing in personal_sign: | ||
|
||
|
@@ -55,29 +54,55 @@ Using `0x19` thus makes it possible to extend the scheme by defining a version ` | |
| `0x01` | [712][eip-712] | Structured data | ||
| `0x45` | [191][eip-191] | `personal_sign` messages | ||
|
||
#### Version `0x00` | ||
|
||
``` | ||
0x19 <0x00> <intended validator address> <data to sign> | ||
``` | ||
|
||
The version `0x00` has `<intended validator address>` for the version specific data. In the case of a Multisig wallet that perform an execution based on a passed signature, the validator address is the address of the Multisig itself. The data to sign could be any arbitrary data. | ||
|
||
#### Version `0x01` | ||
|
||
The version `0x01` is for structured data as defined in [EIP-712] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QQ: Should we mention anything about the EIP-712 "domain" besides the "structured data" here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
#### Version `0x45` (E) | ||
|
||
``` | ||
0x19 <0x45 (E)> <thereum Signed Message:\n" + len(message)> <data to sign> | ||
``` | ||
|
||
The version `0x45` (E) has `<thereum Signed Message:\n" + len(message)>` for the version-specific data. The data to sign can be any arbitrary data. | ||
|
||
> NB: The `E` in `Ethereum Signed Message` refers to the version byte 0x45. The character `E` is `0x45` in hexadecimal which makes the remainder, `thereum Signed Message:\n + len(message)`, the version-specific data. | ||
|
||
[EIP-191]: ./eip-191.md | ||
[EIP-712]: ./eip-712.md | ||
|
||
### Example | ||
|
||
The following snippet has been written in Solidity 0.5.0. | ||
The following snippets has been written in Solidity 0.8.0. | ||
|
||
#### Version `0x00` | ||
|
||
```solidity | ||
function submitTransactionPreSigned(address destination, uint value, bytes data, uint nonce, uint8 v, bytes32 r, bytes32 s) | ||
public | ||
returns (bytes32 transactionHash) | ||
{ | ||
function signatureBasedExecution(address target, uint256 nonce, bytes memory payload, uint8 v, bytes32 r, bytes32 s) public payable { | ||
|
||
// Arguments when calculating hash to validate | ||
// 1: byte(0x19) - the initial 0x19 byte | ||
// 2: byte(0) - the version byte | ||
// 3: this - the validator address | ||
// 4-7 : Application specific data | ||
transactionHash = keccak256(abi.encodePacked(byte(0x19),byte(0),address(this),destination, value, data, nonce)); | ||
sender = ecrecover(transactionHash, v, r, s); | ||
// ... | ||
// 3: address(this) - the validator address | ||
// 4-6 : Application specific data | ||
|
||
bytes32 hash = keccak256(abi.encodePacked(byte(0x19), byte(0), address(this), msg.value, nonce, payload)); | ||
|
||
// recovering the signer from the hash and the signature | ||
addressRecovered = ecrecover(hash, v, r, s); | ||
|
||
// logic of the wallet | ||
// if (addressRecovered == owner) executeOnTarget(target, payload); | ||
} | ||
``` | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](../LICENSE.md). |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I must be missing something here, are we adding the
<0x00> <intended validator address>
to the original EIP-191?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinbenlv The version
0x00
was always there in the standard from the start, but it was not explained very well, and that's one of the purposes of the PR