Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

feat: Use standard RLP transactions #300

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

smartcontracts
Copy link
Collaborator

@smartcontracts smartcontracts commented Mar 8, 2021

Description

Updates our sequencer entrypoint and ECDSA contracts to use the standard RLP encoding that we're using in geth now.

Metadata

Fixes

  • Fixes roadmap#754

Contributing Agreement

@smartcontracts smartcontracts marked this pull request as draft March 8, 2021 02:50
@@ -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";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files were unused, I removed them.

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";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file gets way simpler.

@@ -0,0 +1,111 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.9.0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled decoding logic into this file to make review easier. It's mostly the same as what was originally in OVM codec. We can confirm this with some careful review.

@@ -1,98 +0,0 @@
// SPDX-License-Identifier: MIT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File is no longer needed.

@@ -1,95 +0,0 @@
// SPDX-License-Identifier: MIT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this in geth and we shouldn't use this in ethereumjs-vm.

@@ -1,22 +1,4 @@
{
"tests": {
"decompressEIP155Transaction": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests move to new eip155tx library.

address to;
uint256 value;
bytes data;
uint8 recoveryParam;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically just caching the recovery param so that it is only computed once instead of needing to compute it when calling sender which is only called once and is always called. Might save gas to use it depending on how well packed this struct can be made

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Given a chain ID, the recovery param will never change. So it seems a bit easier to compute this once (we do actually end up computing this in two different places otherwise).

@tynes
Copy link
Collaborator

tynes commented Mar 8, 2021

Overall good changes. The abi is changing, we need to make sure to not break everything when we publish these changes. Also we dont have hardhat deploy so there are no deployment artifacts in this repo so we need to be mindful about this change.

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the calls to slice which is good

@tynes
Copy link
Collaborator

tynes commented Mar 8, 2021

The calldata size of using a RLP encoded tx is about ~250 gas more than using the custom serialization. Trading a bit of cost for simplicity, but its possible that the gas usage was decreased elsewhere in these changes. We really need automated gas metering in CI

import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol";
import { Lib_SafeMathWrapper } from "../../libraries/wrappers/Lib_SafeMathWrapper.sol";

import { console } from "hardhat/console.sol";
Copy link
Collaborator

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

bytes memory _out
)
{
return writeBytes(abi.encodePacked(_in));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes32 isn't treated any differently from bytes when it comes to RLP.

const message = serializeNativeTransaction(DEFAULT_EIP155_TX)
const sig = await signNativeTransaction(wallet, DEFAULT_EIP155_TX)
const transaction = DEFAULT_EIP155_TX
const encodedTransaction = await wallet.signTransaction(transaction)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests get way simpler.

@@ -0,0 +1,248 @@
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test hash here, but sender implicitly tests this under the hood so it should be fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covers tests for decode, encode, and sender.

"0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d",
"0x01",
"0x00",
false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format is:

[
    "0x00", // nonce
    "0x04a817c800", // gasPrice
    "0x5208", // gasLimit
    "0x3535353535353535353535353535353535353535", // to
    "0x00", // value
    "0x", // data
    "0x25", // v
    "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", // r
    "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", // s
    "0x01", // chainId
    "0x00", // recoveryParam
    false // isCreate
]

@@ -4,10 +4,16 @@ import { expect } from '../../setup'
import { ethers } from 'hardhat'
import { Contract, BigNumber } from 'ethers'

const bigNumberify = (arr) => {
const bnRegex = /^\d+n$/gm
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this generally more reliable. Treat more things as big numbers so that equality checking is easier.

)
const ovmREVERT: any =
Mock__OVM_ExecutionManager.smocked.ovmREVERT.calls[0]
expect(decodeSolidityError(ovmREVERT._data)).to.equal(
'Transaction chainId does not match expected OVM chainId.'
'OVM_ECDSAContractAccount: Transaction was signed with the wrong chain ID.'
)
})

// TEMPORARY: Skip gas checks for minnet.
it.skip(`should revert on insufficient gas`, async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped test has been modified. Should double check it still passes

@smartcontracts smartcontracts marked this pull request as ready for review March 8, 2021 23:06
@smartcontracts smartcontracts changed the title [WIP] feat: Use standard RLP transactions feat: Use standard RLP transactions Mar 8, 2021
@tynes
Copy link
Collaborator

tynes commented Mar 13, 2021

Note that this change must be done in a way that is backwards compatible with the current ctc elements. From the point of view of geth, the old contract must be used when syncing the initial set of transactions. This makes me lean towards not changing the contract and adding a new one that is OVM_SequencerEntrypointv2. This way geth can use the old sequencer entrypoint to sync and switch out at a certain point.

This means that geth needs the old serialization logic still and we need a way to selectively set rawTransaction in the data transport layer based on the how the transaction is serialized

@gakonst
Copy link
Contributor

gakonst commented Mar 19, 2021

CI Fails at:

h_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_ExecutionManager Method=run
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_StateManager     Method=isAuthenticated
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_StateManager     Method=hasAccount
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_StateManager     Method=testAndSetAccountLoaded
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_StateManager     Method=getAccountEthAddress
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_SequencerEntrypoint Message="no method with id: 0x00dede53"
geth_l2_1               | DEBUG[03-16|01:02:16.924] Calling Known Contract                   ID=85f757a4 Name=OVM_ExecutionManager    Method=ovmCHAINID
geth_l2_1               | DEBUG[03-16|01:02:16.925] Reached the end of an OVM execution      ID=85f757a4 Return Data=0x Error="ovm execution failed"
geth_l2_1               | INFO [03-16|01:02:16.925] New block                                index=5     l1-timestamp=1615856583 l1-blocknumber=64 tx-hash=0x40483b4c114a3330ce0afb10500ad4ca304c1a327c5fcab06f0b9b19353074de queue-orign=0 type=0 gas=294814 fees=0 elapsed=4.505ms

gakonst added a commit to ethereum-optimism/go-ethereum that referenced this pull request Mar 23, 2021
@maurelian maurelian marked this pull request as draft March 23, 2021 13:08
@maurelian
Copy link
Collaborator

Converting to draft until checks pass.

@maurelian
Copy link
Collaborator

Is this dead?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants