-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Adds initial versions of our account abstraction contracts #243
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
Changes from all commits
6faba38
7751a17
fc5e08a
1e80486
ad43ea6
79aed11
94027ac
ab14ee7
575955c
37e3e31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| pragma solidity ^0.5.0; | ||
|
|
||
| /* Library Imports */ | ||
| import { DataTypes } from "../utils/libraries/DataTypes.sol"; | ||
| import { TransactionParser } from "../utils/libraries/TransactionParser.sol"; | ||
| import { ECDSAUtils } from "../utils/libraries/ECDSAUtils.sol"; | ||
| import { ExecutionManagerWrapper } from "../utils/libraries/ExecutionManagerWrapper.sol"; | ||
| import { RLPReader } from "../utils/libraries/RLPReader.sol"; | ||
|
|
||
| /* Contract Imports */ | ||
| import { ExecutionManager } from "../ovm/ExecutionManager.sol"; | ||
|
|
||
| /** | ||
| * @title ECDSAContractAccount | ||
| * @dev NOTE: This contract must be made upgradeable! | ||
| */ | ||
| contract ECDSAContractAccount { | ||
| /* | ||
| * Constructor | ||
| */ | ||
|
|
||
| constructor() | ||
| public | ||
| { | ||
| // TODO: Pay the Sequencer a fee in the ETH ERC-20 token. | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| * Public Functions | ||
| */ | ||
|
|
||
| /** | ||
| * Executes a signed transaction. | ||
| * @param _transaction Signed EOA transaction. | ||
| * @param _isEthSignedMessage Whether or not the user used the `Ethereum Signed Message` prefix. | ||
| * @param _v Signature `v` parameter. | ||
| * @param _r Signature `r` parameter. | ||
| * @param _s Signature `s` parameter. | ||
| * @return Result of executing the transaction. | ||
| */ | ||
| function execute( | ||
| bytes memory _transaction, | ||
| bool _isEthSignedMessage, | ||
| uint8 _v, | ||
| bytes32 _r, | ||
| bytes32 _s | ||
| ) | ||
| public | ||
| returns ( | ||
| bytes memory _ret | ||
| ) | ||
| { | ||
| DataTypes.EOATransaction memory decodedTx = TransactionParser.decodeEOATransaction( | ||
| _transaction | ||
| ); | ||
| bytes memory encodedTx = TransactionParser.encodeEOATransaction( | ||
| decodedTx, | ||
| _isEthSignedMessage | ||
| ); | ||
|
|
||
| ExecutionManager executionManager = ExecutionManager(msg.sender); | ||
|
|
||
| require( | ||
| ECDSAUtils.recover( | ||
| encodedTx, | ||
| _isEthSignedMessage, | ||
| _v, | ||
| _r, | ||
| _s, | ||
| ExecutionManagerWrapper.ovmCHAINID(address(executionManager)) | ||
| ) == ExecutionManagerWrapper.ovmADDRESS(address(executionManager)), | ||
| "Provided signature is invalid." | ||
| ); | ||
|
Contributor
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. Ugh one horrible note is that if we transpile revert (which we have to) we will need to transpile this contract so that we don't actually REVERT when this require fails. 😭 I guess this is an argument for not adding upgradability until we have the final version of the contracts because we'll have to change a bunch of stuff when we rewrite these contracts anyway |
||
|
|
||
| uint256 expectedNonce = executionManager.ovmGETNONCE() + 1; | ||
| require( | ||
| decodedTx.nonce == expectedNonce, | ||
| "Nonce must match expected nonce." | ||
| ); | ||
| executionManager.ovmSETNONCE(expectedNonce); | ||
|
|
||
| if (decodedTx.to == address(0)) { | ||
| _ret = abi.encode( | ||
| ExecutionManagerWrapper.ovmCREATE( | ||
| address(executionManager), | ||
| decodedTx.data, | ||
| decodedTx.gasLimit | ||
| ) | ||
| ); | ||
| } else { | ||
| _ret = ExecutionManagerWrapper.ovmCALL( | ||
| address(executionManager), | ||
| decodedTx.to, | ||
| decodedTx.data, | ||
| decodedTx.gasLimit | ||
| ); | ||
| } | ||
|
|
||
| return _ret; | ||
|
Contributor
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. Ah I just realized that this does not include fee logic! We'll need to add an ERC20 contract precompile which is at a fixed address & which we use for collecting fees inside of the EOA account. Again, either we add it here / include in this PR or we'll need to make another ticket for it |
||
| } | ||
| } | ||
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.
Right now this EOA contract is not upgradable but it definitely should be & also shouldn't be hard to make it. This contract won't have to change too much but we just need to make a more generalized:
EOAContractwhich starts out with it'simplementationAddresspointing at this contract, as well as a simple functionSo it's important that we allow upgradability
should add a very simple function to this in order to enable upgradability --
This can be the final form of the EOAContract
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.
So the parent / upgradable contract would look something like:
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.
Good point! I'll add this.