This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
feat: Use standard RLP transactions #300
Draft
smartcontracts
wants to merge
10
commits into
master
Choose a base branch
from
feat/standard-rlp-transaction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
35f48aa
feat: Use standard RLP transactions
smartcontracts 0cdf826
Better support for chain IDs
smartcontracts d722c02
Cleanup files and add comments
smartcontracts 4d8d722
Expand on why uint8 is ok
smartcontracts b57a94b
Added tests for decoding
smartcontracts 0b76bd9
Added encoding and sender tests
smartcontracts e6ecb6e
Updated config so dump won't throw
smartcontracts 9d87dd3
Merge branch 'master' into feat/standard-rlp-transaction
smartcontracts b3f694f
merge master
smartcontracts 957de33
resolve merge conflicts
smartcontracts 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 |
---|---|---|
|
@@ -3,8 +3,6 @@ pragma solidity >0.5.0 <0.8.0; | |
|
||
/* Library Imports */ | ||
import { Lib_Bytes32Utils } from "../../libraries/utils/Lib_Bytes32Utils.sol"; | ||
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol"; | ||
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. Files were unused, I removed them. |
||
import { Lib_ECDSAUtils } from "../../libraries/utils/Lib_ECDSAUtils.sol"; | ||
import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol"; | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -2,9 +2,7 @@ | |
pragma solidity >0.5.0 <0.8.0; | ||
|
||
/* Library Imports */ | ||
import { Lib_BytesUtils } from "../../libraries/utils/Lib_BytesUtils.sol"; | ||
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol"; | ||
import { Lib_ECDSAUtils } from "../../libraries/utils/Lib_ECDSAUtils.sol"; | ||
import { Lib_EIP155Tx } from "../../libraries/codec/Lib_EIP155Tx.sol"; | ||
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. This file gets way simpler. |
||
import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol"; | ||
|
||
/** | ||
|
@@ -19,109 +17,39 @@ import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_Sa | |
* Runtime target: OVM | ||
*/ | ||
contract OVM_SequencerEntrypoint { | ||
|
||
/********* | ||
* Enums * | ||
*********/ | ||
|
||
enum TransactionType { | ||
NATIVE_ETH_TRANSACTION, | ||
ETH_SIGNED_MESSAGE | ||
} | ||
using Lib_EIP155Tx for Lib_EIP155Tx.EIP155Tx; | ||
|
||
|
||
/********************* | ||
* Fallback Function * | ||
*********************/ | ||
|
||
/** | ||
* Uses a custom "compressed" format to save on calldata gas: | ||
* calldata[00:01]: transaction type (0 == EIP 155, 2 == Eth Sign Message) | ||
* calldata[01:33]: signature "r" parameter | ||
* calldata[33:65]: signature "s" parameter | ||
* calldata[65:66]: signature "v" parameter | ||
* calldata[66:69]: transaction gas limit | ||
* calldata[69:72]: transaction gas price | ||
* calldata[72:75]: transaction nonce | ||
* calldata[75:95]: transaction target address | ||
* calldata[95:XX]: transaction data | ||
*/ | ||
fallback() | ||
external | ||
{ | ||
TransactionType transactionType = _getTransactionType(Lib_BytesUtils.toUint8(msg.data, 0)); | ||
|
||
bytes32 r = Lib_BytesUtils.toBytes32(Lib_BytesUtils.slice(msg.data, 1, 32)); | ||
bytes32 s = Lib_BytesUtils.toBytes32(Lib_BytesUtils.slice(msg.data, 33, 32)); | ||
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. Removes the calls to |
||
uint8 v = Lib_BytesUtils.toUint8(msg.data, 65); | ||
|
||
// Remainder is the transaction to execute. | ||
bytes memory compressedTx = Lib_BytesUtils.slice(msg.data, 66); | ||
bool isEthSignedMessage = transactionType == TransactionType.ETH_SIGNED_MESSAGE; | ||
|
||
// Need to decompress and then re-encode the transaction based on the original encoding. | ||
bytes memory encodedTx = Lib_OVMCodec.encodeEIP155Transaction( | ||
Lib_OVMCodec.decompressEIP155Transaction(compressedTx), | ||
isEthSignedMessage | ||
Lib_EIP155Tx.EIP155Tx memory transaction = Lib_EIP155Tx.decode( | ||
msg.data, | ||
Lib_SafeExecutionManagerWrapper.safeCHAINID() | ||
); | ||
|
||
address target = Lib_ECDSAUtils.recover( | ||
encodedTx, | ||
isEthSignedMessage, | ||
uint8(v), | ||
r, | ||
s | ||
); | ||
address sender = transaction.sender(); | ||
|
||
if (Lib_SafeExecutionManagerWrapper.safeEXTCODESIZE(target) == 0) { | ||
// ProxyEOA has not yet been deployed for this EOA. | ||
bytes32 messageHash = Lib_ECDSAUtils.getMessageHash(encodedTx, isEthSignedMessage); | ||
Lib_SafeExecutionManagerWrapper.safeCREATEEOA(messageHash, uint8(v), r, s); | ||
if (Lib_SafeExecutionManagerWrapper.safeEXTCODESIZE(sender) == 0) { | ||
Lib_SafeExecutionManagerWrapper.safeCREATEEOA( | ||
transaction.hash(), | ||
transaction.recoveryParam, | ||
transaction.r, | ||
transaction.s | ||
); | ||
} | ||
|
||
// ProxyEOA has been deployed for this EOA, continue to CALL. | ||
bytes memory callbytes = abi.encodeWithSignature( | ||
"execute(bytes,uint8,uint8,bytes32,bytes32)", | ||
encodedTx, | ||
isEthSignedMessage, | ||
uint8(v), | ||
r, | ||
s | ||
); | ||
|
||
Lib_SafeExecutionManagerWrapper.safeCALL( | ||
gasleft(), | ||
target, | ||
callbytes | ||
sender, | ||
abi.encodeWithSignature( | ||
"execute(bytes)", | ||
msg.data | ||
) | ||
); | ||
} | ||
|
||
|
||
/********************** | ||
* Internal Functions * | ||
**********************/ | ||
|
||
/** | ||
* Converts a uint256 into a TransactionType enum. | ||
* @param _transactionType Transaction type index. | ||
* @return Transaction type enum value. | ||
*/ | ||
function _getTransactionType( | ||
uint8 _transactionType | ||
) | ||
internal | ||
returns ( | ||
TransactionType | ||
) | ||
{ | ||
if (_transactionType == 0) { | ||
return TransactionType.NATIVE_ETH_TRANSACTION; | ||
} if (_transactionType == 2) { | ||
return TransactionType.ETH_SIGNED_MESSAGE; | ||
} else { | ||
Lib_SafeExecutionManagerWrapper.safeREVERT( | ||
"Transaction type must be 0 or 2" | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
I know this is WIP, but just noting to remove this