Skip to content

Commit

Permalink
Make CALLs Revert Properly (#28)
Browse files Browse the repository at this point in the history
* Making calls that revert revert
* Fixing circlular dependency

Released:
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
 - @eth-optimism/[email protected]
  • Loading branch information
willmeister authored Mar 5, 2020
1 parent 00581e3 commit 430ce36
Show file tree
Hide file tree
Showing 20 changed files with 1,563 additions and 153 deletions.
4 changes: 2 additions & 2 deletions packages/core-db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/core-db",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimism DB Utils",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-utils": "0.0.1-alpha.12",
"@eth-optimism/core-utils": "^0.0.1-alpha.13",
"abstract-leveldown": "^6.2.2",
"async-lock": "^1.2.2",
"chai": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/core-utils",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimism Core Utils",
"main": "build/index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eth-optimism/docs",
"private": true,
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimism docs",
"author": "Optimism",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions packages/optimistic-game-semantics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/optimistic-game-semantics",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimism Optimistic Game Semantics",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,8 +29,8 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-db": "0.0.1-alpha.12",
"@eth-optimism/core-utils": "0.0.1-alpha.12",
"@eth-optimism/core-db": "^0.0.1-alpha.13",
"@eth-optimism/core-utils": "^0.0.1-alpha.13",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"debug": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/ovm-truffle-provider-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/ovm-truffle-provider-wrapper",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimism Truffle Provider Wrapper",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/rollup-full-node": "0.0.1-alpha.12"
"@eth-optimism/rollup-full-node": "^0.0.1-alpha.13"
},
"devDependencies": {
"@types/node": "^12.0.7",
Expand Down
8 changes: 4 additions & 4 deletions packages/ovm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/ovm",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "An optimistic execution-compatible EVM",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -50,9 +50,9 @@
"typescript": "^3.3.3333"
},
"dependencies": {
"@eth-optimism/core-db": "0.0.1-alpha.12",
"@eth-optimism/core-utils": "0.0.1-alpha.12",
"@eth-optimism/rollup-core": "0.0.1-alpha.12",
"@eth-optimism/core-db": "^0.0.1-alpha.13",
"@eth-optimism/core-utils": "^0.0.1-alpha.13",
"@eth-optimism/rollup-core": "^0.0.1-alpha.13",
"@types/sinon-chai": "^3.2.2",
"chai": "^4.2.0",
"ethereum-waffle": "2.1.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/ovm/src/contracts/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ contract ExecutionManager is FullStateManager {
mstore8(add(_callBytes, 3), methodId)
}

bool isCall = executionContext.ovmTxOrigin == ZERO_ADDRESS;
bool success = false;
address addr = address(this);
assembly {
Expand All @@ -258,6 +259,9 @@ contract ExecutionManager is FullStateManager {
if eq(success, 1) {
return(result, size)
}
if eq(isCall, 1) {
revert(result, size)
}
}

if (!success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ contract DummyContract {
success = testInt != 0;
output = testBytes;
}

function dummyRevert() public {
revert("This is a test revert");
}

function dummyFailingRequire() public {
require(false, "This is a test revert");
}
}
85 changes: 83 additions & 2 deletions packages/ovm/test/contracts/execution-manager.executeCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
manuallyDeployOvmContract,
getUnsignedTransactionCalldata,
DEFAULT_ETHNODE_GAS_LIMIT,
ZERO_UINT,
} from '../helpers'
import { GAS_LIMIT, CHAIN_ID, OPCODE_WHITELIST_MASK } from '../../src/app'

Expand All @@ -28,8 +29,8 @@ const log = getLogger('execution-manager-calls', true)
* TESTS *
*********/

const methodId: string = ethereumjsAbi
.methodID('executeCall', [])
const unsignedCallMethodId: string = ethereumjsAbi
.methodID('executeUnsignedEOACall', [])
.toString('hex')

