-
Notifications
You must be signed in to change notification settings - Fork 3.9k
refactor[contracts]: Port OVM_ECDSAContractAccount to use ovm-solc #546
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
7c26e74
48e30f6
d31173b
21fdc8d
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,5 @@ | ||
| --- | ||
| "@eth-optimism/contracts": patch | ||
| --- | ||
|
|
||
| Ports OVM_ECDSAContractAccount to use optimistic-solc. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // @unsupported: evm | ||
| pragma solidity >0.5.0 <0.8.0; | ||
| pragma experimental ABIEncoderV2; | ||
|
|
||
|
|
@@ -8,16 +9,21 @@ import { iOVM_ECDSAContractAccount } from "../../iOVM/accounts/iOVM_ECDSAContrac | |
| /* Library Imports */ | ||
| import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol"; | ||
| import { Lib_ECDSAUtils } from "../../libraries/utils/Lib_ECDSAUtils.sol"; | ||
| import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol"; | ||
| import { Lib_SafeMathWrapper } from "../../libraries/wrappers/Lib_SafeMathWrapper.sol"; | ||
| import { Lib_ExecutionManagerWrapper } from "../../libraries/wrappers/Lib_ExecutionManagerWrapper.sol"; | ||
|
|
||
| /* Contract Imports */ | ||
| import { OVM_ETH } from "../predeploys/OVM_ETH.sol"; | ||
|
|
||
| /* External Imports */ | ||
| import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; | ||
|
|
||
| /** | ||
| * @title OVM_ECDSAContractAccount | ||
| * @dev The ECDSA Contract Account can be used as the implementation for a ProxyEOA deployed by the | ||
| * ovmCREATEEOA operation. It enables backwards compatibility with Ethereum's Layer 1, by | ||
| * providing eth_sign and EIP155 formatted transaction encodings. | ||
| * | ||
| * Compiler used: solc | ||
| * Compiler used: optimistic-solc | ||
| * Runtime target: OVM | ||
| */ | ||
| contract OVM_ECDSAContractAccount is iOVM_ECDSAContractAccount { | ||
|
|
@@ -29,7 +35,7 @@ contract OVM_ECDSAContractAccount is iOVM_ECDSAContractAccount { | |
| // TODO: should be the amount sufficient to cover the gas costs of all of the transactions up | ||
| // to and including the CALL/CREATE which forms the entrypoint of the transaction. | ||
| uint256 constant EXECUTION_VALIDATION_GAS_OVERHEAD = 25000; | ||
| address constant ETH_ERC20_ADDRESS = 0x4200000000000000000000000000000000000006; | ||
| OVM_ETH constant ovmETH = OVM_ETH(0x4200000000000000000000000000000000000006); | ||
|
|
||
|
|
||
| /******************** | ||
|
|
@@ -66,75 +72,75 @@ contract OVM_ECDSAContractAccount is iOVM_ECDSAContractAccount { | |
| // recovered address of the user who signed this message. This is how we manage to shim | ||
| // account abstraction even though the user isn't a contract. | ||
| // Need to make sure that the transaction nonce is right and bump it if so. | ||
| Lib_SafeExecutionManagerWrapper.safeREQUIRE( | ||
| require( | ||
| Lib_ECDSAUtils.recover( | ||
| _transaction, | ||
| isEthSign, | ||
| _v, | ||
| _r, | ||
| _s | ||
| ) == Lib_SafeExecutionManagerWrapper.safeADDRESS(), | ||
| ) == address(this), | ||
| "Signature provided for EOA transaction execution is invalid." | ||
| ); | ||
|
|
||
| Lib_OVMCodec.EIP155Transaction memory decodedTx = Lib_OVMCodec.decodeEIP155Transaction(_transaction, isEthSign); | ||
| Lib_OVMCodec.EIP155Transaction memory decodedTx = Lib_OVMCodec.decodeEIP155Transaction( | ||
| _transaction, | ||
| isEthSign | ||
| ); | ||
|
|
||
| // Grab the chain ID of the current network. | ||
| uint256 chainId; | ||
| assembly { | ||
| chainId := chainid() | ||
| } | ||
|
|
||
| // Need to make sure that the transaction chainId is correct. | ||
| Lib_SafeExecutionManagerWrapper.safeREQUIRE( | ||
| decodedTx.chainId == Lib_SafeExecutionManagerWrapper.safeCHAINID(), | ||
| require( | ||
| decodedTx.chainId == chainId, | ||
| "Transaction chainId does not match expected OVM chainId." | ||
| ); | ||
|
|
||
| // Need to make sure that the transaction nonce is right. | ||
| Lib_SafeExecutionManagerWrapper.safeREQUIRE( | ||
| decodedTx.nonce == Lib_SafeExecutionManagerWrapper.safeGETNONCE(), | ||
| require( | ||
| decodedTx.nonce == Lib_ExecutionManagerWrapper.ovmGETNONCE(), | ||
| "Transaction nonce does not match the expected nonce." | ||
| ); | ||
|
|
||
| // TEMPORARY: Disable gas checks for mainnet. | ||
| // // Need to make sure that the gas is sufficient to execute the transaction. | ||
| // Lib_SafeExecutionManagerWrapper.safeREQUIRE( | ||
| // gasleft() >= Lib_SafeMathWrapper.add(decodedTx.gasLimit, EXECUTION_VALIDATION_GAS_OVERHEAD), | ||
| // require( | ||
| // gasleft() >= SafeMath.add(decodedTx.gasLimit, EXECUTION_VALIDATION_GAS_OVERHEAD), | ||
| // "Gas is not sufficient to execute the transaction." | ||
| // ); | ||
|
|
||
| // Transfer fee to relayer. | ||
| address relayer = Lib_SafeExecutionManagerWrapper.safeCALLER(); | ||
| uint256 fee = Lib_SafeMathWrapper.mul(decodedTx.gasLimit, decodedTx.gasPrice); | ||
| (bool success, ) = Lib_SafeExecutionManagerWrapper.safeCALL( | ||
| gasleft(), | ||
| ETH_ERC20_ADDRESS, | ||
| abi.encodeWithSignature("transfer(address,uint256)", relayer, fee) | ||
| ); | ||
| Lib_SafeExecutionManagerWrapper.safeREQUIRE( | ||
| success == true, | ||
| require( | ||
| ovmETH.transfer( | ||
| msg.sender, | ||
| SafeMath.mul(decodedTx.gasLimit, decodedTx.gasPrice) | ||
| ), | ||
| "Fee was not transferred to relayer." | ||
| ); | ||
|
|
||
| // Contract creations are signalled by sending a transaction to the zero address. | ||
| if (decodedTx.to == address(0)) { | ||
| (address created, bytes memory revertData) = Lib_SafeExecutionManagerWrapper.safeCREATE( | ||
| gasleft(), | ||
| (address created, bytes memory revertdata) = Lib_ExecutionManagerWrapper.ovmCREATE( | ||
|
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. Why do we need to wrap
Collaborator
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. see https://github.com/ethereum-optimism/optimism/pull/475/files#r617100336 for a discussion of the alternative using
Contributor
Author
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. Yes, agree with Ben here. Doing |
||
| decodedTx.data | ||
| ); | ||
|
|
||
| // Return true if the contract creation succeeded, false w/ revertData otherwise. | ||
| // Return true if the contract creation succeeded, false w/ revertdata otherwise. | ||
| if (created != address(0)) { | ||
| return (true, abi.encode(created)); | ||
| } else { | ||
| return (false, revertData); | ||
| return (false, revertdata); | ||
| } | ||
| } else { | ||
| // We only want to bump the nonce for `ovmCALL` because `ovmCREATE` automatically bumps | ||
| // the nonce of the calling account. Normally an EOA would bump the nonce for both | ||
| // cases, but since this is a contract we'd end up bumping the nonce twice. | ||
| Lib_SafeExecutionManagerWrapper.safeINCREMENTNONCE(); | ||
| Lib_ExecutionManagerWrapper.ovmINCREMENTNONCE(); | ||
|
|
||
| return Lib_SafeExecutionManagerWrapper.safeCALL( | ||
| gasleft(), | ||
| decodedTx.to, | ||
| decodedTx.data | ||
| ); | ||
| return decodedTx.to.call(decodedTx.data); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './contract-defs' | ||
| export { getLatestStateDump, StateDump } from './contract-dumps' | ||
| export * from './contract-deployment' | ||
| export * from './predeploys' |
Uh oh!
There was an error while loading. Please reload this page.