Commit 26a47f72 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #2619 from ethereum-optimism/fix/hh

contracts-bedrock: migrate to `packages`
parents fc3a677a 63c8f5dc
......@@ -63,7 +63,7 @@ jobs:
yarn-monorepo:
docker:
- image: ethereumoptimism/js-builder:latest
- image: ethereumoptimism/js-builder:nightly
steps:
- restore_cache:
keys:
......@@ -87,6 +87,7 @@ jobs:
- node_modules
- packages/common-ts/node_modules
- packages/contracts/node_modules
- packages/contracts-bedrock/node_modules
- packages/contracts-periphery/node_modules
- packages/core-utils/node_modules
- packages/data-transport-layer/node_modules
......@@ -97,7 +98,8 @@ jobs:
- integration-tests/node_modules
- run:
name: Build monorepo
command: yarn build
command: |
yarn build
- save_cache:
key: v2-cache-yarn-build-{{ .Revision }}
paths:
......@@ -366,46 +368,36 @@ jobs:
bedrock-solidity:
docker:
- image: ethereumoptimism/js-builder:0.0.4
- image: ethereumoptimism/js-builder:nightly
steps:
- checkout
- run:
name: init submodules
command: |
git submodule sync --recursive
git submodule update --recursive --init
- run:
name: install
command: yarn install
working_directory: contracts-bedrock
working_directory: packages/contracts-bedrock
- run:
name: lint
command: |
# remove prettierrc in root of repo since it doesn't work with non-Lerna packages
mv ../.eslintrc.js ../.eslintrc.bak
yarn lint:check
mv ../.eslintrc.bak ../.eslintrc.js
working_directory: contracts-bedrock
command: yarn lint:check
working_directory: packages/contracts-bedrock
- run:
name: slither
command: yarn slither || exit 0
working_directory: contracts-bedrock
working_directory: packages/contracts-bedrock
- run:
name: build forge
command: yarn build:forge
working_directory: contracts-bedrock
name: build
command: yarn build
working_directory: packages/contracts-bedrock
- run:
name: test forge
command: yarn test:forge
working_directory: contracts-bedrock
name: test
command: yarn test
working_directory: packages/contracts-bedrock
- run:
name: gas snapshot
command: forge snapshot
working_directory: contracts-bedrock
command: forge snapshot && git diff --exit-code
working_directory: packages/contracts-bedrock
- run:
name: check go bindings
command: |
make && git diff --exit-code
command: make && git diff --exit-code
working_directory: op-bindings
bedrock-go-tests:
......@@ -476,24 +468,13 @@ jobs:
bedrock-integration-tests:
machine:
image: ubuntu-2004:202111-02
image: ethereumoptimism/js-builder:nightly
docker_layer_caching: true
steps:
- checkout
- run:
name: init submodules
command: |
git submodule sync --recursive
git submodule update --recursive --init
- node/install:
install-yarn: true
node-version: '16.13'
- run:
name: install Foundry
command: |
curl -L https://foundry.paradigm.xyz | bash
source /home/circleci/.bashrc
foundryup
- run:
name: build typescript
command: make build-ts
......
......@@ -6,11 +6,12 @@ module.exports = {
},
ignorePatterns: ['dist', 'coverage', 'packages/contracts/hardhat'],
extends: ['plugin:prettier/recommended'],
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
parserOptions: {
es6: true,
ecmaVersion: 6,
sourceType: 'module',
requireConfigFile: false,
},
plugins: [
'eslint-plugin-import',
......@@ -25,7 +26,7 @@ module.exports = {
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
project: './packages/**/tsconfig.json',
sourceType: 'module',
allowAutomaticSingleRunInference: true,
},
......
......@@ -58,6 +58,11 @@ jobs:
- name: Install Dependencies
run: yarn
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: yarn build
......
......@@ -55,6 +55,11 @@ jobs:
- name: Install Dependencies
run: yarn
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Publish To NPM or Create Release Pull Request
uses: changesets/action@v1
id: changesets
......
......@@ -27,6 +27,9 @@ packages/data-transport-layer/db
packages/integration-tests-bedrock/cache
packages/integration-tests-bedrock/artifacts
packages/contracts-bedrock/deployments/devnetL1
packages/contracts-bedrock/deployments/anvil
# vim
*.sw*
......
[submodule "tests"]
path = l2geth/tests/testdata
url = https://github.com/ethereum/tests
[submodule "packages/contracts-bedrock/lib/forge-std"]
path = contracts-bedrock/lib/forge-std
url = https://github.com/foundry-rs/forge-std.git
[submodule "packages/contracts-bedrock/lib/solmate"]
path = contracts-bedrock/lib/solmate
url = https://github.com/rari-capital/solmate.git
[submodule "packages/contracts-bedrock/lib/ds-test"]
path = contracts-bedrock/lib/ds-test
url = https://github.com/dapphub/ds-test.git
......@@ -17,7 +17,7 @@ module.exports = {
bracketSpacing: true,
// These options are specific to the Solidity Plugin
explicitTypes: 'always',
compiler: '0.8.9',
compiler: '>=0.8.10',
},
},
],
......
{
"$schema": "http://json.schemastore.org/prettierrc",
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"arrowParens": "always"
}
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
plugins: ['@typescript-eslint'],
extends: [
'standard',
'plugin:prettier/recommended',
'plugin:node/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
},
rules: {
'node/no-unpublished-import': 'off',
'node/no-unsupported-features/es-syntax': [
'error',
{ ignores: ['modules'] },
],
},
}
module.exports = {
$schema: 'http://json.schemastore.org/prettierrc',
trailingComma: 'es5',
tabWidth: 2,
semi: false,
singleQuote: true,
arrowParens: 'always',
overrides: [
{
files: '*.sol',
options: {
// These options are native to Prettier.
printWidth: 100,
tabWidth: 4,
useTabs: false,
singleQuote: false,
bracketSpacing: true,
// These options are specific to the Solidity Plugin
explicitTypes: 'always',
compiler: '0.8.10',
},
},
],
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_BedrockPredeployAddresses
* TODO: just merge this value into the monorepo
*/
library Lib_BedrockPredeployAddresses {
address internal constant L1_BLOCK_ATTRIBUTES = 0x4200000000000000000000000000000000000015;
}
Subproject commit c7a36fb236f298e04edf28e2fee385b80f53945f
Subproject commit 1680d7fb3e00b7b197a7336e7c88e838c7e6a3ec
Subproject commit 851ea3baa4327f453da723df75b1093b58b964dc
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"declaration": true,
"resolveJsonModule": true
},
"include": ["./scripts", "./test", "./typechain"],
"files": ["./hardhat.config.ts"]
}
......@@ -28,6 +28,7 @@
"url": "https://github.com/ethereum-optimism/optimism.git"
},
"devDependencies": {
"@babel/eslint-parser": "^7.5.4",
"@eth-optimism/contracts": "0.5.25",
"@eth-optimism/core-utils": "0.8.5",
"@eth-optimism/sdk": "1.1.6",
......@@ -47,7 +48,6 @@
"@uniswap/v3-periphery": "^1.0.1",
"@uniswap/v3-sdk": "^3.6.2",
"async-mutex": "^0.3.2",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"commander": "^8.3.0",
......@@ -55,12 +55,12 @@
"envalid": "^7.1.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"eslint-plugin-unicorn": "^42.0.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.6.8",
"hardhat": "^2.9.6",
......
#/bin/bash
set -eu
CONTRACTS_PATH="../contracts-bedrock/"
CONTRACTS_PATH="../packages/contracts-bedrock/"
if [ "$#" -ne 2 ]; then
......
......@@ -32,6 +32,8 @@ set -eu
L1_URL="http://localhost:8545"
L2_URL="http://localhost:9545"
CONTRACTS_BEDROCK=./packages/contracts-bedrock
# Helper method that waits for a given URL to be up. Can't use
# cURL's built-in retry logic because connection reset errors
# are ignored unless you're using a very recent version of cURL
......@@ -64,25 +66,27 @@ else
fi
# Bring up L1.
cd ops-bedrock
echo "Bringing up L1..."
DOCKER_BUILDKIT=1 docker-compose build
docker-compose up -d l1
wait_up $L1_URL
cd ../
(
cd ops-bedrock
echo "Bringing up L1..."
DOCKER_BUILDKIT=1 docker-compose build
docker-compose up -d l1
wait_up $L1_URL
)
# Deploy contracts using Hardhat.
if [ ! -f ./contracts-bedrock/deployments/devnetL1/OptimismPortal.json ]; then
if [ ! -f $CONTRACTS_BEDROCK/deployments/devnetL1/OptimismPortal.json ]; then
echo "Deploying contracts."
cd ./contracts-bedrock
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP yarn hardhat --network devnetL1 deploy
cd ../
(
cd $CONTRACTS_BEDROCK
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP yarn hardhat --network devnetL1 deploy
)
else
echo "Contracts already deployed, skipping."
fi
function get_deployed_bytecode() {
echo $(jq -r .deployedBytecode ./contracts-bedrock/artifacts/contracts/$1)
echo $(jq -r .deployedBytecode $CONTRACTS_BEDROCK/artifacts/contracts/$1)
}
# Pull out the necessary bytecode/addresses from the artifacts/deployments.
......@@ -92,8 +96,8 @@ OPTIMISM_MINTABLE_TOKEN_FACTORY_BYTECODE=$(get_deployed_bytecode universal/Optim
L2_STANDARD_BRIDGE_BYTECODE=$(get_deployed_bytecode L2/L2StandardBridge.sol/L2StandardBridge.json)
L1_BLOCK_INFO_BYTECODE=$(get_deployed_bytecode L2/L1Block.sol/L1Block.json)
DEPOSIT_CONTRACT_ADDRESS=$(jq -r .address < ./contracts-bedrock/deployments/devnetL1/OptimismPortal.json)
L2OO_ADDRESS=$(jq -r .address < ./contracts-bedrock/deployments/devnetL1/L2OutputOracle.json)
DEPOSIT_CONTRACT_ADDRESS=$(jq -r .address < $CONTRACTS_BEDROCK/deployments/devnetL1/OptimismPortal.json)
L2OO_ADDRESS=$(jq -r .address < $CONTRACTS_BEDROCK/deployments/devnetL1/L2OutputOracle.json)
# Replace values in the L2 genesis file. It doesn't matter if this gets run every time,
# since the replaced values will be the same.
......@@ -110,11 +114,12 @@ jq ". | .alloc.\"4200000000000000000000000000000000000015\".code = \"$L1_BLOCK_I
jq ". | .timestamp = \"$GENESIS_TIMESTAMP\" " > ./.devnet/genesis-l2.json
# Bring up L2.
cd ops-bedrock
echo "Bringing up L2..."
docker-compose up -d l2
wait_up $L2_URL
cd ../
(
cd ops-bedrock
echo "Bringing up L2..."
docker-compose up -d l2
wait_up $L2_URL
)
# Start putting together the rollup config.
echo "Building rollup config..."
......@@ -154,16 +159,16 @@ SEQUENCER_GENESIS_HASH="$(echo $L2_GENESIS | jq -r '.result.hash')"
SEQUENCER_BATCH_INBOX_ADDRESS="$(cat ./ops-bedrock/rollup.json | jq -r '.batch_inbox_address')"
# Bring up everything else.
cd ops-bedrock
echo "Bringing up devnet..."
L2OO_ADDRESS="$L2OO_ADDRESS" \
SEQUENCER_GENESIS_HASH="$SEQUENCER_GENESIS_HASH" \
SEQUENCER_BATCH_INBOX_ADDRESS="$SEQUENCER_BATCH_INBOX_ADDRESS" \
docker-compose up -d op-proposer op-batcher
echo "Bringin up stateviz webserver..."
docker-compose up -d stateviz
cd ../
(
cd ops-bedrock
echo "Bringing up devnet..."
L2OO_ADDRESS="$L2OO_ADDRESS" \
SEQUENCER_GENESIS_HASH="$SEQUENCER_GENESIS_HASH" \
SEQUENCER_BATCH_INBOX_ADDRESS="$SEQUENCER_BATCH_INBOX_ADDRESS" \
docker-compose up -d op-proposer op-batcher
echo "Bringin up stateviz webserver..."
docker-compose up -d stateviz
)
echo "Devnet ready."
......@@ -2,10 +2,15 @@
# be used to build any of the follow-on services
#
# ### BASE: Install deps
FROM ghcr.io/foundry-rs/foundry:latest as foundry
FROM node:16-alpine3.14 as base
RUN apk --no-cache add curl jq python3 ca-certificates git make gcc musl-dev linux-headers bash build-base
COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
COPY --from=foundry /usr/local/bin/cast /usr/local/bin/cast
# copy over the needed configs to run the dep installation
# note: this approach can be a bit unhandy to maintain, but it allows
# us to cache the installation steps
......@@ -15,6 +20,7 @@ COPY packages/sdk/package.json ./packages/sdk/package.json
COPY packages/core-utils/package.json ./packages/core-utils/package.json
COPY packages/common-ts/package.json ./packages/common-ts/package.json
COPY packages/contracts/package.json ./packages/contracts/package.json
COPY packages/contracts-bedrock/package.json ./packages/contracts-bedrock/package.json
COPY packages/contracts-periphery/package.json ./packages/contracts-periphery/package.json
COPY packages/data-transport-layer/package.json ./packages/data-transport-layer/package.json
COPY packages/message-relayer/package.json ./packages/message-relayer/package.json
......
......@@ -21,8 +21,11 @@
"teleportr"
],
"nohoist": [
"**/typechain",
"**/@typechain/*"
"**/typechain/*",
"**/@typechain/*",
"@eth-optimism/contracts-bedrock/ds-test",
"@eth-optimism/contracts-bedrock/forge-std",
"@eth-optimism/contracts-bedrock/@rari-capital/solmate"
]
},
"private": true,
......@@ -41,25 +44,39 @@
"release": "yarn build && yarn changeset publish"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@babel/eslint-parser": "^7.18.2",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^8.2.2",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"copyfiles": "^2.3.0",
"depcheck": "^1.4.3",
"doctoc": "2.1.0",
"eslint": "^7.27.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"eslint-plugin-unicorn": "^42.0.0",
"husky": "^6.0.0",
"lerna": "^4.0.0",
"lint-staged": "11.0.0",
"markdownlint": "^0.24.0",
"markdownlint-cli2": "^0.3.2",
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"patch-package": "^6.4.7",
"prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.13",
"ts-mocha": "^8.0.0",
"typescript": "^4.6.2"
},
"dependencies": {
......
......@@ -9,8 +9,8 @@
],
"scripts": {
"all": "yarn clean && yarn build && yarn test && yarn lint:fix && yarn lint",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint:check": "eslint . --max-warnings=0",
"lint:fix": "yarn lint:check --fix",
"lint": "yarn lint:fix && yarn lint:check",
......@@ -48,28 +48,10 @@
"devDependencies": {
"@ethersproject/abstract-provider": "^5.6.1",
"@ethersproject/abstract-signer": "^5.6.2",
"@types/chai": "^4.2.18",
"@types/express": "^4.17.12",
"@types/mocha": "^8.2.2",
"@types/pino": "^6.3.6",
"@types/pino-multi-stream": "^5.1.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"lint-staged": "11.0.0",
"mocha": "^8.4.0",
"prettier": "^2.3.1",
"supertest": "^6.1.4",
"ts-mocha": "^8.0.0",
"typescript": "^4.6.2"
"supertest": "^6.1.4"
}
}
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
module.exports = {
extends: '../../.eslintrc.js',
}
......@@ -88,14 +88,14 @@ OVM_ETH_Test:test_metadata() (gas: 15608)
OVM_ETH_Test:test_mint() (gas: 10621)
OVM_ETH_Test:test_transfer() (gas: 10726)
OVM_ETH_Test:test_transferFrom() (gas: 13008)
OptimismMintableTokenFactory_Test:test_bridge() (gas: 9850)
OptimismMintableTokenFactory_Test:test_burn() (gas: 52791)
OptimismMintableTokenFactory_Test:test_burnRevertsFromNotBridge() (gas: 13211)
OptimismMintableTokenFactory_Test:test_l1Token() (gas: 9779)
OptimismMintableTokenFactory_Test:test_l2Bridge() (gas: 9768)
OptimismMintableTokenFactory_Test:test_mint() (gas: 65732)
OptimismMintableTokenFactory_Test:test_mintRevertsFromNotBridge() (gas: 13213)
OptimismMintableTokenFactory_Test:test_remoteToken() (gas: 9762)
OptimismMintableERC20_Test:test_bridge() (gas: 9850)
OptimismMintableERC20_Test:test_burn() (gas: 52791)
OptimismMintableERC20_Test:test_burnRevertsFromNotBridge() (gas: 13211)
OptimismMintableERC20_Test:test_l1Token() (gas: 9779)
OptimismMintableERC20_Test:test_l2Bridge() (gas: 9768)
OptimismMintableERC20_Test:test_mint() (gas: 65732)
OptimismMintableERC20_Test:test_mintRevertsFromNotBridge() (gas: 13213)
OptimismMintableERC20_Test:test_remoteToken() (gas: 9762)
OptimismMintableTokenFactory_Test:test_bridge() (gas: 9707)
OptimismMintableTokenFactory_Test:test_createStandardL2Token() (gas: 1106538)
OptimismMintableTokenFactory_Test:test_createStandardL2TokenSameTwice() (gas: 2193987)
......
module.exports = {
...require('../../.prettierrc.js'),
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { OptimismPortal } from "./OptimismPortal.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { StandardBridge } from "../universal/StandardBridge.sol";
/**
......
......@@ -3,7 +3,7 @@ pragma solidity 0.8.10;
import { L2OutputOracle } from "./L2OutputOracle.sol";
import { WithdrawalVerifier } from "../libraries/Lib_WithdrawalVerifier.sol";
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { ExcessivelySafeCall } from "../libraries/ExcessivelySafeCall.sol";
/**
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.10;
/* External Imports */
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Lib_BedrockPredeployAddresses } from "../libraries/Lib_BedrockPredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { L1Block } from "../L2/L1Block.sol";
/**
......@@ -68,7 +68,7 @@ contract GasPriceOracle is Ownable {
}
function l1BaseFee() public view returns (uint256) {
return L1Block(Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES).basefee();
return L1Block(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES).basefee();
}
/**
......
......@@ -2,7 +2,7 @@
pragma solidity 0.8.10;
import { L1Block } from "./L1Block.sol";
import { Lib_BedrockPredeployAddresses } from "../libraries/Lib_BedrockPredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
/**
* @title L1BlockNumber
......@@ -30,6 +30,6 @@ contract L1BlockNumber {
}
function getL1BlockNumber() public view returns (uint256) {
return L1Block(Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES).number();
return L1Block(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES).number();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
import { L2ToL1MessagePasser } from "./L2ToL1MessagePasser.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { StandardBridge } from "../universal/StandardBridge.sol";
import { OptimismMintableERC20 } from "../universal/OptimismMintableERC20.sol";
......
......@@ -2,9 +2,7 @@
pragma solidity ^0.8.9;
/* Library Imports */
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
/* Contract Imports */
import { OptimismMintableERC20 } from "../universal/OptimismMintableERC20.sol";
......
......@@ -2,9 +2,7 @@
pragma solidity ^0.8.9;
/* Library Imports */
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
/* Contract Imports */
import { L2StandardBridge } from "./L2StandardBridge.sol";
......
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright 2019-2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pragma solidity ^0.8.7;
library AddressAliasHelper {
uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);
/// @notice Utility function that converts the address in the L1 that submitted a tx to
/// the inbox to the msg.sender viewed in the L2
/// @param l1Address the address in the L1 that triggered the tx to L2
/// @return l2Address L2 address as viewed in msg.sender
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
unchecked {
l2Address = address(uint160(l1Address) + offset);
}
}
/// @notice Utility function that converts the msg.sender viewed in the L2 to the
/// address in the L1 that submitted a tx to the inbox
/// @param l2Address L2 address as viewed in msg.sender
/// @return l1Address the address in the L1 that triggered the tx to L2
function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
unchecked {
l1Address = address(uint160(l2Address) - offset);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_BytesUtils
*/
library Lib_BytesUtils {
/**********************
* Internal Functions *
**********************/
function slice(
bytes memory _bytes,
uint256 _start,
uint256 _length
) internal pure returns (bytes memory) {
require(_length + 31 >= _length, "slice_overflow");
require(_start + _length >= _start, "slice_overflow");
require(_bytes.length >= _start + _length, "slice_outOfBounds");
bytes memory tempBytes;
assembly {
switch iszero(_length)
case 0 {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)
// The first word of the slice result is potentially a partial
// word read from the original array. To read it, we calculate
// the length of that partial word and start copying that many
// bytes into the array. The first word we copy will start with
// data we don't care about, but the last `lengthmod` bytes will
// land at the beginning of the contents of the new array. When
// we're done copying, we overwrite the full first word with
// the actual length of the slice.
let lengthmod := and(_length, 31)
// The multiplication in the next line is necessary
// because when slicing multiples of 32 bytes (lengthmod == 0)
// the following copy loop was copying the origin's length
// and then ending prematurely not copying everything it should.
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
let end := add(mc, _length)
for {
// The multiplication in the next line has the same exact purpose
// as the one above.
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
mstore(mc, mload(cc))
}
mstore(tempBytes, _length)
//update free-memory pointer
//allocating the array padded to 32 bytes like the compiler does now
mstore(0x40, and(add(mc, 31), not(31)))
}
//if we want a zero-length slice let's just return a zero-length array
default {
tempBytes := mload(0x40)
//zero out the 32 bytes slice we are about to return
//we need to do it because Solidity does not garbage collect
mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
}
}
return tempBytes;
}
function slice(bytes memory _bytes, uint256 _start) internal pure returns (bytes memory) {
if (_start >= _bytes.length) {
return bytes("");
}
return slice(_bytes, _start, _bytes.length - _start);
}
function toBytes32(bytes memory _bytes) internal pure returns (bytes32) {
if (_bytes.length < 32) {
bytes32 ret;
assembly {
ret := mload(add(_bytes, 32))
}
return ret;
}
return abi.decode(_bytes, (bytes32)); // will truncate if input length > 32 bytes
}
function toUint256(bytes memory _bytes) internal pure returns (uint256) {
return uint256(toBytes32(_bytes));
}
function toNibbles(bytes memory _bytes) internal pure returns (bytes memory) {
bytes memory nibbles = new bytes(_bytes.length * 2);
for (uint256 i = 0; i < _bytes.length; i++) {
nibbles[i * 2] = _bytes[i] >> 4;
nibbles[i * 2 + 1] = bytes1(uint8(_bytes[i]) % 16);
}
return nibbles;
}
function fromNibbles(bytes memory _bytes) internal pure returns (bytes memory) {
bytes memory ret = new bytes(_bytes.length / 2);
for (uint256 i = 0; i < ret.length; i++) {
ret[i] = (_bytes[i * 2] << 4) | (_bytes[i * 2 + 1]);
}
return ret;
}
function equal(bytes memory _bytes, bytes memory _other) internal pure returns (bool) {
return keccak256(_bytes) == keccak256(_other);
}
}
//SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import {
Lib_CrossDomainUtils
} from "@eth-optimism/contracts/libraries/bridge/Lib_CrossDomainUtils.sol";
import { Lib_RLPWriter } from "@eth-optimism/contracts/libraries/rlp/Lib_RLPWriter.sol";
import { Lib_CrossDomainUtils } from "./Lib_CrossDomainUtils.sol";
import { Lib_RLPWriter } from "./rlp/Lib_RLPWriter.sol";
/**
* @title CrossDomainHashing
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_CrossDomainUtils
*/
library Lib_CrossDomainUtils {
/**
* Generates the correct cross domain calldata for a message.
* @param _target Target contract address.
* @param _sender Message sender address.
* @param _message Message to send to the target.
* @param _messageNonce Nonce for the provided message.
* @return ABI encoded cross domain calldata.
*/
function encodeXDomainCalldata(
address _target,
address _sender,
bytes memory _message,
uint256 _messageNonce
) internal pure returns (bytes memory) {
return
abi.encodeWithSignature(
"relayMessage(address,address,bytes,uint256)",
_target,
_sender,
_message,
_messageNonce
);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_DefaultValues
*/
library Lib_DefaultValues {
// The default x-domain message sender being set to a non-zero value makes
// deployment a bit more expensive, but in exchange the refund on every call to
// `relayMessage` by the L1 and L2 messengers will be higher.
address internal constant DEFAULT_XDOMAIN_SENDER = 0x000000000000000000000000000000000000dEaD;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_PredeployAddresses
*/
library Lib_PredeployAddresses {
address internal constant L2_TO_L1_MESSAGE_PASSER = 0x4200000000000000000000000000000000000000;
address internal constant L1_MESSAGE_SENDER = 0x4200000000000000000000000000000000000001;
address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002;
address payable internal constant OVM_ETH = payable(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000);
address internal constant L2_CROSS_DOMAIN_MESSENGER =
0x4200000000000000000000000000000000000007;
address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008;
address internal constant PROXY_EOA = 0x4200000000000000000000000000000000000009;
address internal constant L2_STANDARD_BRIDGE = 0x4200000000000000000000000000000000000010;
address internal constant SEQUENCER_FEE_WALLET = 0x4200000000000000000000000000000000000011;
address internal constant L2_STANDARD_TOKEN_FACTORY =
0x4200000000000000000000000000000000000012;
address internal constant L1_BLOCK_NUMBER = 0x4200000000000000000000000000000000000013;
address internal constant L1_BLOCK_ATTRIBUTES = 0x4200000000000000000000000000000000000015;
}
......@@ -2,12 +2,8 @@
pragma solidity 0.8.10;
/* Library Imports */
import {
Lib_SecureMerkleTrie
} from "@eth-optimism/contracts/libraries/trie/Lib_SecureMerkleTrie.sol";
import {
Lib_CrossDomainUtils
} from "@eth-optimism/contracts/libraries/bridge/Lib_CrossDomainUtils.sol";
import { Lib_SecureMerkleTrie } from "./trie/Lib_SecureMerkleTrie.sol";
import { Lib_CrossDomainUtils } from "./Lib_CrossDomainUtils.sol";
/**
* @title WithdrawalVerifier
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_RLPReader
* @dev Adapted from "RLPReader" by Hamdi Allam (hamdi.allam97@gmail.com).
*/
library Lib_RLPReader {
/*************
* Constants *
*************/
uint256 internal constant MAX_LIST_LENGTH = 32;
/*********
* Enums *
*********/
enum RLPItemType {
DATA_ITEM,
LIST_ITEM
}
/***********
* Structs *
***********/
struct RLPItem {
uint256 length;
uint256 ptr;
}
/**********************
* Internal Functions *
**********************/
/**
* Converts bytes to a reference to memory position and length.
* @param _in Input bytes to convert.
* @return Output memory reference.
*/
function toRLPItem(bytes memory _in) internal pure returns (RLPItem memory) {
uint256 ptr;
assembly {
ptr := add(_in, 32)
}
return RLPItem({ length: _in.length, ptr: ptr });
}
/**
* Reads an RLP list value into a list of RLP items.
* @param _in RLP list value.
* @return Decoded RLP list items.
*/
function readList(RLPItem memory _in) internal pure returns (RLPItem[] memory) {
(uint256 listOffset, , RLPItemType itemType) = _decodeLength(_in);
require(itemType == RLPItemType.LIST_ITEM, "Invalid RLP list value.");
// Solidity in-memory arrays can't be increased in size, but *can* be decreased in size by
// writing to the length. Since we can't know the number of RLP items without looping over
// the entire input, we'd have to loop twice to accurately size this array. It's easier to
// simply set a reasonable maximum list length and decrease the size before we finish.
RLPItem[] memory out = new RLPItem[](MAX_LIST_LENGTH);
uint256 itemCount = 0;
uint256 offset = listOffset;
while (offset < _in.length) {
require(itemCount < MAX_LIST_LENGTH, "Provided RLP list exceeds max list length.");
(uint256 itemOffset, uint256 itemLength, ) = _decodeLength(
RLPItem({ length: _in.length - offset, ptr: _in.ptr + offset })
);
out[itemCount] = RLPItem({ length: itemLength + itemOffset, ptr: _in.ptr + offset });
itemCount += 1;
offset += itemOffset + itemLength;
}
// Decrease the array size to match the actual item count.
assembly {
mstore(out, itemCount)
}
return out;
}
/**
* Reads an RLP list value into a list of RLP items.
* @param _in RLP list value.
* @return Decoded RLP list items.
*/
function readList(bytes memory _in) internal pure returns (RLPItem[] memory) {
return readList(toRLPItem(_in));
}
/**
* Reads an RLP bytes value into bytes.
* @param _in RLP bytes value.
* @return Decoded bytes.
*/
function readBytes(RLPItem memory _in) internal pure returns (bytes memory) {
(uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in);
require(itemType == RLPItemType.DATA_ITEM, "Invalid RLP bytes value.");
return _copy(_in.ptr, itemOffset, itemLength);
}
/**
* Reads an RLP bytes value into bytes.
* @param _in RLP bytes value.
* @return Decoded bytes.
*/
function readBytes(bytes memory _in) internal pure returns (bytes memory) {
return readBytes(toRLPItem(_in));
}
/**
* Reads an RLP string value into a string.
* @param _in RLP string value.
* @return Decoded string.
*/
function readString(RLPItem memory _in) internal pure returns (string memory) {
return string(readBytes(_in));
}
/**
* Reads an RLP string value into a string.
* @param _in RLP string value.
* @return Decoded string.
*/
function readString(bytes memory _in) internal pure returns (string memory) {
return readString(toRLPItem(_in));
}
/**
* Reads an RLP bytes32 value into a bytes32.
* @param _in RLP bytes32 value.
* @return Decoded bytes32.
*/
function readBytes32(RLPItem memory _in) internal pure returns (bytes32) {
require(_in.length <= 33, "Invalid RLP bytes32 value.");
(uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in);
require(itemType == RLPItemType.DATA_ITEM, "Invalid RLP bytes32 value.");
uint256 ptr = _in.ptr + itemOffset;
bytes32 out;
assembly {
out := mload(ptr)
// Shift the bytes over to match the item size.
if lt(itemLength, 32) {
out := div(out, exp(256, sub(32, itemLength)))
}
}
return out;
}
/**
* Reads an RLP bytes32 value into a bytes32.
* @param _in RLP bytes32 value.
* @return Decoded bytes32.
*/
function readBytes32(bytes memory _in) internal pure returns (bytes32) {
return readBytes32(toRLPItem(_in));
}
/**
* Reads an RLP uint256 value into a uint256.
* @param _in RLP uint256 value.
* @return Decoded uint256.
*/
function readUint256(RLPItem memory _in) internal pure returns (uint256) {
return uint256(readBytes32(_in));
}
/**
* Reads an RLP uint256 value into a uint256.
* @param _in RLP uint256 value.
* @return Decoded uint256.
*/
function readUint256(bytes memory _in) internal pure returns (uint256) {
return readUint256(toRLPItem(_in));
}
/**
* Reads an RLP bool value into a bool.
* @param _in RLP bool value.
* @return Decoded bool.
*/
function readBool(RLPItem memory _in) internal pure returns (bool) {
require(_in.length == 1, "Invalid RLP boolean value.");
uint256 ptr = _in.ptr;
uint256 out;
assembly {
out := byte(0, mload(ptr))
}
require(out == 0 || out == 1, "Lib_RLPReader: Invalid RLP boolean value, must be 0 or 1");
return out != 0;
}
/**
* Reads an RLP bool value into a bool.
* @param _in RLP bool value.
* @return Decoded bool.
*/
function readBool(bytes memory _in) internal pure returns (bool) {
return readBool(toRLPItem(_in));
}
/**
* Reads an RLP address value into a address.
* @param _in RLP address value.
* @return Decoded address.
*/
function readAddress(RLPItem memory _in) internal pure returns (address) {
if (_in.length == 1) {
return address(0);
}
require(_in.length == 21, "Invalid RLP address value.");
return address(uint160(readUint256(_in)));
}
/**
* Reads an RLP address value into a address.
* @param _in RLP address value.
* @return Decoded address.
*/
function readAddress(bytes memory _in) internal pure returns (address) {
return readAddress(toRLPItem(_in));
}
/**
* Reads the raw bytes of an RLP item.
* @param _in RLP item to read.
* @return Raw RLP bytes.
*/
function readRawBytes(RLPItem memory _in) internal pure returns (bytes memory) {
return _copy(_in);
}
/*********************
* Private Functions *
*********************/
/**
* Decodes the length of an RLP item.
* @param _in RLP item to decode.
* @return Offset of the encoded data.
* @return Length of the encoded data.
* @return RLP item type (LIST_ITEM or DATA_ITEM).
*/
function _decodeLength(RLPItem memory _in)
private
pure
returns (
uint256,
uint256,
RLPItemType
)
{
require(_in.length > 0, "RLP item cannot be null.");
uint256 ptr = _in.ptr;
uint256 prefix;
assembly {
prefix := byte(0, mload(ptr))
}
if (prefix <= 0x7f) {
// Single byte.
return (0, 1, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xb7) {
// Short string.
// slither-disable-next-line variable-scope
uint256 strLen = prefix - 0x80;
require(_in.length > strLen, "Invalid RLP short string.");
return (1, strLen, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xbf) {
// Long string.
uint256 lenOfStrLen = prefix - 0xb7;
require(_in.length > lenOfStrLen, "Invalid RLP long string length.");
uint256 strLen;
assembly {
// Pick out the string length.
strLen := div(mload(add(ptr, 1)), exp(256, sub(32, lenOfStrLen)))
}
require(_in.length > lenOfStrLen + strLen, "Invalid RLP long string.");
return (1 + lenOfStrLen, strLen, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xf7) {
// Short list.
// slither-disable-next-line variable-scope
uint256 listLen = prefix - 0xc0;
require(_in.length > listLen, "Invalid RLP short list.");
return (1, listLen, RLPItemType.LIST_ITEM);
} else {
// Long list.
uint256 lenOfListLen = prefix - 0xf7;
require(_in.length > lenOfListLen, "Invalid RLP long list length.");
uint256 listLen;
assembly {
// Pick out the list length.
listLen := div(mload(add(ptr, 1)), exp(256, sub(32, lenOfListLen)))
}
require(_in.length > lenOfListLen + listLen, "Invalid RLP long list.");
return (1 + lenOfListLen, listLen, RLPItemType.LIST_ITEM);
}
}
/**
* Copies the bytes from a memory location.
* @param _src Pointer to the location to read from.
* @param _offset Offset to start reading from.
* @param _length Number of bytes to read.
* @return Copied bytes.
*/
function _copy(
uint256 _src,
uint256 _offset,
uint256 _length
) private pure returns (bytes memory) {
bytes memory out = new bytes(_length);
if (out.length == 0) {
return out;
}
uint256 src = _src + _offset;
uint256 dest;
assembly {
dest := add(out, 32)
}
// Copy over as many complete words as we can.
for (uint256 i = 0; i < _length / 32; i++) {
assembly {
mstore(dest, mload(src))
}
src += 32;
dest += 32;
}
// Pick out the remaining bytes.
uint256 mask;
unchecked {
mask = 256**(32 - (_length % 32)) - 1;
}
assembly {
mstore(dest, or(and(mload(src), not(mask)), and(mload(dest), mask)))
}
return out;
}
/**
* Copies an RLP item into bytes.
* @param _in RLP item to copy.
* @return Copied bytes.
*/
function _copy(RLPItem memory _in) private pure returns (bytes memory) {
return _copy(_in.ptr, 0, _in.length);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/**
* @title Lib_RLPWriter
* @author Bakaoh (with modifications)
*/
library Lib_RLPWriter {
/**********************
* Internal Functions *
**********************/
/**
* RLP encodes a byte string.
* @param _in The byte string to encode.
* @return The RLP encoded string in bytes.
*/
function writeBytes(bytes memory _in) internal pure returns (bytes memory) {
bytes memory encoded;
if (_in.length == 1 && uint8(_in[0]) < 128) {
encoded = _in;
} else {
encoded = abi.encodePacked(_writeLength(_in.length, 128), _in);
}
return encoded;
}
/**
* RLP encodes a list of RLP encoded byte byte strings.
* @param _in The list of RLP encoded byte strings.
* @return The RLP encoded list of items in bytes.
*/
function writeList(bytes[] memory _in) internal pure returns (bytes memory) {
bytes memory list = _flatten(_in);
return abi.encodePacked(_writeLength(list.length, 192), list);
}
/**
* RLP encodes a string.
* @param _in The string to encode.
* @return The RLP encoded string in bytes.
*/
function writeString(string memory _in) internal pure returns (bytes memory) {
return writeBytes(bytes(_in));
}
/**
* RLP encodes an address.
* @param _in The address to encode.
* @return The RLP encoded address in bytes.
*/
function writeAddress(address _in) internal pure returns (bytes memory) {
return writeBytes(abi.encodePacked(_in));
}
/**
* RLP encodes a uint.
* @param _in The uint256 to encode.
* @return The RLP encoded uint256 in bytes.
*/
function writeUint(uint256 _in) internal pure returns (bytes memory) {
return writeBytes(_toBinary(_in));
}
/**
* RLP encodes a bool.
* @param _in The bool to encode.
* @return The RLP encoded bool in bytes.
*/
function writeBool(bool _in) internal pure returns (bytes memory) {
bytes memory encoded = new bytes(1);
encoded[0] = (_in ? bytes1(0x01) : bytes1(0x80));
return encoded;
}
/*********************
* Private Functions *
*********************/
/**
* Encode the first byte, followed by the `len` in binary form if `length` is more than 55.
* @param _len The length of the string or the payload.
* @param _offset 128 if item is string, 192 if item is list.
* @return RLP encoded bytes.
*/
function _writeLength(uint256 _len, uint256 _offset) private pure returns (bytes memory) {
bytes memory encoded;
if (_len < 56) {
encoded = new bytes(1);
encoded[0] = bytes1(uint8(_len) + uint8(_offset));
} else {
uint256 lenLen;
uint256 i = 1;
while (_len / i != 0) {
lenLen++;
i *= 256;
}
encoded = new bytes(lenLen + 1);
encoded[0] = bytes1(uint8(lenLen) + uint8(_offset) + 55);
for (i = 1; i <= lenLen; i++) {
encoded[i] = bytes1(uint8((_len / (256**(lenLen - i))) % 256));
}
}
return encoded;
}
/**
* Encode integer in big endian binary form with no leading zeroes.
* @notice TODO: This should be optimized with assembly to save gas costs.
* @param _x The integer to encode.
* @return RLP encoded bytes.
*/
function _toBinary(uint256 _x) private pure returns (bytes memory) {
bytes memory b = abi.encodePacked(_x);
uint256 i = 0;
for (; i < 32; i++) {
if (b[i] != 0) {
break;
}
}
bytes memory res = new bytes(32 - i);
for (uint256 j = 0; j < res.length; j++) {
res[j] = b[i++];
}
return res;
}
/**
* Copies a piece of memory to another location.
* @notice From: https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol.
* @param _dest Destination location.
* @param _src Source location.
* @param _len Length of memory to copy.
*/
function _memcpy(
uint256 _dest,
uint256 _src,
uint256 _len
) private pure {
uint256 dest = _dest;
uint256 src = _src;
uint256 len = _len;
for (; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
dest += 32;
src += 32;
}
uint256 mask;
unchecked {
mask = 256**(32 - len) - 1;
}
assembly {
let srcpart := and(mload(src), not(mask))
let destpart := and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
/**
* Flattens a list of byte strings into one byte string.
* @notice From: https://github.com/sammayo/solidity-rlp-encoder/blob/master/RLPEncode.sol.
* @param _list List of byte strings to flatten.
* @return The flattened byte string.
*/
function _flatten(bytes[] memory _list) private pure returns (bytes memory) {
if (_list.length == 0) {
return new bytes(0);
}
uint256 len;
uint256 i = 0;
for (; i < _list.length; i++) {
len += _list[i].length;
}
bytes memory flattened = new bytes(len);
uint256 flattenedPtr;
assembly {
flattenedPtr := add(flattened, 0x20)
}
for (i = 0; i < _list.length; i++) {
bytes memory item = _list[i];
uint256 listPtr;
assembly {
listPtr := add(item, 0x20)
}
_memcpy(flattenedPtr, listPtr, item.length);
flattenedPtr += _list[i].length;
}
return flattened;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_BytesUtils } from "../Lib_BytesUtils.sol";
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
import { Lib_RLPWriter } from "../rlp/Lib_RLPWriter.sol";
/**
* @title Lib_MerkleTrie
*/
library Lib_MerkleTrie {
/*******************
* Data Structures *
*******************/
enum NodeType {
BranchNode,
ExtensionNode,
LeafNode
}
struct TrieNode {
bytes encoded;
Lib_RLPReader.RLPItem[] decoded;
}
/**********************
* Contract Constants *
**********************/
// TREE_RADIX determines the number of elements per branch node.
uint256 constant TREE_RADIX = 16;
// Branch nodes have TREE_RADIX elements plus an additional `value` slot.
uint256 constant BRANCH_NODE_LENGTH = TREE_RADIX + 1;
// Leaf nodes and extension nodes always have two elements, a `path` and a `value`.
uint256 constant LEAF_OR_EXTENSION_NODE_LENGTH = 2;
// Prefixes are prepended to the `path` within a leaf or extension node and
// allow us to differentiate between the two node types. `ODD` or `EVEN` is
// determined by the number of nibbles within the unprefixed `path`. If the
// number of nibbles if even, we need to insert an extra padding nibble so
// the resulting prefixed `path` has an even number of nibbles.
uint8 constant PREFIX_EXTENSION_EVEN = 0;
uint8 constant PREFIX_EXTENSION_ODD = 1;
uint8 constant PREFIX_LEAF_EVEN = 2;
uint8 constant PREFIX_LEAF_ODD = 3;
// Just a utility constant. RLP represents `NULL` as 0x80.
bytes1 constant RLP_NULL = bytes1(0x80);
/**********************
* Internal Functions *
**********************/
/**
* @notice Verifies a proof that a given key/value pair is present in the
* Merkle trie.
* @param _key Key of the node to search for, as a hex string.
* @param _value Value of the node to search for, as a hex string.
* @param _proof Merkle trie inclusion proof for the desired node. Unlike
* traditional Merkle trees, this proof is executed top-down and consists
* of a list of RLP-encoded nodes that make a path down to the target node.
* @param _root Known root of the Merkle trie. Used to verify that the
* included proof is correctly constructed.
* @return _verified `true` if the k/v pair exists in the trie, `false` otherwise.
*/
function verifyInclusionProof(
bytes memory _key,
bytes memory _value,
bytes memory _proof,
bytes32 _root
) internal pure returns (bool _verified) {
(bool exists, bytes memory value) = get(_key, _proof, _root);
return (exists && Lib_BytesUtils.equal(_value, value));
}
/**
* @notice Retrieves the value associated with a given key.
* @param _key Key to search for, as hex bytes.
* @param _proof Merkle trie inclusion proof for the key.
* @param _root Known root of the Merkle trie.
* @return _exists Whether or not the key exists.
* @return _value Value of the key if it exists.
*/
function get(
bytes memory _key,
bytes memory _proof,
bytes32 _root
) internal pure returns (bool _exists, bytes memory _value) {
TrieNode[] memory proof = _parseProof(_proof);
(uint256 pathLength, bytes memory keyRemainder, bool isFinalNode) = _walkNodePath(
proof,
_key,
_root
);
bool exists = keyRemainder.length == 0;
require(exists || isFinalNode, "Provided proof is invalid.");
bytes memory value = exists ? _getNodeValue(proof[pathLength - 1]) : bytes("");
return (exists, value);
}
/*********************
* Private Functions *
*********************/
/**
* @notice Walks through a proof using a provided key.
* @param _proof Inclusion proof to walk through.
* @param _key Key to use for the walk.
* @param _root Known root of the trie.
* @return _pathLength Length of the final path
* @return _keyRemainder Portion of the key remaining after the walk.
* @return _isFinalNode Whether or not we've hit a dead end.
*/
function _walkNodePath(
TrieNode[] memory _proof,
bytes memory _key,
bytes32 _root
)
private
pure
returns (
uint256 _pathLength,
bytes memory _keyRemainder,
bool _isFinalNode
)
{
uint256 pathLength = 0;
bytes memory key = Lib_BytesUtils.toNibbles(_key);
bytes32 currentNodeID = _root;
uint256 currentKeyIndex = 0;
uint256 currentKeyIncrement = 0;
TrieNode memory currentNode;
// Proof is top-down, so we start at the first element (root).
for (uint256 i = 0; i < _proof.length; i++) {
currentNode = _proof[i];
currentKeyIndex += currentKeyIncrement;
// Keep track of the proof elements we actually need.
// It's expensive to resize arrays, so this simply reduces gas costs.
pathLength += 1;
if (currentKeyIndex == 0) {
// First proof element is always the root node.
require(keccak256(currentNode.encoded) == currentNodeID, "Invalid root hash");
} else if (currentNode.encoded.length >= 32) {
// Nodes 32 bytes or larger are hashed inside branch nodes.
require(
keccak256(currentNode.encoded) == currentNodeID,
"Invalid large internal hash"
);
} else {
// Nodes smaller than 31 bytes aren't hashed.
require(
Lib_BytesUtils.toBytes32(currentNode.encoded) == currentNodeID,
"Invalid internal node hash"
);
}
if (currentNode.decoded.length == BRANCH_NODE_LENGTH) {
if (currentKeyIndex == key.length) {
// We've hit the end of the key
// meaning the value should be within this branch node.
break;
} else {
// We're not at the end of the key yet.
// Figure out what the next node ID should be and continue.
uint8 branchKey = uint8(key[currentKeyIndex]);
Lib_RLPReader.RLPItem memory nextNode = currentNode.decoded[branchKey];
currentNodeID = _getNodeID(nextNode);
currentKeyIncrement = 1;
continue;
}
} else if (currentNode.decoded.length == LEAF_OR_EXTENSION_NODE_LENGTH) {
bytes memory path = _getNodePath(currentNode);
uint8 prefix = uint8(path[0]);
uint8 offset = 2 - (prefix % 2);
bytes memory pathRemainder = Lib_BytesUtils.slice(path, offset);
bytes memory keyRemainder = Lib_BytesUtils.slice(key, currentKeyIndex);
uint256 sharedNibbleLength = _getSharedNibbleLength(pathRemainder, keyRemainder);
if (prefix == PREFIX_LEAF_EVEN || prefix == PREFIX_LEAF_ODD) {
if (
pathRemainder.length == sharedNibbleLength &&
keyRemainder.length == sharedNibbleLength
) {
// The key within this leaf matches our key exactly.
// Increment the key index to reflect that we have no remainder.
currentKeyIndex += sharedNibbleLength;
}
// We've hit a leaf node, so our next node should be NULL.
currentNodeID = bytes32(RLP_NULL);
break;
} else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) {
if (sharedNibbleLength != pathRemainder.length) {
// Our extension node is not identical to the remainder.
// We've hit the end of this path
// updates will need to modify this extension.
currentNodeID = bytes32(RLP_NULL);
break;
} else {
// Our extension shares some nibbles.
// Carry on to the next node.
currentNodeID = _getNodeID(currentNode.decoded[1]);
currentKeyIncrement = sharedNibbleLength;
continue;
}
} else {
revert("Received a node with an unknown prefix");
}
} else {
revert("Received an unparseable node.");
}
}
// If our node ID is NULL, then we're at a dead end.
bool isFinalNode = currentNodeID == bytes32(RLP_NULL);
return (pathLength, Lib_BytesUtils.slice(key, currentKeyIndex), isFinalNode);
}
/**
* @notice Parses an RLP-encoded proof into something more useful.
* @param _proof RLP-encoded proof to parse.
* @return _parsed Proof parsed into easily accessible structs.
*/
function _parseProof(bytes memory _proof) private pure returns (TrieNode[] memory _parsed) {
Lib_RLPReader.RLPItem[] memory nodes = Lib_RLPReader.readList(_proof);
TrieNode[] memory proof = new TrieNode[](nodes.length);
for (uint256 i = 0; i < nodes.length; i++) {
bytes memory encoded = Lib_RLPReader.readBytes(nodes[i]);
proof[i] = TrieNode({ encoded: encoded, decoded: Lib_RLPReader.readList(encoded) });
}
return proof;
}
/**
* @notice Picks out the ID for a node. Node ID is referred to as the
* "hash" within the specification, but nodes < 32 bytes are not actually
* hashed.
* @param _node Node to pull an ID for.
* @return _nodeID ID for the node, depending on the size of its contents.
*/
function _getNodeID(Lib_RLPReader.RLPItem memory _node) private pure returns (bytes32 _nodeID) {
bytes memory nodeID;
if (_node.length < 32) {
// Nodes smaller than 32 bytes are RLP encoded.
nodeID = Lib_RLPReader.readRawBytes(_node);
} else {
// Nodes 32 bytes or larger are hashed.
nodeID = Lib_RLPReader.readBytes(_node);
}
return Lib_BytesUtils.toBytes32(nodeID);
}
/**
* @notice Gets the path for a leaf or extension node.
* @param _node Node to get a path for.
* @return _path Node path, converted to an array of nibbles.
*/
function _getNodePath(TrieNode memory _node) private pure returns (bytes memory _path) {
return Lib_BytesUtils.toNibbles(Lib_RLPReader.readBytes(_node.decoded[0]));
}
/**
* @notice Gets the path for a node.
* @param _node Node to get a value for.
* @return _value Node value, as hex bytes.
*/
function _getNodeValue(TrieNode memory _node) private pure returns (bytes memory _value) {
return Lib_RLPReader.readBytes(_node.decoded[_node.decoded.length - 1]);
}
/**
* @notice Utility; determines the number of nibbles shared between two
* nibble arrays.
* @param _a First nibble array.
* @param _b Second nibble array.
* @return _shared Number of shared nibbles.
*/
function _getSharedNibbleLength(bytes memory _a, bytes memory _b)
private
pure
returns (uint256 _shared)
{
uint256 i = 0;
while (_a.length > i && _b.length > i && _a[i] == _b[i]) {
i++;
}
return i;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_MerkleTrie } from "./Lib_MerkleTrie.sol";
/**
* @title Lib_SecureMerkleTrie
*/
library Lib_SecureMerkleTrie {
/**********************
* Internal Functions *
**********************/
/**
* @notice Verifies a proof that a given key/value pair is present in the
* Merkle trie.
* @param _key Key of the node to search for, as a hex string.
* @param _value Value of the node to search for, as a hex string.
* @param _proof Merkle trie inclusion proof for the desired node. Unlike
* traditional Merkle trees, this proof is executed top-down and consists
* of a list of RLP-encoded nodes that make a path down to the target node.
* @param _root Known root of the Merkle trie. Used to verify that the
* included proof is correctly constructed.
* @return _verified `true` if the k/v pair exists in the trie, `false` otherwise.
*/
function verifyInclusionProof(
bytes memory _key,
bytes memory _value,
bytes memory _proof,
bytes32 _root
) internal pure returns (bool _verified) {
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.verifyInclusionProof(key, _value, _proof, _root);
}
/**
* @notice Retrieves the value associated with a given key.
* @param _key Key to search for, as hex bytes.
* @param _proof Merkle trie inclusion proof for the key.
* @param _root Known root of the Merkle trie.
* @return _exists Whether or not the key exists.
* @return _value Value of the key if it exists.
*/
function get(
bytes memory _key,
bytes memory _proof,
bytes32 _root
) internal pure returns (bool _exists, bytes memory _value) {
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.get(key, _proof, _root);
}
/*********************
* Private Functions *
*********************/
/**
* Computes the secure counterpart to a key.
* @param _key Key to get a secure key from.
* @return _secureKey Secure version of the key.
*/
function _getSecureKey(bytes memory _key) private pure returns (bytes memory _secureKey) {
return abi.encodePacked(keccak256(_key));
}
}
......@@ -13,13 +13,9 @@ import { OptimismPortal } from "../L1/OptimismPortal.sol";
import { L2ToL1MessagePasser } from "../L2/L2ToL1MessagePasser.sol";
import { L1CrossDomainMessenger } from "../L1/L1CrossDomainMessenger.sol";
import { L2CrossDomainMessenger } from "../L2/L2CrossDomainMessenger.sol";
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { OVM_ETH } from "../L2/OVM_ETH.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract CommonTest is Test {
......
......@@ -4,7 +4,7 @@ pragma solidity 0.8.10;
import { CommonTest } from "./CommonTest.t.sol";
import { GasPriceOracle } from "../L2/GasPriceOracle.sol";
import { L1Block } from "../L2/L1Block.sol";
import { Lib_BedrockPredeployAddresses } from "../libraries/Lib_BedrockPredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
contract GasPriceOracle_Test is CommonTest {
......@@ -19,11 +19,11 @@ contract GasPriceOracle_Test is CommonTest {
function setUp() external {
// place the L1Block contract at the predeploy address
vm.etch(
Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES,
Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES,
address(new L1Block()).code
);
l1Block = L1Block(Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES);
l1Block = L1Block(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES);
depositor = l1Block.DEPOSITOR_ACCOUNT();
// We are not setting the gas oracle at its predeploy
......
......@@ -4,15 +4,15 @@ pragma solidity 0.8.10;
import { Test } from "forge-std/Test.sol";
import { L1Block } from "../L2/L1Block.sol";
import { L1BlockNumber } from "../L2/L1BlockNumber.sol";
import { Lib_BedrockPredeployAddresses } from "../libraries/Lib_BedrockPredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
contract L1BlockNumberTest is Test {
L1Block lb;
L1BlockNumber bn;
function setUp() external {
vm.etch(Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES, address(new L1Block()).code);
lb = L1Block(Lib_BedrockPredeployAddresses.L1_BLOCK_ATTRIBUTES);
vm.etch(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES, address(new L1Block()).code);
lb = L1Block(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES);
bn = new L1BlockNumber();
vm.prank(lb.DEPOSITOR_ACCOUNT());
lb.setL1BlockValues(uint64(999), uint64(2), 3, keccak256(abi.encode(1)), uint64(4));
......
......@@ -6,18 +6,10 @@ import { Messenger_Initializer } from "./CommonTest.t.sol";
import { L2OutputOracle_Initializer } from "./L2OutputOracle.t.sol";
/* Libraries */
import {
AddressAliasHelper
} from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import {
Lib_DefaultValues
} from "@eth-optimism/contracts/libraries/constants/Lib_DefaultValues.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import {
Lib_CrossDomainUtils
} from "@eth-optimism/contracts/libraries/bridge/Lib_CrossDomainUtils.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { Lib_DefaultValues } from "../libraries/Lib_DefaultValues.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { Lib_CrossDomainUtils } from "../libraries/Lib_CrossDomainUtils.sol";
import { WithdrawalVerifier } from "../libraries/Lib_WithdrawalVerifier.sol";
/* Target contract dependencies */
......@@ -29,10 +21,6 @@ import { CrossDomainHashing } from "../libraries/Lib_CrossDomainHashing.sol";
/* Target contract */
import { L1CrossDomainMessenger } from "../L1/L1CrossDomainMessenger.sol";
import {
ICrossDomainMessenger
} from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
contract L1CrossDomainMessenger_Test is Messenger_Initializer {
// Receiver address for testing
address recipient = address(0xabbaacdc);
......
......@@ -5,10 +5,8 @@ import { Bridge_Initializer } from "./CommonTest.t.sol";
import { StandardBridge } from "../universal/StandardBridge.sol";
import { L2StandardBridge } from "../L2/L2StandardBridge.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { stdStorage, StdStorage } from "forge-std/Test.sol";
......
......@@ -3,26 +3,14 @@ pragma solidity 0.8.10;
import { Messenger_Initializer } from "./CommonTest.t.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import {
Lib_CrossDomainUtils
} from "@eth-optimism/contracts/libraries/bridge/Lib_CrossDomainUtils.sol";
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import { Lib_CrossDomainUtils } from "../libraries/Lib_CrossDomainUtils.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { L2ToL1MessagePasser } from "../L2/L2ToL1MessagePasser.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { L2CrossDomainMessenger } from "../L2/L2CrossDomainMessenger.sol";
import { L1CrossDomainMessenger } from "../L1/L1CrossDomainMessenger.sol";
import { Lib_BedrockPredeployAddresses } from "../libraries/Lib_BedrockPredeployAddresses.sol";
import { CrossDomainHashing } from "../libraries/Lib_CrossDomainHashing.sol";
import {
Lib_DefaultValues
} from "@eth-optimism/contracts/libraries/constants/Lib_DefaultValues.sol";
import { console } from "forge-std/console.sol";
import { Lib_DefaultValues } from "../libraries/Lib_DefaultValues.sol";
contract L2CrossDomainMessenger_Test is Messenger_Initializer {
// Receiver address for testing
......
......@@ -3,10 +3,7 @@ pragma solidity ^0.8.9;
import { CommonTest } from "./CommonTest.t.sol";
import { OVM_ETH } from "../L2/OVM_ETH.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
contract OVM_ETH_Test is CommonTest {
OVM_ETH eth;
......
......@@ -4,7 +4,7 @@ pragma solidity 0.8.10;
import { Bridge_Initializer } from "./CommonTest.t.sol";
import { LibRLP } from "./Lib_RLP.t.sol";
contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
contract OptimismMintableERC20_Test is Bridge_Initializer {
event Mint(address indexed _account, uint256 _amount);
event Burn(address indexed _account, uint256 _amount);
......
//SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";
import { CommonTest } from "./CommonTest.t.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { OptimismPortal } from "../L1/OptimismPortal.sol";
import { WithdrawalVerifier } from "../libraries/Lib_WithdrawalVerifier.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Bridge_Initializer } from "./CommonTest.t.sol";
import { SequencerFeeVault } from "../L2/SequencerFeeVault.sol";
import { L2StandardBridge } from "../L2/L2StandardBridge.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
contract SequencerFeeVault_Test is Bridge_Initializer {
SequencerFeeVault vault =
......
......@@ -4,9 +4,7 @@ pragma solidity ^0.8.9;
// solhint-disable max-line-length
/* Library Imports */
import {
Lib_DefaultValues
} from "@eth-optimism/contracts/libraries/constants/Lib_DefaultValues.sol";
import { Lib_DefaultValues } from "../libraries/Lib_DefaultValues.sol";
import { CrossDomainHashing } from "../libraries/Lib_CrossDomainHashing.sol";
/* External Imports */
......
......@@ -3,9 +3,7 @@ pragma solidity ^0.8.9;
/* Contract Imports */
import { OptimismMintableERC20 } from "../universal/OptimismMintableERC20.sol";
import {
Lib_PredeployAddresses
} from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
/**
* @title OptimismMintableTokenFactory
......
......@@ -5,10 +5,13 @@ src = 'contracts'
out = 'forge-artifacts'
optimizer = true
optimizer_runs = 999999
remappings = [
'@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/',
'@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/',
'@eth-optimism/contracts/=node_modules/@eth-optimism/contracts/',
'excessively-safe-call/=node_modules/excessively-safe-call/src/',
'solmate/=node_modules/@rari-capital/solmate/src',
'forge-std/=node_modules/forge-std/src',
'ds-test/=node_modules/ds-test/src'
]
bytecode_hash = "none"
......@@ -2,9 +2,9 @@ import { HardhatUserConfig, task, subtask } from 'hardhat/config'
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from 'hardhat/builtin-tasks/task-names'
import '@nomiclabs/hardhat-waffle'
import '@typechain/hardhat'
import 'hardhat-gas-reporter'
import 'solidity-coverage'
import 'hardhat-deploy'
import '@foundry-rs/hardhat-forge'
import './tasks/deposits'
......@@ -33,9 +33,9 @@ const config: HardhatUserConfig = {
],
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: 'USD',
typechain: {
outDir: 'dist/types',
target: 'ethers-v5',
},
namedAccounts: {
deployer: {
......
import { BigNumber, BigNumberish, BytesLike, ContractReceipt, ethers, Event } from 'ethers'
function formatNumber(value: BigNumberish, name: string): Uint8Array {
import {
BigNumber,
BigNumberish,
BytesLike,
ContractReceipt,
ethers,
Event,
} from 'ethers'
const formatNumber = (value: BigNumberish, name: string): Uint8Array => {
const result = ethers.utils.stripZeros(BigNumber.from(value).toHexString())
if (result.length > 32) {
throw new Error(`invalid length for ${name}`)
......@@ -8,14 +15,14 @@ function formatNumber(value: BigNumberish, name: string): Uint8Array {
return result
}
function handleNumber(value: string): BigNumber {
const handleNumber = (value: string): BigNumber => {
if (value === '0x') {
return ethers.constants.Zero
}
return BigNumber.from(value)
}
function handleAddress(value: string): string {
const handleAddress = (value: string): string => {
if (value === '0x') {
// @ts-ignore
return null
......@@ -102,10 +109,16 @@ export class DepositTx {
}
const l1BlockHash = this.l1BlockHash
const input = ethers.utils.hexConcat([l1BlockHash, ethers.utils.zeroPad(marker, 32)])
const input = ethers.utils.hexConcat([
l1BlockHash,
ethers.utils.zeroPad(marker, 32),
])
const depositIDHash = ethers.utils.keccak256(input)
const domain = BigNumber.from(this.domain).toHexString()
const domainInput = ethers.utils.hexConcat([ethers.utils.zeroPad(domain, 32), depositIDHash])
const domainInput = ethers.utils.hexConcat([
ethers.utils.zeroPad(domain, 32),
depositIDHash,
])
this._sourceHash = ethers.utils.keccak256(domainInput)
}
return this._sourceHash
......@@ -157,7 +170,9 @@ export class DepositTx {
}
fromL1Receipt(receipt: ContractReceipt, index: number): DepositTx {
if (!receipt.events) throw new Error('cannot parse receipt')
if (!receipt.events) {
throw new Error('cannot parse receipt')
}
const event = receipt.events[index]
if (!event) {
throw new Error(`event index ${index} does not exist`)
......@@ -170,27 +185,38 @@ export class DepositTx {
}
fromL1Event(event: Event): DepositTx {
if (event.event !== 'TransactionDeposited')
if (event.event !== 'TransactionDeposited') {
throw new Error(`incorrect event type: ${event.event}`)
if (typeof event.args === 'undefined') throw new Error('no event args')
if (typeof event.args.from === 'undefined')
}
if (typeof event.args === 'undefined') {
throw new Error('no event args')
}
if (typeof event.args.from === 'undefined') {
throw new Error('"from" undefined')
}
this.from = event.args.from
if (typeof event.args.isCreation === 'undefined')
if (typeof event.args.isCreation === 'undefined') {
throw new Error('"isCreation" undefined')
if (typeof event.args.to === 'undefined') throw new Error('"to" undefined')
}
if (typeof event.args.to === 'undefined') {
throw new Error('"to" undefined')
}
this.to = event.args.isCreation ? null : event.args.to
if (typeof event.args.mint === 'undefined')
if (typeof event.args.mint === 'undefined') {
throw new Error('"mint" undefined')
}
this.mint = event.args.mint
if (typeof event.args.value === 'undefined')
if (typeof event.args.value === 'undefined') {
throw new Error('"value" undefined')
}
this.value = event.args.value
if (typeof event.args.gasLimit === 'undefined')
if (typeof event.args.gasLimit === 'undefined') {
throw new Error('"gasLimit" undefined')
}
this.gas = event.args.gasLimit
if (typeof event.args.data === 'undefined')
if (typeof event.args.data === 'undefined') {
throw new Error('"data" undefined')
}
this.data = event.args.data
this.domain = SourceHashDomain.UserDeposit
this.l1BlockHash = event.blockHash
......
{
"name": "@eth-optimism/specs-contracts",
"name": "@eth-optimism/contracts-bedrock",
"version": "0.1.0",
"description": "Contracts for Optimism Specs",
"main": "index.js",
"main": "dist/index",
"types": "dist/index",
"license": "MIT",
"files": [
"dist/**/*.js",
"dist/**/*.d.ts",
"dist/types/*.ts",
"artifacts/src/**/*.json",
"deployments/**/*.json"
],
"dependencies": {
"@eth-optimism/contracts": "^0.5.21",
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/contracts-upgradeable": "^4.5.2",
"ethers": "^5.6.8",
"hardhat": "^2.9.6",
"@rari-capital/solmate": "7.0.0-alpha.1",
"ds-test": "https://github.com/dapphub/ds-test.git#9310e879db8ba3ea6d5c6489a579118fd264a3f5",
"forge-std": "https://github.com/foundry-rs/forge-std.git#1680d7fb3e00b7b197a7336e7c88e838c7e6a3ec",
"merkle-patricia-tree": "^4.2.4",
"rlp": "^2.2.7"
},
"scripts": {
"build:forge": "forge build",
"build:hh": "yarn hardhat compile",
"build": "yarn build:forge && yarn build:hh",
"build": "yarn hardhat compile",
"test:hh": "yarn hardhat test",
"test": "yarn test:forge",
"test:forge": "forge test",
"gas-snapshot": "forge snapshot",
"slither": "slither .",
"clean": "rm -rf ./artifacts ./forge-artifacts ./cache ./coverage ./tsconfig.build.tsbuildinfo",
"clean": "rm -rf ./artifacts ./forge-artifacts ./cache ./coverage ./tsconfig.tsbuildinfo",
"lint:ts:check": "eslint .",
"lint:contracts:check": "yarn solhint -f table 'contracts/**/*.sol'",
"lint:check": "yarn lint:contracts:check && yarn lint:ts:check",
......@@ -33,36 +42,24 @@
},
"devDependencies": {
"@eth-optimism/core-utils": "^0.7.3",
"@foundry-rs/hardhat-forge": "^0.1.5",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.1.3",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@typechain/ethers-v5": "^7.0.1",
"@typechain/hardhat": "^2.3.0",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^4.29.1",
"chai": "^4.2.0",
"dotenv": "^16.0.0",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.1.0",
"ethereum-waffle": "^3.0.0",
"ethers": "^5.6.8",
"hardhat-deploy": "^0.11.4",
"hardhat-gas-reporter": "^1.0.4",
"prettier": "^2.3.2",
"prettier-plugin-solidity": "^1.0.0-beta.13",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.16",
"ts-node": "^10.1.0",
"typechain": "^5.1.2",
"typescript": "^4.5.2"
"typescript": "^4.6.2"
}
}
import { task, types } from 'hardhat/config'
import { Contract, providers, utils, Wallet } from 'ethers'
import { Event } from '@ethersproject/contracts'
import { Contract, providers, utils, Wallet, Event } from 'ethers'
import dotenv from 'dotenv'
import { DepositTx, SourceHashDomain } from '../helpers/index'
import { DepositTx } from '../helpers/index'
dotenv.config()
async function sleep(ms: number) {
const sleep = async (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms))
}
......@@ -37,7 +37,7 @@ task('deposit', 'Deposits funds onto L2.')
'deaddeaddeaddeaddeaddeaddeaddeaddead0001',
types.string
)
.setAction(async (args) => {
.setAction(async (args, hre) => {
const {
l1ProviderUrl,
l2ProviderUrl,
......@@ -46,7 +46,7 @@ task('deposit', 'Deposits funds onto L2.')
depositContractAddr,
privateKey,
} = args
const depositFeedArtifact = require('../artifacts/contracts/L1/OptimismPortal.sol/OptimismPortal.json')
const depositFeedArtifact = await hre.deployments.get('OptimismPortal')
const l1Provider = new providers.JsonRpcProvider(l1ProviderUrl)
const l2Provider = new providers.JsonRpcProvider(l2ProviderUrl)
......@@ -95,8 +95,8 @@ task('deposit', 'Deposits funds onto L2.')
console.log(`Waiting for L2 TX hash ${hash}`)
while (true) {
const tx = await l2Provider.send('eth_getTransactionByHash', [hash])
if (tx) {
const expected = await l2Provider.send('eth_getTransactionByHash', [hash])
if (expected) {
console.log('Deposit success')
break
}
......
import { expect } from 'chai'
import { BigNumber } from 'ethers'
import { DepositTx, SourceHashDomain } from '../helpers'
import { BigNumber } from '@ethersproject/bignumber'
describe('Helpers', () => {
describe('DepositTx', () => {
// TODO(tynes): this is out of date now that the subversion
// byte has been added
it('should serialize/deserialize and hash', () => {
// constants serialized using optimistic-geth
// TODO(tynes): more tests
......
{
"extends": "../../tsconfig.build.json",
"extends": "../../tsconfig.json",
"include": ["./scripts/", "./helpers/"],
"compilerOptions": {
"rootDir": ".",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
}
......@@ -7,4 +7,16 @@ ignores: [
"typescript",
"prettier-plugin-solidity",
"solhint-plugin-prettier",
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai",
"babel-eslint"
]
......@@ -31,7 +31,7 @@
"lint:contracts:fix": "yarn prettier --write 'contracts/**/*.sol'",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"lint": "yarn lint:fix && yarn lint:check",
"clean": "rm -rf ./dist ./artifacts ./cache ./coverage ./tsconfig.build.tsbuildinfo",
"clean": "rm -rf ./dist ./artifacts ./cache ./coverage ./tsconfig.tsbuildinfo",
"prepublishOnly": "yarn copyfiles -u 1 -e \"**/test-*/**/*\" \"contracts/**/*\" ./",
"postpublish": "rimraf chugsplash L1 L2 libraries standards",
"prepack": "yarn prepublishOnly",
......@@ -59,24 +59,15 @@
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@rari-capital/solmate": "^6.3.0",
"@openzeppelin/contracts": "4.6.0",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"copyfiles": "^2.3.0",
"dotenv": "^10.0.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.6.8",
"hardhat": "^2.9.6",
......@@ -92,6 +83,6 @@
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.17",
"ts-node": "^10.0.0",
"typescript": "^4.6.2"
"mocha": "^10.0.0"
}
}
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
}
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
......@@ -7,4 +7,14 @@ ignores: [
"prettier-plugin-solidity",
"solhint-plugin-prettier",
"ts-generator",
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier"
]
......@@ -22,7 +22,7 @@ const enableGasReport = !!process.env.ENABLE_GAS_REPORT
const privateKey = process.env.PRIVATE_KEY || '0x' + '11'.repeat(32) // this is to avoid hardhat error
const deploy = process.env.DEPLOY_DIRECTORY || 'deploy'
const config: HardhatUserConfig = {
const config: HardhatUserConfig | any = {
networks: {
hardhat: {
live: false,
......
......@@ -18,7 +18,7 @@
],
"scripts": {
"build": "yarn build:contracts && yarn autogen:artifacts && yarn build:typescript",
"build:typescript": "tsc -p ./tsconfig.build.json",
"build:typescript": "tsc -p ./tsconfig.json",
"build:contracts": "hardhat compile --show-stack-traces",
"autogen:markdown": "ts-node scripts/generate-markdown.ts",
"autogen:artifacts": "ts-node scripts/generate-artifacts.ts && ts-node scripts/generate-deployed-artifacts.ts",
......@@ -35,7 +35,7 @@
"lint:contracts:fix": "yarn prettier --write 'contracts/**/*.sol'",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"lint": "yarn lint:fix && yarn lint:check",
"clean": "rm -rf ./dist ./artifacts ./cache ./coverage ./tsconfig.build.tsbuildinfo",
"clean": "rm -rf ./dist ./artifacts ./cache ./coverage ./tsconfig.tsbuildinfo",
"prepublishOnly": "yarn copyfiles -u 1 -e \"**/test-*/**/*\" \"contracts/**/*\" ./",
"postpublish": "rimraf chugsplash L1 L2 libraries standards",
"prepack": "yarn prepublishOnly",
......@@ -82,21 +82,10 @@
"@types/mkdirp": "^1.0.1",
"@types/mocha": "^8.2.2",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"copyfiles": "^2.3.0",
"directory-tree": "^2.2.7",
"dotenv": "^10.0.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.6.8",
"glob": "^7.1.6",
......
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
}
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
ignores: [
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai"
]
......@@ -9,8 +9,8 @@
],
"scripts": {
"all": "yarn clean && yarn build && yarn test && yarn lint:fix && yarn lint",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"lint:check": "eslint . --max-warnings=0",
"lint:fix": "yarn lint:check --fix",
......@@ -40,24 +40,6 @@
"ethers": "^5.6.8"
},
"devDependencies": {
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"lint-staged": "11.0.0",
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"prettier": "^2.3.1",
"ts-mocha": "^8.0.0",
"typescript": "^4.6.2"
"mocha": "^10.0.0"
}
}
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"typeRoots": ["node_modules/@types", "src/@types"]
}
"rootDir": "./src",
"outDir": "./dist"
},
"compilerOptions": {
"typeRoots": ["node_modules/@types"]
},
"include": [
"src/**/*"
]
}
ignores: [
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai"
]
......@@ -9,7 +9,7 @@
"dist/index"
],
"scripts": {
"clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo",
"clean": "rimraf ./dist ./tsconfig.tsbuildinfo",
"clean:db": "rimraf ./db",
"lint": "yarn run lint:fix && yarn run lint:check",
"lint:fix": "yarn lint:check --fix",
......@@ -18,7 +18,7 @@
"start:local": "ts-node ./src/services/run.ts | pino-pretty",
"test": "hardhat --config test/config/hardhat.config.ts test",
"test:coverage": "nyc hardhat --config test/config/hardhat.config.ts test && nyc merge .nyc_output coverage.json",
"build": "tsc -p tsconfig.build.json",
"build": "tsc -p tsconfig.json",
"pre-commit": "lint-staged"
},
"keywords": [
......@@ -56,33 +56,16 @@
"levelup": "^4.4.0"
},
"devDependencies": {
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/cors": "^2.8.9",
"@types/levelup": "^4.3.0",
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"bfj": "^7.0.2",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"hardhat": "^2.9.6",
"lint-staged": "11.0.0",
"mocha": "^8.4.0",
"pino-pretty": "^4.7.1",
"prettier": "^2.3.1",
"prom-client": "^13.1.0",
"rimraf": "^3.0.2",
"ts-node": "^10.0.0",
"typescript": "^4.6.2"
"ts-node": "^10.0.0"
}
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"typeRoots": ["node_modules/@types", "src/@types"]
}
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
ignores: [
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai"
]
......@@ -11,8 +11,8 @@
"scripts": {
"start": "ts-node ./src/service.ts",
"test:coverage": "echo 'No tests defined.'",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"pre-commit": "lint-staged",
"lint:fix": "yarn lint:check --fix",
......@@ -33,11 +33,9 @@
},
"devDependencies": {
"@types/dateformat": "^5.0.0",
"@types/node": "^17.0.23",
"dateformat": "^4.5.1",
"ethers": "^5.6.8",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
"ts-node": "^10.7.0"
},
"dependencies": {
"@eth-optimism/common-ts": "^0.2.8",
......
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true
}
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
......@@ -8,7 +8,7 @@
"lint:fix": "yarn lint:check --fix",
"lint:check": "eslint . --max-warnings=0",
"build:contracts": "forge build --root . -c contracts -o artifacts",
"test": "ts-mocha --timeout 30000 test/**/*.spec.ts",
"test": "echo 'no unit tests'",
"test:actor": "IS_LIVE_NETWORK=true ts-node actor-tests/lib/runner.ts",
"test:integration:live": "NO_NETWORK=true IS_LIVE_NETWORK=true hardhat --network optimism test",
"clean": "rimraf cache artifacts"
......@@ -31,40 +31,17 @@
"@eth-optimism/core-utils": "0.8.5",
"@eth-optimism/sdk": "1.1.6",
"@ethersproject/abstract-provider": "^5.6.1",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/transactions": "^5.6.2",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^8.2.2",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"async-mutex": "^0.3.2",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"commander": "^8.3.0",
"chai": "^4.3.4",
"dotenv": "^10.0.0",
"envalid": "^7.1.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.6.8",
"mocha": "^8.4.0",
"node-fetch": "^2.6.7",
"prom-client": "^14.0.1",
"rimraf": "^3.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.3.5"
"ts-node": "^10.7.0"
},
"dependencies": {
"ts-mocha": "^9.0.2",
"rlp": "^3.0.0",
"winston": "^3.7.2"
}
}
......@@ -2,30 +2,41 @@
// can fall behind.
/* Imports: External */
import { BigNumber, constants, Contract, ContractReceipt, utils, Wallet } from 'ethers'
import {
BigNumber,
constants,
Contract,
ContractReceipt,
utils,
Wallet,
} from 'ethers'
import { awaitCondition } from '@eth-optimism/core-utils'
import * as rlp from 'rlp'
import { Block } from '@ethersproject/abstract-provider'
/* Imports: Internal */
import env from './shared/env'
import { expect } from './shared/setup'
import winston from 'winston'
import { predeploys } from '@eth-optimism/contracts'
const l2ToL1MessagePasserArtifact = require('../../contracts/artifacts/contracts/L2/L2ToL1MessagePasser.sol/L2ToL1MessagePasser.json')
const l2OOracleArtifact = require('../../contracts/artifacts/contracts/L1/L2OutputOracle.sol/L2OutputOracle.json')
import env from './shared/env'
import { expect } from './shared/setup'
import l2ToL1MessagePasserArtifact from '../../contracts-bedrock/artifacts/contracts/L2/L2ToL1MessagePasser.sol/L2ToL1MessagePasser.json'
import l2OOracleArtifact from '../../contracts-bedrock/artifacts/contracts/L1/L2OutputOracle.sol/L2OutputOracle.json'
/**
* Calculates the target output timestamp to make the withdrawal proof against. ie. the first
* output with a timestamp greater than the burn block timestamp.
*
* @param {Contract} oracle Address of the L2 Output Oracle.
* @param {number} withdrawalTimestamp L2 timestamp of the block the withdrawal was made in.
*/
const getTargetOutput = async (oracle: Contract, withdrawalTimestamp: number) => {
const getTargetOutput = async (
oracle: Contract,
withdrawalTimestamp: number
) => {
const submissionInterval = (await oracle.SUBMISSION_INTERVAL()).toNumber()
const startingBlockTimestamp = (await oracle.STARTING_BLOCK_TIMESTAMP()).toNumber()
let nextTimestamp = (await oracle.nextTimestamp()).toNumber()
const startingBlockTimestamp = (
await oracle.STARTING_BLOCK_TIMESTAMP()
).toNumber()
const nextTimestamp = (await oracle.nextTimestamp()).toNumber()
let targetOutputTimestamp
if (withdrawalTimestamp < nextTimestamp) {
// Just use the next timestamp
......@@ -33,18 +44,16 @@ const getTargetOutput = async (oracle: Contract, withdrawalTimestamp: number) =>
} else {
// Calculate the first timestamp greater than the burnBlock which will be appended.
targetOutputTimestamp =
Math.ceil(
(withdrawalTimestamp - startingBlockTimestamp)
/ submissionInterval
)
* submissionInterval
+ startingBlockTimestamp
Math.ceil(
(withdrawalTimestamp - startingBlockTimestamp) / submissionInterval
) *
submissionInterval +
startingBlockTimestamp
}
return targetOutputTimestamp
}
describe('Withdrawals', () => {
let logger: winston.Logger
let portal: Contract
......@@ -58,7 +67,7 @@ describe('Withdrawals', () => {
withdrawer = new Contract(
predeploys.OVM_L2ToL1MessagePasser,
l2ToL1MessagePasserArtifact.abi,
l2ToL1MessagePasserArtifact.abi
)
})
......@@ -78,16 +87,18 @@ describe('Withdrawals', () => {
recipient: recipient.address,
})
logger.info('Depositing to new address on L2')
let tx = await portal.connect(env.l1Wallet).depositTransaction(
recipient.address,
utils.parseEther('1.337'),
gasLimit,
false,
[],
{
value: utils.parseEther('1.337'),
},
)
let tx = await portal
.connect(env.l1Wallet)
.depositTransaction(
recipient.address,
utils.parseEther('1.337'),
gasLimit,
false,
[],
{
value: utils.parseEther('1.337'),
}
)
await tx.wait()
await awaitCondition(async () => {
......@@ -111,7 +122,7 @@ describe('Withdrawals', () => {
[],
{
value,
},
}
)
const receipt: ContractReceipt = await tx.wait()
expect(receipt.events!.length).to.eq(1)
......@@ -135,8 +146,8 @@ describe('Withdrawals', () => {
value,
gasLimit,
'0x',
],
),
]
)
)
const included = await withdrawer.sentMessages(withdrawalHash)
......@@ -150,39 +161,52 @@ describe('Withdrawals', () => {
portal = portal.connect(recipient)
const oracle = new Contract(
await portal.L2_ORACLE(),
l2OOracleArtifact.abi,
l2OOracleArtifact.abi
).connect(recipient)
const targetOutputTimestamp = await getTargetOutput(oracle, burnBlock.timestamp)
const targetOutputTimestamp = await getTargetOutput(
oracle,
burnBlock.timestamp
)
// Set the timeout based on the diff between latest output and target output timestamp.
let latestBlockTimestamp = (await oracle.latestBlockTimestamp()).toNumber()
let latestBlockTimestamp = (
await oracle.latestBlockTimestamp()
).toNumber()
let difference = targetOutputTimestamp - latestBlockTimestamp
this.timeout(difference * 5000)
let output: string
await awaitCondition(async () => {
const proposal = await oracle.getL2Output(targetOutputTimestamp)
output = proposal.outputRoot
latestBlockTimestamp = (await oracle.latestBlockTimestamp()).toNumber()
if(targetOutputTimestamp - latestBlockTimestamp < difference){
// Only log when a new output has been appended
difference = targetOutputTimestamp - latestBlockTimestamp
logger.info('Waiting for output submission', {
targetTimestamp: targetOutputTimestamp,
latestOracleTS: latestBlockTimestamp,
difference,
output,
})
}
return output != constants.HashZero
}, 2000, 2*difference)
await awaitCondition(
async () => {
const proposal = await oracle.getL2Output(targetOutputTimestamp)
output = proposal.outputRoot
latestBlockTimestamp = (
await oracle.latestBlockTimestamp()
).toNumber()
if (targetOutputTimestamp - latestBlockTimestamp < difference) {
// Only log when a new output has been appended
difference = targetOutputTimestamp - latestBlockTimestamp
logger.info('Waiting for output submission', {
targetTimestamp: targetOutputTimestamp,
latestOracleTS: latestBlockTimestamp,
difference,
output,
})
}
return output !== constants.HashZero
},
2000,
2 * difference
)
// suppress compilation errors since Typescript cannot detect
// that awaitCondition above will throw if it times out.
output = output!
const blocksSinceBurn = Math.floor((targetOutputTimestamp - burnBlock.timestamp) / 2)
const blocksSinceBurn = Math.floor(
(targetOutputTimestamp - burnBlock.timestamp) / 2
)
const targetBlockNum = burnBlock.number + blocksSinceBurn + 1
const targetBlockNumHex = utils.hexValue(targetBlockNum)
const storageSlot = '00'.repeat(31) + '01' // i.e the second variable declared in the contract
......@@ -192,19 +216,19 @@ describe('Withdrawals', () => {
targetBlockNumHex,
])
const {stateRoot: targetStateRoot, hash: targetHash} = await env.l2Provider.send(
'eth_getBlockByNumber',
[
const { stateRoot: targetStateRoot, hash: targetHash } =
await env.l2Provider.send('eth_getBlockByNumber', [
targetBlockNumHex,
false,
],
)
])
const finalizationPeriod = (await portal.FINALIZATION_PERIOD()).toNumber()
logger.info('Waiting finalization period', {
seconds: finalizationPeriod,
})
await new Promise((resolve) => setTimeout(resolve, finalizationPeriod * 1000))
await new Promise((resolve) =>
setTimeout(resolve, finalizationPeriod * 1000)
)
logger.info('Finalizing withdrawal')
const initialBal = await recipient.getBalance()
......@@ -225,7 +249,7 @@ describe('Withdrawals', () => {
rlp.encode(proof.storageProof[0].proof),
{
gasLimit,
},
}
)
await tx.wait()
const finalBal = await recipient.getBalance()
......
......@@ -5,9 +5,8 @@ import { awaitCondition } from '@eth-optimism/core-utils'
/* Imports: Internal */
import { defaultTransactionFactory } from './shared/utils'
import env from './shared/env'
const counterArtifact = require('../artifacts/Counter.sol/Counter.json')
const multiDepositorArtifact = require('../artifacts/MultiDepositor.sol/MultiDepositor.json')
import counterArtifact from '../artifacts/Counter.sol/Counter.json'
import multiDepositorArtifact from '../artifacts/MultiDepositor.sol/MultiDepositor.json'
describe('Deposits', () => {
let portal: Contract
......@@ -29,7 +28,7 @@ describe('Deposits', () => {
[],
{
value: tx.value,
},
}
)
await result.wait()
......@@ -44,7 +43,7 @@ describe('Deposits', () => {
const value = utils.parseEther('0.1')
const factory = new ContractFactory(
multiDepositorArtifact.abi,
multiDepositorArtifact.bytecode.object,
multiDepositorArtifact.bytecode.object
).connect(env.l1Wallet)
const contract = await factory.deploy(portal.address)
await contract.deployed()
......@@ -63,7 +62,7 @@ describe('Deposits', () => {
const value = utils.parseEther('0.1')
const factory = new ContractFactory(
counterArtifact.abi,
counterArtifact.bytecode.object,
counterArtifact.bytecode.object
)
const tx = await factory.getDeployTransaction()
const result = await portal.depositTransaction(
......@@ -73,8 +72,8 @@ describe('Deposits', () => {
true,
tx.data,
{
value: value,
},
value,
}
)
await result.wait()
const l2Nonce = await env.l2Wallet.getTransactionCount()
......
......@@ -5,8 +5,7 @@ import { ContractFactory, Wallet } from 'ethers'
import { expect } from './shared/setup'
import { defaultTransactionFactory } from './shared/utils'
import env from './shared/env'
const counterArtifact = require('../artifacts/Counter.sol/Counter.json')
import counterArtifact from '../artifacts/Counter.sol/Counter.json'
describe('RPCs', () => {
let wallet: Wallet
......@@ -38,10 +37,10 @@ describe('RPCs', () => {
it('should correctly process a contract creation', async () => {
const factory = new ContractFactory(
counterArtifact.abi,
counterArtifact.bytecode.object,
counterArtifact.bytecode.object
).connect(wallet)
const counter = await factory.deploy({
gasLimit: 1_000_000
gasLimit: 1_000_000,
})
await counter.deployed()
expect(await env.l2Provider.getCode(counter.address)).not.to.equal('0x')
......
......@@ -2,27 +2,26 @@
import { Wallet, providers, Contract } from 'ethers'
import { bool, cleanEnv, num, str } from 'envalid'
import dotenv from 'dotenv'
import winston, { info } from 'winston'
import winston from 'winston'
const {combine, timestamp, printf, colorize, align} = winston.format
const { combine, timestamp, printf, colorize, align } = winston.format
/* Imports: Internal */
const portalArtifact = require('../../../contracts/artifacts/contracts/L1/OptimismPortal.sol/OptimismPortal.json')
import portalArtifact from '../../../contracts-bedrock/artifacts/contracts/L1/OptimismPortal.sol/OptimismPortal.json'
dotenv.config()
const procEnv = cleanEnv(process.env, {
L1_URL: str({default: 'http://localhost:8545'}),
L1_POLLING_INTERVAL: num({default: 10}),
L1_URL: str({ default: 'http://localhost:8545' }),
L1_POLLING_INTERVAL: num({ default: 10 }),
L2_URL: str({default: 'http://localhost:9545'}),
L2_POLLING_INTERVAL: num({default: 1}),
L2_URL: str({ default: 'http://localhost:9545' }),
L2_POLLING_INTERVAL: num({ default: 1 }),
OPTIMISM_PORTAL_ADDRESS: str(),
PRIVATE_KEY: str({
default:
'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
default: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
}),
MOCHA_TIMEOUT: num({
......@@ -72,13 +71,13 @@ export class OptimismEnv {
this.l2Provider = l2Provider
this.optimismPortal = new Contract(
procEnv.OPTIMISM_PORTAL_ADDRESS,
portalArtifact.abi,
portalArtifact.abi
)
this.logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'info',
format: combine(
{
transform(info) {
transform: (info) => {
// @ts-ignore
const args = info[Symbol.for('splat')]
const meta = args ? args[0] : null
......@@ -87,16 +86,18 @@ export class OptimismEnv {
return info
},
},
colorize({all: true}),
colorize({ all: true }),
timestamp({
format: 'YYYY-MM-DD hh:mm:ss.SSS A',
}),
align(),
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`),
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
),
transports: [new winston.transports.Stream({
stream: process.stderr,
})],
transports: [
new winston.transports.Stream({
stream: process.stderr,
}),
],
})
}
}
......
......@@ -7,4 +7,4 @@ chai.use(solidity)
chai.use(chaiAsPromised)
const expect = chai.expect
export { expect }
\ No newline at end of file
export { expect }
......@@ -8,4 +8,3 @@ export const defaultTransactionFactory = () => {
value: BigNumber.from(0),
}
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"declaration": true,
"resolveJsonModule": true
"outDir": "./dist"
},
"include": [
"src/**/*",
"./test",
"./artifacts/**/*.json",
"./tasks/**/*.ts",
......
ignores: [
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai"
]
......@@ -11,8 +11,8 @@
"scripts": {
"start": "ts-node ./src/service.ts",
"test:coverage": "echo 'No tests defined.'",
"build": "tsc -p ./tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"build": "tsc -p ./tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"pre-commit": "lint-staged",
"lint:fix": "yarn lint:check --fix",
......@@ -40,22 +40,8 @@
"@ethersproject/abstract-provider": "^5.6.1",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
"hardhat": "^2.9.6",
"lint-staged": "11.0.0",
"prettier": "^2.3.1",
"ts-node": "^10.0.0",
"typescript": "^4.6.2"
"ts-node": "^10.0.0"
}
}
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
\ No newline at end of file
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true
}
}
\ No newline at end of file
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
......@@ -11,8 +11,8 @@
"scripts": {
"start": "ts-node ./src/service",
"test:coverage": "echo 'No tests defined.'",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"clean": "rimraf ./dist ./tsconfig.tsbuildinfo",
"lint": "yarn run lint:fix && yarn run lint:check",
"pre-commit": "lint-staged",
"lint:fix": "yarn lint:check --fix",
......@@ -37,19 +37,6 @@
"@ethersproject/abstract-provider": "^5.6.1"
},
"devDependencies": {
"@types/node": "^15.12.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"lint-staged": "11.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.6.2"
"ts-node": "^10.0.0"
}
}
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
ignores: [
"@eth-optimism/core-utils",
"ts-mocha",
"typedoc",
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai",
"typedoc"
]
......@@ -9,8 +9,8 @@
],
"scripts": {
"all": "yarn clean && yarn build && yarn test && yarn lint:fix && yarn lint",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"lint:check": "eslint . --max-warnings=0",
"lint:fix": "yarn lint:check --fix",
......@@ -37,32 +37,13 @@
"@ethersproject/transactions": "^5.6.2",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.6.8",
"hardhat": "^2.9.6",
"lint-staged": "11.0.0",
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"prettier": "^2.3.1",
"ts-mocha": "^8.0.0",
"typedoc": "^0.22.13",
"typescript": "^4.6.2"
"mocha": "^10.0.0"
},
"dependencies": {
"@eth-optimism/contracts": "0.5.25",
......
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"sourceMap": true,
"esModuleInterop": true,
"composite": true,
"resolveJsonModule": true,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"dist"
]
}
{
"extends": "./tsconfig.build.json"
"compilerOptions": {
"module": "commonjs",
"target": "es2022",
"sourceMap": true,
"esModuleInterop": true,
"composite": true,
"resolveJsonModule": true,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"dist"
]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
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