describe('Execution Manager -- Call opcodes', () => {
Expand Down Expand Up @@ -217,5 +218,85 @@ describe('Execution Manager -- Call opcodes', () => {
)
await provider.waitForTransaction(tx.hash)
})

it('reverts when it makes a call that reverts', async () => {
// Generate our tx internalCalldata
const internalCalldata = getUnsignedTransactionCalldata(
dummyContract,
'dummyRevert',
[]
)

const calldata = getUnsignedTransactionCalldata(
executionManager,
'executeUnsignedEOACall',
[
ZERO_UINT,
ZERO_UINT,
dummyContractAddress,
internalCalldata,
wallet.address,
]
)
const nonce = await wallet.getTransactionCount()

let failed = false
try {
await wallet.provider.call({
nonce,
gasLimit: GAS_LIMIT,
gasPrice: 0,
to: executionManager.address,
value: 0,
data: calldata,
chainId: CHAIN_ID,
})
} catch (e) {
log.debug(JSON.stringify(e) + ' ' + e.stack)
failed = true
}

failed.should.equal(true, `This call should have reverted!`)
})

it('reverts when it makes a call that fails a require', async () => {
// Generate our tx internalCalldata
const internalCalldata = getUnsignedTransactionCalldata(
dummyContract,
'dummyFailingRequire',
[]
)

const calldata = getUnsignedTransactionCalldata(
executionManager,
'executeUnsignedEOACall',
[
ZERO_UINT,
ZERO_UINT,
dummyContractAddress,
internalCalldata,
wallet.address,
]
)
const nonce = await wallet.getTransactionCount()

let failed = false
try {
await wallet.provider.call({
nonce,
gasLimit: GAS_LIMIT,
gasPrice: 0,
to: executionManager.address,
value: 0,
data: calldata,
chainId: CHAIN_ID,
})
} catch (e) {
log.debug(JSON.stringify(e) + ' ' + e.stack)
failed = true
}

failed.should.equal(true, `This call should have reverted!`)
})
})
})
4 changes: 3 additions & 1 deletion packages/ovm/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
bufToHexString,
bufferUtils,
} from '@eth-optimism/core-utils'
import * as ethereumjsAbi from 'ethereumjs-abi'
import { Contract, ContractFactory, Wallet, ethers } from 'ethers'
import {
Provider,
Expand All @@ -21,6 +20,7 @@ import {
Log,
} from 'ethers/providers'
import { Transaction } from 'ethers/utils'
import * as ethereumjsAbi from 'ethereumjs-abi'

/* Contract Imports */
import {
Expand All @@ -31,6 +31,8 @@ import {

type Signature = [string, string, string]

export const ZERO_UINT = '00'.repeat(32)

export const DEFAULT_ETHNODE_GAS_LIMIT = 9_000_000
export const gasLimit = 6_700_000
const log = getLogger('helpers', true)
Expand Down
8 changes: 4 additions & 4 deletions packages/rollup-contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-contracts",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "Optimistic Rollup smart contracts",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -43,9 +43,9 @@
"typescript": "^3.3.3333"
},
"dependencies": {
"@eth-optimism/core-db": "0.0.1-alpha.12",
"@eth-optimism/core-utils": "0.0.1-alpha.12",
"@eth-optimism/rollup-core": "0.0.1-alpha.12",
"@eth-optimism/core-db": "^0.0.1-alpha.13",
"@eth-optimism/core-utils": "^0.0.1-alpha.13",
"@eth-optimism/rollup-core": "^0.0.1-alpha.13",
"@types/sinon-chai": "^3.2.2",
"chai": "^4.2.0",
"ethereum-waffle": "2.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-core",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "[Optimism] Optimistic Rollup Core Library",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,8 +29,8 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-db": "0.0.1-alpha.12",
"@eth-optimism/core-utils": "0.0.1-alpha.12",
"@eth-optimism/core-db": "^0.0.1-alpha.13",
"@eth-optimism/core-utils": "^0.0.1-alpha.13",
"async-lock": "^1.2.2",
"ethers": "^4.0.39"
},
Expand Down
Loading

0 comments on commit 430ce36

Please sign in to comment.