Commit eefcea0c authored by Kelvin Fichter's avatar Kelvin Fichter Committed by Kelvin Fichter

maintenance: remove dead code in contracts

parent dfc784e8
......@@ -60,18 +60,13 @@
"@openzeppelin/contracts-upgradeable": "^3.3.0",
"@typechain/ethers-v5": "^7.0.1",
"@typechain/hardhat": "^2.3.0",
"@types/buffer-xor": "^2.0.0",
"@types/chai": "^4.2.18",
"@types/copyfiles": "^2.4.0",
"@types/glob": "^7.1.3",
"@types/lodash": "^4.14.168",
"@types/mkdirp": "^1.0.1",
"@types/mocha": "^8.2.2",
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"buffer-xor": "^2.0.2",
"chai": "^4.3.4",
"copyfiles": "^2.3.0",
"directory-tree": "^2.2.7",
......
......@@ -4,5 +4,3 @@ export { tests as Lib_Bytes32Utils_TEST_JSON } from './json/libraries/utils/Lib_
export { tests as Lib_BytesUtils_TEST_JSON } from './json/libraries/utils/Lib_BytesUtils.test.json'
export { tests as Lib_MerkleTrie_TEST_JSON } from './json/libraries/trie/Lib_MerkleTrie.test.json'
export { tests as Lib_OVMCodec_TEST_JSON } from './json/libraries/codec/Lib_OVMCodec.test.json'
export { tests as CREATE2_TEST_JSON } from './json/create2.test.json'
export { tests as SAFETY_CHECKER_TEST_JSON } from './json/safety-checker.test.json'
This diff is collapsed.
/* Imports: Internal */
import { getContractInterface } from '../../../src/contract-defs'
export const encodeXDomainCalldata = (
......
/* External Imports */
import { ethers } from 'hardhat'
import { constants, Wallet } from 'ethers'
/* Internal Imports */
import { remove0x, fromHexString } from '@eth-optimism/core-utils'
export interface EIP155Transaction {
nonce: number
gasLimit: number
gasPrice: number
to: string
data: string
chainId: number
}
export interface SignatureParameters {
messageHash: string
v: string
r: string
s: string
}
export const DEFAULT_EIP155_TX: EIP155Transaction = {
to: `0x${'12'.repeat(20)}`,
nonce: 100,
gasLimit: 1000000,
gasPrice: 100000000,
data: `0x${'99'.repeat(10)}`,
chainId: 420,
}
export const getRawSignedComponents = (signed: string): any[] => {
return [signed.slice(130, 132), signed.slice(2, 66), signed.slice(66, 130)]
}
export const getSignedComponents = (signed: string): any[] => {
return ethers.utils.RLP.decode(signed).slice(-3)
}
export * from './revert-flags'
export * from './encoding'
export * from './bridge'
/* External Imports */
import { ethers } from 'hardhat'
export const encodeRevertData = (
flag: number,
data: string = '0x',
nuisanceGasLeft: number = 0,
ovmGasRefund: number = 0
): string => {
const abiEncoded: string = ethers.utils.defaultAbiCoder.encode(
['uint256', 'uint256', 'uint256', 'bytes'],
[flag, nuisanceGasLeft, ovmGasRefund, data]
)
return abiEncoded
}
export const decodeRevertData = (revertData: string): any => {
const decoded = ethers.utils.defaultAbiCoder.decode(
['uint256', 'uint256', 'uint256', 'bytes'],
revertData
)
return (
'[revertFlag:' +
Object.keys(REVERT_FLAGS)[decoded[0]] +
', nuisanceGasLeft:' +
decoded[1] +
', ovmGasRefund: ' +
decoded[2] +
', data: ' +
decoded[3] +
']'
)
}
export const REVERT_FLAGS = {
OUT_OF_GAS: 0,
INTENTIONAL_REVERT: 1,
EXCEEDS_NUISANCE_GAS: 2,
INVALID_STATE_ACCESS: 3,
UNSAFE_BYTECODE: 4,
CREATE_COLLISION: 5,
STATIC_VIOLATION: 6,
CREATOR_NOT_ALLOWED: 7,
}
/* External Imports */
import { ethers } from 'ethers'
import { defaultAccounts } from 'ethereum-waffle'
import { fromHexString, toHexString } from '@eth-optimism/core-utils'
import xor from 'buffer-xor'
/* Internal Imports */
import { getContractDefinition } from '../../src/contract-defs'
export const DEFAULT_ACCOUNTS = defaultAccounts
export const DEFAULT_ACCOUNTS_HARDHAT = defaultAccounts.map((account) => {
......@@ -15,7 +9,6 @@ export const DEFAULT_ACCOUNTS_HARDHAT = defaultAccounts.map((account) => {
}
})
export const OVM_TX_GAS_LIMIT = 10_000_000
export const RUN_OVM_TEST_GAS = 20_000_000
export const FORCE_INCLUSION_PERIOD_SECONDS = 600
export const FORCE_INCLUSION_PERIOD_BLOCKS = 600 / 12
......@@ -23,40 +16,3 @@ export const FORCE_INCLUSION_PERIOD_BLOCKS = 600 / 12
export const NON_NULL_BYTES32 =
'0x1111111111111111111111111111111111111111111111111111111111111111'
export const NON_ZERO_ADDRESS = '0x1111111111111111111111111111111111111111'
export const VERIFIED_EMPTY_CONTRACT_HASH =
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
export const STORAGE_XOR_VALUE =
'0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF'
export const NUISANCE_GAS_COSTS = {
NUISANCE_GAS_SLOAD: 20000,
NUISANCE_GAS_SSTORE: 20000,
MIN_NUISANCE_GAS_PER_CONTRACT: 30000,
NUISANCE_GAS_PER_CONTRACT_BYTE: 100,
MIN_GAS_FOR_INVALID_STATE_ACCESS: 30000,
}
let len
// This is hacky, but `hardhat compile` evaluates this file for some reason.
// Feels better to have something hacky then a constant we have to keep re-hardcoding.
try {
len = fromHexString(
getContractDefinition('Helper_TestRunner').deployedBytecode
).byteLength
// eslint-disable-next-line no-empty
} catch {}
export const Helper_TestRunner_BYTELEN = len
export const STORAGE_XOR =
'0xfeedfacecafebeeffeedfacecafebeeffeedfacecafebeeffeedfacecafebeef'
export const getStorageXOR = (key: string): string => {
return toHexString(xor(fromHexString(key), fromHexString(STORAGE_XOR)))
}
export const EMPTY_ACCOUNT_CODE_HASH =
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
export const KECCAK_256_NULL =
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
/* External Imports */
import { BigNumber, constants } from 'ethers'
/* Internal Imports */
import { DUMMY_BYTES32 } from './bytes32'
import { NON_ZERO_ADDRESS } from '../constants'
import { OVMAccount } from '../types/ovm-types'
export const DUMMY_ACCOUNTS: Array<{
address: string
data: OVMAccount
}> = [
{
address: '0x1212121212121212121212121212121212121212',
data: {
nonce: BigNumber.from(123),
balance: BigNumber.from(456),
storageRoot: DUMMY_BYTES32[0],
codeHash: DUMMY_BYTES32[1],
ethAddress: constants.AddressZero,
},
},
{
address: '0x2121212121212121212121212121212121212121',
data: {
nonce: BigNumber.from(321),
balance: BigNumber.from(654),
storageRoot: DUMMY_BYTES32[2],
codeHash: DUMMY_BYTES32[3],
ethAddress: NON_ZERO_ADDRESS,
},
},
]
/* External Imports */
import { keccak256 } from 'ethers/lib/utils'
export const DUMMY_BYTECODE = '0x123412341234'
export const DUMMY_BYTECODE_BYTELEN = 6
export const UNSAFE_BYTECODE = '0x6069606955'
export const DUMMY_BYTECODE_HASH = keccak256(DUMMY_BYTECODE)
/* External Imports */
import { ethers } from 'ethers'
export const DUMMY_BYTES32: string[] = Array.from(
{
length: 10,
},
(_, i) => {
return ethers.utils.keccak256(`0x0${i}`)
}
)
/* Internal Imports */
import { NON_ZERO_ADDRESS } from '../constants'
export const DUMMY_CONTEXT = {
GLOBAL: {
ovmCHAINID: 11,
},
TRANSACTION: {
ovmORIGIN: NON_ZERO_ADDRESS,
ovmTIMESTAMP: 22,
ovmGASLIMIT: 33,
ovmTXGASLIMIT: 44,
ovmQUEUEORIGIN: 55,
},
MESSAGE: {
ovmCALLER: NON_ZERO_ADDRESS,
ovmADDRESS: NON_ZERO_ADDRESS,
ovmSTATICCTX: true,
},
}
export * from './accounts'
export * from './bytes32'
export * from './context'
export * from './bytecode'
export * from './batches'
export * from './transactions'
import { constants, ethers } from 'ethers'
export interface Transaction {
timestamp: number
blockNumber: number
l1QueueOrigin: number
l1TxOrigin: string
entrypoint: string
gasLimit: number
data: string
}
export const DUMMY_OVM_TRANSACTIONS: Array<Transaction> = [
...Array(10).keys(),
].map((i) => {
return {
timestamp: i,
blockNumber: 0,
l1QueueOrigin: 0,
l1TxOrigin: constants.AddressZero,
entrypoint: constants.AddressZero,
gasLimit: 0,
data: ethers.constants.HashZero,
}
})
export const hashTransaction = ({
timestamp,
blockNumber,
l1QueueOrigin,
l1TxOrigin,
entrypoint,
gasLimit,
data,
}: Transaction): string => {
return ethers.utils.solidityKeccak256(
['uint256', 'uint256', 'uint8', 'address', 'address', 'uint256', 'bytes'],
[
timestamp,
blockNumber,
l1QueueOrigin,
l1TxOrigin,
entrypoint,
gasLimit,
data,
]
)
}
import { ethers } from 'hardhat'
import { Contract, Signer, BigNumber } from 'ethers'
import { expect } from 'chai'
import { Contract, Signer } from 'ethers'
export class GasMeasurement {
GasMeasurementContract: Contract
......
export * from './dummy'
export * from './types'
export * from './constants'
export * from './resolver'
export * from './utils'
......
/* External Imports */
import { BigNumber, constants } from 'ethers'
import { parse, Transaction } from '@ethersproject/transactions'
export interface OVMAccount {
nonce: number | BigNumber
balance: number | BigNumber
storageRoot: string
codeHash: string
ethAddress: string
}
export const LibEIP155TxStruct = (tx: Transaction | string): Array<any> => {
if (typeof tx === 'string') {
tx = parse(tx)
}
const values = [
tx.nonce,
tx.gasPrice,
tx.gasLimit,
tx.to ? tx.to : constants.AddressZero,
tx.value,
tx.data,
tx.v % 256,
tx.r,
tx.s,
tx.chainId,
tx.v === 0 ? 0 : tx.v - 2 * tx.chainId - 35,
tx.to === null,
]
return values
}
/* External Imports */
import { Signer } from 'ethers'
import { toHexString } from '@eth-optimism/core-utils'
export const deployContractCode = async (
code: string,
signer: Signer,
gasLimit: number
): Promise<string> => {
// "Magic" prefix to be prepended to the contract code. Contains a series of opcodes that will
// copy the given code into memory and return it, thereby storing at the contract address.
const prefix = '0x600D380380600D6000396000f3'
const deployCode = prefix + toHexString(code).slice(2)
const response = await signer.sendTransaction({
to: null,
data: deployCode,
gasLimit,
})
const result = await response.wait()
return result.contractAddress
}
export * from './eth-time'
export * from './sol-utils'
export * from './custom-deployer'
import { ethers } from 'ethers'
const errorABI = new ethers.utils.Interface([
{
type: 'function',
inputs: [
{
type: 'string',
},
],
name: 'Error',
stateMutability: 'pure',
},
])
export const decodeSolidityError = (err: string): string => {
return errorABI.decodeFunctionData('Error', err)[0]
}
export const encodeSolidityError = (message: string): string => {
return errorABI.encodeFunctionData('Error', [message])
}
......@@ -2470,14 +2470,7 @@
resolved "https://registry.yarnpkg.com/@types/browser-or-node/-/browser-or-node-1.3.0.tgz#896ec59bcb8109fc858d8e68d3c056c176a19622"
integrity sha512-MVetr65IR7RdJbUxVHsaPFaXAO8fi89zv1g8L/mHygh1Q7xnnK02XZLwfMh57FOpTO6gtnagoPMQ/UOFfctXRQ==
"@types/buffer-xor@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/buffer-xor/-/buffer-xor-2.0.0.tgz#15738051e0720b68120cd2cc3f204aa4dc16bab1"
integrity sha512-NEJkIKUE/xboduuIAJmdtUvbXgUOfMkjOo6lWsiBVUIWBC5fVWGT+50yEw9W1Xp4ga76khg57pHELXw5Xm3Y+A==
dependencies:
"@types/node" "*"
"@types/chai-as-promised@^7.1.4":
"@types/chai-as-promised@^7.1.3", "@types/chai-as-promised@^7.1.4":
version "7.1.4"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.4.tgz#caf64e76fb056b8c8ced4b761ed499272b737601"
integrity sha512-1y3L1cHePcIm5vXkh1DSGf/zQq5n5xDKG1fpCvf18+uOkpce0Z1ozNFPkyWsVswK7ntN1sZBw3oU6gmN+pDUcA==
......@@ -2503,11 +2496,6 @@
dependencies:
"@types/node" "*"
"@types/copyfiles@^2.4.0":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/copyfiles/-/copyfiles-2.4.1.tgz#b0119c781457910115454bacb35f59e91145e7ec"
integrity sha512-v2JLxXeWUeWYWVo3/tlpxqiDCvgewSvf58HHjHYNaCi0lAthhRQ7jz8InxGzJsrMbWmWkYaxBO+BEtKjBU4ebw==
"@types/cors@^2.8.9":
version "2.8.12"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
......@@ -2539,7 +2527,7 @@
dependencies:
"@types/node" "*"
"@types/glob@*", "@types/glob@^7.1.1", "@types/glob@^7.1.3":
"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.4"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.4.tgz#ea59e21d2ee5c517914cb4bc8e4153b99e566672"
integrity sha512-w+LsMxKyYQm347Otw+IfBXOv9UWVjpHpCDdbBMt8Kz/xbvCYNjP+0qPh91Km3iKfSRLBB0P7fAMf0KHrPu+MyA==
......@@ -2813,18 +2801,6 @@
dependencies:
"@types/node" "*"
"@types/yargs-parser@*":
version "20.2.1"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz#3b9ce2489919d9e4fea439b76916abc34b2df129"
integrity sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==
"@types/yargs@^16.0.1":
version "16.0.4"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-16.0.4.tgz#26aad98dd2c2a38e421086ea9ad42b9e51642977"
integrity sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==
dependencies:
"@types/yargs-parser" "*"
"@typescript-eslint/eslint-plugin@^4.26.0":
version "4.29.3"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.3.tgz#95cb8029a8bd8bd9c7f4ab95074a7cb2115adefa"
......@@ -4332,7 +4308,7 @@ buffer-xor@^1.0.3:
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9"
integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=
buffer-xor@^2.0.1, buffer-xor@^2.0.2:
buffer-xor@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-2.0.2.tgz#34f7c64f04c777a1f8aac5e661273bb9dd320289"
integrity sha512-eHslX0bin3GB+Lx2p7lEYRShRewuNZL3fUl4qlVJGGiwoPGftmt8JQgk2Y9Ji5/01TnVDo33E5b5O3vUB1HdqQ==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment