-
Notifications
You must be signed in to change notification settings - Fork 125
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
Include system contracts #45
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# System Contracts (Revision 0) | ||
|
||
System contracts are interfaces defined as contracts, which are essential or | ||
recommended for an eWASM VM. | ||
|
||
An eWASM VM implementation may opt to implement these interfaces natively | ||
or to rely on implementations written in eWASM. | ||
|
||
Each of these contracts have a pre defined address and can be executed through | ||
regular contract invocations. | ||
|
||
## Sentinel Contract | ||
|
||
Address: `0x000000000000000000000000000000000000000a` | ||
|
||
Every newly deployed eWASM contract must be processed by the *Sentinel Contract* | ||
prior to including the code in the state. The sentinel will perform three very | ||
important processing steps: | ||
- Validate eWASM semantics | ||
- Inject metering code | ||
- Wrap the result in the deployer preamble (*see Appendix A*) | ||
|
||
Input: | ||
- **variable length**: *eWASM contract code* | ||
|
||
Output: | ||
- **variable length**: *eWASM contract code* | ||
|
||
## EVM Transcompiler | ||
|
||
Address: `0x000000000000000000000000000000000000000b` | ||
|
||
This is optional. It is provided for pure eWASM VMs to support EVM1 contracts. | ||
|
||
Input: | ||
- **variable length**: *EVM1 contract code* | ||
|
||
Output: | ||
- **variable length**: *eWASM contract code* | ||
|
||
## EVM Precompiled Contracts | ||
|
||
Precompiled contracts are defined for EVM1 (see the Yellow Paper). Several | ||
extensions have been proposed as *[Ethereum Improvement Proposals](https://github.com/ethereum/EIPs)*. | ||
|
||
We assume the contracts defined in the Yellow Paper still apply for eWASM. | ||
|
||
### ecrecover | ||
|
||
Address: `0x0000000000000000000000000000000000000001` | ||
|
||
Calculates the corresponding Ethereum address for the public key which created the given signature. | ||
|
||
Input: | ||
- **32 bytes**: *message hash* | ||
- **32 bytes**: *recovery id* | ||
- **32 bytes**: *R component* | ||
- **32 bytes**: *S component* | ||
|
||
Output: | ||
- **32 bytes**: *Ethereum address* (left padded with zeroes) | ||
|
||
### sha2-256 | ||
|
||
Address: `0x0000000000000000000000000000000000000002` | ||
|
||
Returns the SHA2-256 hash of the input. | ||
|
||
Input: | ||
- **variable length**: *input data* | ||
|
||
Output: | ||
- **32 bytes**: *sha2-256 hash* | ||
|
||
### ripemd160 | ||
|
||
Address: `0x0000000000000000000000000000000000000003` | ||
|
||
Returns the RIPEMD-160 hash of the input. | ||
|
||
Input: | ||
- **variable length**: *input data* | ||
|
||
Output: | ||
- **32 bytes**: *ripemd160 hash* (left padded with zeroes) | ||
|
||
### identity | ||
|
||
Address: `0x0000000000000000000000000000000000000004` | ||
|
||
Copies the input data to the output. | ||
|
||
Input: | ||
- **variable length**: *input data* | ||
|
||
Output: | ||
- **variable length**: *output data* | ||
|
||
### Appendix A: eWASM deployer preamble | ||
|
||
``` | ||
;; | ||
;; Standard eWASM deployer code. | ||
;; | ||
;; We keep the to-be-deployed contract as a memory segment and simply return it. | ||
;; | ||
|
||
(module | ||
(memory 1 | ||
(segment 0 "\10\00\00\00") ;; Here comes the size of the code in LSB | ||
(segment 4 "Hello World CODE") ;; Here comes the code as a escaped hex string | ||
) | ||
(export "memory" memory) | ||
(export "main" $main) | ||
(import $ethereum_return "ethereum" "return" (param i32 i32)) | ||
(func $main | ||
(call_import $ethereum_return (i32.const 4) (i32.load (i32.const 0))) | ||
) | ||
) | ||
``` |
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.
optional is a bit misleading here
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.
Why? They are optional as in not a mandatory part of a client if it opts to implement EVM1 natively.
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.
yes but they will still need to implement the logic to run the EVM1 when a call goes to that address.
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.
I don't think this is related to the precompile and the transcompiler.
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.
I think this is fine this way now, added the semantics in #54.