Skip to content

Commit

Permalink
Extract StateManager from ExecutionManager (#132)
Browse files Browse the repository at this point in the history
* Pull StateManager out into its own contract

* Pass remaining StateManager tests

* Pass OVM tests

* Move deployCodeContract into the StateManager

* Move purity checking into the FullStateManager

* Fix bug where we didn't check initcode purity

* Fix fullnode & StateManager lint errors

* Refactor deployContract(...) to remove params

* Reduce gas limits to more reasonable values

* Update packages/ovm/test/contracts/execution-manager.l1-l2-opcodes.spec.ts

Co-authored-by: ben-chain <[email protected]>

* Update packages/rollup-contracts/contracts/FullStateManager.sol

Co-authored-by: ben-chain <[email protected]>

* Address PR feedback

* Fix lint errors

Co-authored-by: Karl Floersch <[email protected]>
Co-authored-by: ben-chain <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2020
1 parent 8af4001 commit 4075556
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 100 deletions.
22 changes: 14 additions & 8 deletions packages/ovm/test/contracts/execution-manager.executeCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

import {
ExecutionManagerContractDefinition as ExecutionManager,
FullStateManagerContractDefinition as StateManager,
TestDummyContractDefinition as DummyContract,
} from '@eth-optimism/rollup-contracts'

Expand Down Expand Up @@ -46,6 +47,7 @@ describe('Execution Manager -- Call opcodes', () => {
const [wallet] = getWallets(provider)
// Create pointers to our execution manager & simple copier contract
let executionManager: Contract
let stateManager: Contract
let dummyContract: ContractFactory
let dummyContractAddress: Address

Expand All @@ -59,6 +61,12 @@ describe('Execution Manager -- Call opcodes', () => {
[DEFAULT_OPCODE_WHITELIST_MASK, '0x' + '00'.repeat(20), GAS_LIMIT, true],
{ gasLimit: DEFAULT_ETHNODE_GAS_LIMIT }
)
// Set the state manager as well
stateManager = new Contract(
await executionManager.getStateManagerAddress(),
StateManager.abi,
wallet
)

// Deploy SimpleCopier with the ExecutionManager
dummyContractAddress = await manuallyDeployOvmContract(
Expand Down Expand Up @@ -89,7 +97,7 @@ describe('Execution Manager -- Call opcodes', () => {
'dummyFunction',
[intParam, bytesParam]
)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down Expand Up @@ -131,7 +139,7 @@ describe('Execution Manager -- Call opcodes', () => {
'dummyFunction',
[intParam, bytesParam]
)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down Expand Up @@ -167,7 +175,7 @@ describe('Execution Manager -- Call opcodes', () => {
'dummyFunction',
[intParam, bytesParam]
)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down Expand Up @@ -204,7 +212,7 @@ describe('Execution Manager -- Call opcodes', () => {
'dummyFunction',
[intParam, bytesParam]
)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand All @@ -229,9 +237,7 @@ describe('Execution Manager -- Call opcodes', () => {
s
)
await provider.waitForTransaction(tx.hash)
const nonceAfter = await executionManager.getOvmContractNonce(
wallet.address
)
const nonceAfter = await stateManager.getOvmContractNonce(wallet.address)
nonceAfter.should.equal(parseInt(nonce, 10) + 1)
})

Expand All @@ -244,7 +250,7 @@ describe('Execution Manager -- Call opcodes', () => {
'dummyFunction',
[intParam, bytesParam]
)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down
10 changes: 9 additions & 1 deletion packages/ovm/test/contracts/simple-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../setup'
import { getLogger, add0x, getCurrentTime } from '@eth-optimism/core-utils'
import {
ExecutionManagerContractDefinition as ExecutionManager,
FullStateManagerContractDefinition as StateManager,
TestSimpleStorageArgsFromCalldataDefinition as SimpleStorage,
} from '@eth-optimism/rollup-contracts'
import {
Expand Down Expand Up @@ -38,6 +39,7 @@ describe('SimpleStorage', () => {
const [wallet] = getWallets(provider)
// Create pointers to our execution manager & simple storage contract
let executionManager: Contract
let stateManager: Contract
let simpleStorage: ContractFactory
let simpleStorageOvmAddress: Address

Expand All @@ -51,6 +53,12 @@ describe('SimpleStorage', () => {
[DEFAULT_OPCODE_WHITELIST_MASK, '0x' + '00'.repeat(20), GAS_LIMIT, true],
{ gasLimit: DEFAULT_ETHNODE_GAS_LIMIT }
)
// Set the state manager as well
stateManager = new Contract(
await executionManager.getStateManagerAddress(),
StateManager.abi,
wallet
)

// Deploy SimpleStorage with the ExecutionManager
simpleStorageOvmAddress = await manuallyDeployOvmContract(
Expand Down Expand Up @@ -104,7 +112,7 @@ describe('SimpleStorage', () => {
.toString('hex')

const innerCallData: string = add0x(`${getStorageMethodId}${slot}`)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down
9 changes: 8 additions & 1 deletion packages/ovm/test/contracts/tx-origin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@eth-optimism/rollup-core'
import {
ExecutionManagerContractDefinition as ExecutionManager,
FullStateManagerContractDefinition as StateManager,
TestSimpleTxOriginContractDefinition as SimpleTxOrigin,
} from '@eth-optimism/rollup-contracts'

Expand All @@ -36,6 +37,7 @@ describe('SimpleTxOrigin', () => {
const provider = createMockProvider({ gasLimit: DEFAULT_ETHNODE_GAS_LIMIT })
const [wallet] = getWallets(provider)
let executionManager: Contract
let stateManager: Contract
let simpleTxOrigin: ContractFactory
let simpleTxOriginOvmAddress: Address

Expand All @@ -49,6 +51,11 @@ describe('SimpleTxOrigin', () => {
[DEFAULT_OPCODE_WHITELIST_MASK, '0x' + '00'.repeat(20), GAS_LIMIT, true],
{ gasLimit: DEFAULT_ETHNODE_GAS_LIMIT }
)
stateManager = new Contract(
await executionManager.getStateManagerAddress(),
StateManager.abi,
wallet
)

// Deploy SimpleTxOrigin with the ExecutionManager
simpleTxOriginOvmAddress = await manuallyDeployOvmContract(
Expand All @@ -72,7 +79,7 @@ describe('SimpleTxOrigin', () => {
.toString('hex')

const innerCallData: string = add0x(`${getStorageMethodId}`)
const nonce = await executionManager.getOvmContractNonce(wallet.address)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
const transaction = {
nonce,
gasLimit: GAS_LIMIT,
Expand Down
Loading

0 comments on commit 4075556

Please sign in to comment.