Commit 3f43f039 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: introduce mise (#13156)

Introduces mise for polyglot tool dependency management.
parent a2b1a7e1
...@@ -20,63 +20,54 @@ Interactions within this repository are subject to a [Code of Conduct](https://g ...@@ -20,63 +20,54 @@ Interactions within this repository are subject to a [Code of Conduct](https://g
## Development Quick Start ## Development Quick Start
### Software Dependencies ### Setting Up
| Dependency | Version | Version Check Command |
| ------------------------------------------------------------- | -------- | ------------------------ |
| [git](https://git-scm.com/) | `^2` | `git --version` |
| [go](https://go.dev/) | `^1.21` | `go version` |
| [node](https://nodejs.org/en/) | `^20` | `node --version` |
| [nvm](https://github.com/nvm-sh/nvm) | `^0.39` | `nvm --version` |
| [just](https://github.com/casey/just) | `^1.34.0`| `just --version` |
| [foundry](https://github.com/foundry-rs/foundry#installation) | `^0.2.0` | `forge --version` |
| [make](https://linux.die.net/man/1/make) | `^3` | `make --version` |
| [jq](https://github.com/jqlang/jq) | `^1.6` | `jq --version` |
| [direnv](https://direnv.net) | `^2` | `direnv --version` |
| [docker](https://docs.docker.com/get-docker/) | `^24` | `docker --version` |
| [docker compose](https://docs.docker.com/compose/install/) | `^2.23` | `docker compose version` |
### Notes on Specific Dependencies Clone the repository and open it:
#### `node` ```bash
git clone git@github.com:ethereum-optimism/optimism.git
cd optimism
```
Make sure to use the version of `node` specified within [`.nvmrc`](./.nvmrc). ### Software Dependencies
You can use [`nvm`](https://github.com/nvm-sh/nvm) to manage multiple versions of Node.js on your machine and automatically switch to the correct version when you enter this repository.
#### `foundry` You will need to install a number of software dependencies to effectively contribute to the
Optimism Monorepo. We use [`mise`](https://mise.jdx.dev/) as a dependency manager for these tools.
Once properly installed, `mise` will provide the correct versions for each tool. `mise` does not
replace any other installations of these binaries and will only serve these binaries when you are
working inside of the `optimism` directory.
`foundry` is updated frequently and occasionally contains breaking changes. #### Install `mise`
This repository pins a specific version of `foundry` inside of [`versions.json`](./versions.json).
Use the command `just update-foundry` at the root of the monorepo to make sure that your version of `foundry` is the same as the one currently being used in CI.
#### `direnv` Install `mise` by following the instructions provided on the
[Getting Started page](https://mise.jdx.dev/getting-started.html#_1-install-mise-cli).
[`direnv`](https://direnv.net) is a tool used to load environment variables from [`.envrc`](./.envrc) into your shell so you don't have to manually export variables every time you want to use them. #### Trust the `mise.toml` file
`direnv` only has access to files that you explicitly allow it to see.
After [installing `direnv`](https://direnv.net/docs/installation.html), you will need to **make sure that [`direnv` is hooked into your shell](https://direnv.net/docs/hook.html)**.
Make sure you've followed [the guide on the `direnv` website](https://direnv.net/docs/hook.html), then **close your terminal and reopen it** so that the changes take effect (or `source` your config file if you know how to do that).
#### `docker compose` `mise` requires that you explicitly trust the `mise.toml` file which lists the dependencies that
this repository uses. After you've installed `mise` you'll be able to trust the file via:
[Docker Desktop](https://docs.docker.com/get-docker/) should come with `docker compose` installed by default. ```bash
You'll have to install the `compose` plugin if you're not using Docker Desktop or you're on linux. mise trust mise.toml
```
### Setting Up #### Install dependencies
Clone the repository and open it: Use `mise` to install the correct versions for all of the required tools:
```bash ```bash
git clone git@github.com:ethereum-optimism/optimism.git mise install
cd optimism
``` ```
### Building the Monorepo #### Installing updates
Make sure that you've installed all of the required [Software Dependencies](#software-dependencies) before you continue. `mise` will notify you if any dependencies are outdated. Simply run `mise install` again to install
You will need [foundry](https://github.com/foundry-rs/foundry) to build the smart contracts found within this repository. the latest versions of the dependencies if you receive these notifications.
Refer to the note on [foundry as a dependency](#foundry) for instructions.
### Building the Monorepo
Install dependencies and build all packages within the monorepo by running: You must install all of the required [Software Dependencies](#software-dependencies) to build the
Optimism Monorepo. Once you've done so, run the following command to build:
```bash ```bash
make build make build
...@@ -88,7 +79,7 @@ Use the above command to rebuild the monorepo. ...@@ -88,7 +79,7 @@ Use the above command to rebuild the monorepo.
### Running tests ### Running tests
Before running tests: **follow the above instructions to get everything built.** Before running tests: **follow the above instructions to get everything built**.
#### Running unit tests (solidity) #### Running unit tests (solidity)
......
...@@ -13,91 +13,3 @@ semgrep-test: ...@@ -13,91 +13,3 @@ semgrep-test:
# Runs shellcheck. # Runs shellcheck.
shellcheck: shellcheck:
find . -type f -name '*.sh' -not -path '*/node_modules/*' -not -path './packages/contracts-bedrock/lib/*' -not -path './packages/contracts-bedrock/kout*/*' -exec sh -c 'echo "Checking $1"; shellcheck "$1"' _ {} \; find . -type f -name '*.sh' -not -path '*/node_modules/*' -not -path './packages/contracts-bedrock/lib/*' -not -path './packages/contracts-bedrock/kout*/*' -exec sh -c 'echo "Checking $1"; shellcheck "$1"' _ {} \;
########################################################
# DEPENDENCY MANAGEMENT #
########################################################
# Generic task for checking if a tool version is up to date.
check-tool-version tool:
#!/usr/bin/env bash
EXPECTED=$(jq -r .{{tool}} < versions.json)
ACTUAL=$(just print-{{tool}})
if [ "$ACTUAL" = "$EXPECTED" ]; then
echo "✓ {{tool}} versions match"
else
echo "✗ {{tool}} version mismatch (expected $EXPECTED, got $ACTUAL), run 'just install-{{tool}}' to upgrade"
exit 1
fi
# Installs foundry
install-foundry:
bash ./ops/scripts/install-foundry.sh
# Prints current foundry version.
print-foundry:
forge --version
# Checks if installed foundry version is correct.
check-foundry:
bash ./ops/scripts/check-foundry.sh
# Installs correct kontrol version.
install-kontrol:
bash ./ops/scripts/install-kontrol.sh
# Prints current kontrol version.
print-kontrol:
kontrol version
# Checks if installed kontrol version is correct.
check-kontrol:
just check-tool-version kontrol
# Installs correct abigen version.
install-abigen:
go install github.com/ethereum/go-ethereum/cmd/abigen@$(jq -r .abigen < versions.json)
# Prints current abigen version.
print-abigen:
abigen --version | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' -e 's/ /./g' -e 's/^/v/'
# Checks if installed abigen version is correct.
check-abigen:
just check-tool-version abigen
# Installs correct slither version.
install-slither:
pip3 install slither-analyzer==$(jq -r .slither < versions.json)
# Prints current slither version.
print-slither:
slither --version
# Checks if installed slither version is correct.
check-slither:
just check-tool-version slither
# Installs correct semgrep version.
install-semgrep:
pip3 install semgrep=="$(jq -r .semgrep < versions.json)"
# Prints current semgrep version.
print-semgrep:
semgrep --version | head -n 1
# Checks if installed semgrep version is correct.
check-semgrep:
just check-tool-version semgrep
# Installs correct go version.
install-go:
echo "error: go must be installed manually" && exit 1
# Prints current go version.
print-go:
go version | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/'
# Checks if installed go version is correct.
check-go:
just check-tool-version go
[tools]
# Core dependencies
go = "1.22.7"
rust = "1.83.0"
python = "3.12.0"
uv = "0.5.5"
jq = "1.7.1"
shellcheck = "0.10.0"
direnv = "2.35.0"
# Cargo dependencies
"cargo:just" = "1.37.0"
"cargo:svm-rs" = "0.5.8"
# Go dependencies
"go:github.com/ethereum/go-ethereum/cmd/abigen" = "1.10.25"
"go:github.com/ethereum/go-ethereum/cmd/geth" = "1.14.7"
"go:github.com/protolambda/eth2-testnet-genesis" = "0.10.0"
"go:gotest.tools/gotestsum" = "1.12.0"
"go:github.com/vektra/mockery/v2" = "2.46.0"
"go:github.com/golangci/golangci-lint/cmd/golangci-lint" = "1.61.0"
"go:github.com/mikefarah/yq/v4" = "4.44.3"
# Python dependencies
"pipx:slither-analyzer" = "0.10.2"
"pipx:semgrep" = "1.90.0"
# Foundry dependencies
# Foundry is a special case because it supplies multiple binaries at the same
# GitHub release, so we need to use the aliasing trick to get mise to not error
forge = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"
cast = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"
anvil = "nightly-143abd6a768eeb52a5785240b763d72a56987b4a"
# Fake dependencies
# Put things here if you need to track versions of tools or projects that can't
# actually be managed by mise (yet). Make sure that anything you put in here is
# also found inside of disabled_tools or mise will try to install it.
asterisc = "1.1.1"
kontrol = "1.0.53"
binary_signer = "1.0.4"
[alias]
forge = "ubi:foundry-rs/foundry[exe=forge]"
cast = "ubi:foundry-rs/foundry[exe=cast]"
anvil = "ubi:foundry-rs/foundry[exe=anvil]"
[settings]
experimental = true
pipx.uvx = true
disable_tools = ["asterisc", "kontrol", "binary_signer"]
# Copy docker buildx in order to generate the absolute prestate ###############################################################################
# in the CI pipeline for reproducible fault proof builds # BUILDX #
FROM --platform=linux/amd64 docker as buildx ###############################################################################
FROM --platform=linux/amd64 docker AS buildx
COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
RUN docker buildx version RUN docker buildx version
FROM --platform=linux/amd64 debian:bullseye-slim as rust-build
SHELL ["/bin/bash", "-c"]
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y build-essential git clang lld curl jq
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh && \
chmod +x ./rustup.sh && \
sh rustup.sh -y
# Install nightly toolchain
RUN source $HOME/.profile && rustup update nightly
RUN source $HOME/.profile && cargo install just
RUN source $HOME/.profile && cargo install svm-rs
# Only diff from upstream docker image is this clone instead ###############################################################################
# of COPY. We select a specific commit to use. # CI BUILDER (BASE) #
COPY ./versions.json ./versions.json ###############################################################################
COPY ./ops/scripts/install-foundry.sh ./install-foundry.sh
RUN curl -L https://foundry.paradigm.xyz | bash FROM --platform=linux/amd64 debian:bullseye-slim AS base-builder
RUN source $HOME/.profile && ./install-foundry.sh
RUN strip /root/.foundry/bin/forge && \ # Use bash as the shell
strip /root/.foundry/bin/cast && \ SHELL ["/bin/bash", "-c"]
strip /root/.foundry/bin/anvil && \ ENV SHELL=/bin/bash
strip /root/.cargo/bin/svm && \ ENV BASH=/bin/bash
strip /root/.cargo/bin/just
FROM --platform=linux/amd64 debian:bullseye-slim as go-build
RUN apt-get update && apt-get install -y curl ca-certificates jq binutils
ENV GO_VERSION=1.22.7
# Fetch go manually, rather than using a Go base image, so we can copy the installation into the final stage
RUN curl -sL https://go.dev/dl/go$GO_VERSION.linux-amd64.tar.gz -o go$GO_VERSION.linux-amd64.tar.gz && \
tar -C /usr/local/ -xzvf go$GO_VERSION.linux-amd64.tar.gz
ENV GOPATH=/go
ENV PATH=/usr/local/go/bin:$GOPATH/bin:$PATH
# Install the specific version of abigen and geth from version control
COPY ./versions.json ./versions.json
RUN go install github.com/ethereum/go-ethereum/cmd/abigen@$(jq -r .abigen < versions.json)
RUN go install github.com/ethereum/go-ethereum/cmd/geth@$(jq -r .geth < versions.json)
RUN go install gotest.tools/gotestsum@v1.12.0
RUN go install github.com/vektra/mockery/v2@v2.46.0
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
RUN go install github.com/mikefarah/yq/v4@v4.44.3
# Strip binaries to reduce size # Copy mise configuration
RUN strip /go/bin/gotestsum && \ COPY ./mise.toml ./mise.toml
strip /go/bin/mockery && \
strip /go/bin/golangci-lint && \
strip /go/bin/abigen && \
strip /go/bin/geth && \
strip /go/bin/yq
FROM --platform=linux/amd64 debian:bullseye-slim as base-builder # Set up mise environment
ENV PATH="/root/.local/share/mise/shims:$PATH"
ENV PATH="/root/.local/bin:${PATH}"
ENV GOPATH=/go # Install dependencies
ENV PATH=/usr/local/go/bin:$GOPATH/bin:$PATH # We do this in one mega RUN command to avoid blowing up the size of the image
ENV PATH=/root/.cargo/bin:$PATH
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# copy the go installation, but not the module cache (cache will get stale, and would add a lot of weight)
COPY --from=go-build /usr/local/go /usr/local/go
# copy tools
COPY --from=go-build /go/bin/gotestsum /go/bin/gotestsum
COPY --from=go-build /go/bin/mockery /go/bin/mockery
COPY --from=go-build /go/bin/golangci-lint /go/bin/golangci-lint
COPY --from=go-build /go/bin/abigen /usr/local/bin/abigen
COPY --from=go-build /go/bin/geth /usr/local/bin/geth
COPY --from=go-build /go/bin/yq /go/bin/yq
# copy tools
COPY --from=rust-build /root/.foundry/bin/forge /usr/local/bin/forge
COPY --from=rust-build /root/.foundry/bin/cast /usr/local/bin/cast
COPY --from=rust-build /root/.foundry/bin/anvil /usr/local/bin/anvil
COPY --from=rust-build /root/.cargo/bin/svm /usr/local/bin/svm
COPY --from=rust-build /root/.cargo/bin/just /usr/local/bin/just
COPY ./versions.json ./versions.json
RUN /bin/sh -c set -eux; \ RUN /bin/sh -c set -eux; \
apt-get update; \ apt-get update; \
apt-get install -y --no-install-recommends bash curl openssh-client git build-essential ca-certificates jq gnupg binutils-mips-linux-gnu python3 python3-pip python3-setuptools; \ apt-get install -y --no-install-recommends bash curl openssh-client git build-essential ca-certificates gnupg binutils-mips-linux-gnu clang libffi-dev; \
mkdir -p /etc/apt/keyrings; \ mkdir -p /etc/apt/keyrings; \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg; \ curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg; \
chmod a+r /etc/apt/keyrings/docker.gpg; \ chmod a+r /etc/apt/keyrings/docker.gpg; \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null; \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null; \
apt-get update; \ apt-get update; \
apt-get install -y docker-ce-cli; \ apt-get install -y docker-ce-cli; \
ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt; \ curl https://mise.run | sh; \
pip install capstone pyelftools; \ mise trust ./mise.toml; \
pip install semgrep==$(jq -r .semgrep < versions.json); \ mise install; \
curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | bash; \ curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | bash; \
pip install capstone pyelftools; \
go env -w GOMODCACHE=/go/pkg/mod; \
go env -w GOCACHE=/root/.cache/go-build; \
ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
go clean -cache -modcache -testcache; \
rm -rf /var/lib/apt/lists/*; \ rm -rf /var/lib/apt/lists/*; \
rm -rf /root/.cache/pip; rm -rf /root/.cache/pip; \
rm -rf /root/.cache/uv; \
rm -rf /root/.rustup;
RUN svm install 0.8.25 && \ # Install Solidity versions
svm install 0.8.15 && \ RUN echo "installing Solidity versions" && \
svm install 0.8.19 svm install 0.8.25 && \
svm install 0.8.19 && \
svm install 0.8.15
# Install Codecov uploader
RUN echo "downloading and verifying Codecov uploader" && \ RUN echo "downloading and verifying Codecov uploader" && \
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import && \ curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import && \
curl -Os "https://uploader.codecov.io/latest/linux/codecov" && \ curl -Os "https://uploader.codecov.io/latest/linux/codecov" && \
...@@ -129,24 +73,18 @@ RUN echo "downloading and verifying Codecov uploader" && \ ...@@ -129,24 +73,18 @@ RUN echo "downloading and verifying Codecov uploader" && \
# Copy docker buildx # Copy docker buildx
COPY --from=buildx /usr/libexec/docker/cli-plugins/docker-buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --from=buildx /usr/libexec/docker/cli-plugins/docker-buildx /usr/libexec/docker/cli-plugins/docker-buildx
# within docker use bash # Set up entrypoint
SHELL ["/bin/bash", "-c"] ENTRYPOINT ["/bin/bash", "-c"]
# set env to use bash
ENV SHELL=/bin/bash
ENV BASH=/bin/bash
ENTRYPOINT ["/bin/bash", "-c"] ###############################################################################
# CI BUILDER (RUST) #
###############################################################################
FROM base-builder as rust-builder FROM base-builder as rust-builder
# Install clang & lld # Install clang & lld
RUN apt-get update && apt-get install -y clang lld RUN apt-get update && apt-get install -y clang lld
# Copy the rust installation, alongside the installed toolchains # Install nightly toolchain
COPY --from=rust-build /root/.cargo /root/.cargo RUN rustup update nightly
COPY --from=rust-build /root/.rustup /root/.rustup
# copy the rust installation, alongside the installed toolchains
COPY --from=rust-build /root/.cargo/bin /root/.cargo/bin
COPY --from=rust-build /root/.rustup /root/.rustup
* *
!/.nvmrc !/.nvmrc
!/versions.json !/mise.toml
!/ops/scripts/install-foundry.sh
#!/usr/bin/env bash
VERSIONS_FILE="versions.json"
if ! command -v jq &> /dev/null
then
# shellcheck disable=SC2006
echo "Please install jq" >&2
exit 1
fi
if ! command -v forge &> /dev/null
then
# shellcheck disable=SC2006
echo "Is Foundry not installed? Consider installing via just install-foundry" >&2
exit 1
fi
# Check VERSIONS_FILE has expected foundry property
if ! jq -e '.foundry' "$VERSIONS_FILE" &> /dev/null; then
echo "'foundry' is missing from $VERSIONS_FILE" >&2
exit 1
fi
# Extract the expected foundry version from versions.json
EXPECTED_VERSION=$(jq -r '.foundry' "$VERSIONS_FILE" | cut -c 1-7)
if [ -z "$EXPECTED_VERSION" ]; then
echo "Unable to extract Foundry version from $VERSIONS_FILE" >&2
exit 1
fi
# Extract the installed forge version
INSTALLED_VERSION=$(forge --version | grep -o '[a-f0-9]\{7\}' | head -n 1)
# Compare the installed timestamp with the expected timestamp
if [ "$INSTALLED_VERSION" = "$EXPECTED_VERSION" ]; then
echo "Foundry version matches the expected version."
else
echo "Mismatch between installed Foundry version ($INSTALLED_VERSION) and expected version ($EXPECTED_VERSION)."
echo "Your version of Foundry may either not be up to date, or it could be a later version."
echo "Running 'just update-foundry' from the repository root will install the expected version."
fi
#!/bin/bash
SCRIPTS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MONOREPO_DIR=$(cd "$SCRIPTS_DIR/../../" && pwd)
# Extract the version from the geth command output
GETH_VERSION="v$(geth version | grep '^Version:' | awk '{print $2}')"
# Read the version from the versions file
EXPECTED_GETH_VERSION=$(jq -r .geth < "$MONOREPO_DIR"/versions.json)
# Check if EXPECTED_GETH_VERSION contains a '-'. If not, append '-stable'.
if [[ $EXPECTED_GETH_VERSION != *-* ]]; then
EXPECTED_GETH_VERSION="${EXPECTED_GETH_VERSION}-stable"
fi
# Compare the versions
if [[ "$GETH_VERSION" == "$EXPECTED_GETH_VERSION" ]]; then
echo "Geth version $GETH_VERSION is correct!"
exit 0
else
echo "Geth version does not match!"
echo "Local geth version: $GETH_VERSION"
echo "Expected geth version: $EXPECTED_GETH_VERSION"
exit 1
fi
#!/bin/bash
set -e
# Check if foundryup exists, if not, install it
if ! command -v foundryup &> /dev/null; then
echo "foundryup not found, installing..."
curl -L https://foundry.paradigm.xyz | bash
fi
SCRIPTS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MONOREPO_DIR=$(cd "$SCRIPTS_DIR/../../" && pwd)
# Grab the foundry commit hash.
SHA=$(jq -r .foundry < "$MONOREPO_DIR"/versions.json)
# Check if there is a nightly tag corresponding to the commit hash
TAG="nightly-$SHA"
# If the foundry repository exists and a branch is checked out, we need to abort
# any changes inside ~/.foundry/foundry-rs/foundry. This is because foundryup will
# attempt to pull the latest changes from the remote repository, which will fail
# if there are any uncommitted changes.
if [ -d ~/.foundry/foundry-rs/foundry ]; then
echo "Foundry repository exists! Aborting any changes..."
cd ~/.foundry/foundry-rs/foundry
git reset --hard
git clean -fd
cd -
fi
# Create a temporary directory
TMP_DIR=$(mktemp -d)
echo "Created tempdir @ $TMP_DIR"
# Clone the foundry repo temporarily. We do this to avoid the need for a personal access
# token to interact with the GitHub REST API, and clean it up after we're done.
git clone https://github.com/foundry-rs/foundry.git "$TMP_DIR" && cd "$TMP_DIR"
# If the nightly tag exists, we can download the pre-built binaries rather than building
# from source. Otherwise, clone the repository, check out the commit SHA, and build `forge`,
# `cast`, `anvil`, and `chisel` from source.
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Nightly tag exists! Downloading prebuilt binaries..."
foundryup -v "$TAG"
else
echo "Nightly tag doesn't exist! Building from source..."
git checkout "$SHA"
# Use native `cargo` build to avoid any rustc environment variables `foundryup` sets. We explicitly
# ignore chisel, as it is not a part of `ci-builder`.
cargo build --bin forge --release
cargo build --bin cast --release
cargo build --bin anvil --release
mkdir -p ~/.foundry/bin
mv target/release/forge ~/.foundry/bin
mv target/release/cast ~/.foundry/bin
mv target/release/anvil ~/.foundry/bin
fi
# Remove the temporary foundry repo; Used just for checking the nightly tag's existence.
rm -rf "$TMP_DIR"
echo "Removed tempdir @ $TMP_DIR"
#!/bin/bash
set -e
# Check if kup exists, if not, install it
if ! command -v kup &> /dev/null; then
echo "kup not found, installing..."
yes | bash <(curl -L https://kframework.org/install)
fi
SCRIPTS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MONOREPO_DIR=$(cd "$SCRIPTS_DIR/../../" && pwd)
# Grab the correct kontrol version.
VERSION=$(jq -r .kontrol < "$MONOREPO_DIR"/versions.json)
kup install kontrol --version v"$VERSION"
...@@ -66,7 +66,7 @@ See the [Optimism Developer Docs](https://docs.optimism.io/chain/addresses) for ...@@ -66,7 +66,7 @@ See the [Optimism Developer Docs](https://docs.optimism.io/chain/addresses) for
### Contributing Guide ### Contributing Guide
Contributions to the OP Stack are always welcome. Contributions to the OP Stack are always welcome.
Please refer to the [CONTRIBUTING.md](./meta/CONTRIBUTING.md) for more information about how to contribute to the OP Stack smart contracts. Please refer to the [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information about how to contribute to the OP Stack smart contracts.
### Style Guide ### Style Guide
......
...@@ -15,24 +15,12 @@ dep-status: ...@@ -15,24 +15,12 @@ dep-status:
# BUILD # # BUILD #
######################################################## ########################################################
# Checks that the correct version of Foundry is installed.
check-foundry:
cd ../../ && ./ops/scripts/check-foundry.sh
# Checks that semgrep is installed.
check-semgrep:
cd ../../ && just check-semgrep
# Checks that the correct versions of Foundry and semgrep are installed.
check-dependencies:
just check-foundry && just check-semgrep
# Core forge build command # Core forge build command
forge-build: forge-build:
forge build forge build
# Builds the contracts. # Builds the contracts.
build: check-dependencies lint-fix-no-fail forge-build interfaces-check-no-build build: lint-fix-no-fail forge-build interfaces-check-no-build
# Builds the go-ffi tool for contract tests. # Builds the go-ffi tool for contract tests.
build-go-ffi-default: build-go-ffi-default:
......
# Contributing to CONTRIBUTING.md
First off, thanks for taking the time to contribute!
We welcome and appreciate all kinds of contributions. We ask that before contributing you please review the procedures for each type of contribution available in the [Table of Contents](#table-of-contents). This will streamline the process for both maintainers and contributors. To find ways to contribute, view the [I Want To Contribute](#i-want-to-contribute) section below. Larger contributions should [open an issue](https://github.com/ethereum-optimism/optimism/issues/new) before implementation to ensure changes don't go to waste.
We're excited to work with you and your contributions to scaling Ethereum!
## Table of Contents
- [I Have a Question](#i-have-a-question)
- [I Want To Contribute](#i-want-to-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Your First Code Contribution](#your-first-code-contribution)
- [Improving The Documentation](#improving-the-documentation)
- [Deploying on Devnet](#deploying-on-devnet)
- [Tools](#tools)
## I Have a Question
> **Note**
> Before making an issue, please read the documentation and search the issues to see if your question has already been answered.
If you have any questions about the smart contracts, please feel free to ask them in the Optimism discord developer channels or create a new detailed issue.
## I Want To Contribute
### Reporting Bugs
**Any and all bug reports on production smart contract code should be submitted privately to the Optimism team so that we can mitigate the issue before it is exploited. Please see our security policy document [here](https://github.com/ethereum-optimism/.github/blob/master/SECURITY.md).**
### Suggesting Enhancements
#### Before Submitting an Enhancement
- Read the documentation and the smart contracts themselves to see if the feature already exists.
- Perform a search in the issues to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
#### How Do I Submit a Good Enhancement Suggestion?
Enhancement suggestions are tracked as [GitHub issues](https://github.com/ethereum-optimism/optimism/issues).
- Use a **clear and descriptive title** for the issue to identify the suggestion.
- Provide a **step-by-step** description of the suggested enhancement in as many details as possible.
- Describe the **current** behavior and why the **intended** behavior you expected to see differs. At this point you can also tell which alternatives do not work for you.
- Explain why this enhancement would be useful in Optimism's smart contracts. You may also want to point out the other projects that solved it better and which could serve as inspiration.
### Your First Code Contribution
The best place to begin contributing is by looking through the issues with the `good first issue` label. These are issues that are relatively easy to implement and are a great way to get familiar with the codebase.
Optimism's smart contracts are written in Solidity and we use [foundry](https://github.com/foundry-rs/foundry) as our development framework. To get started, you'll need to install several dependencies:
1. [just](https://github.com/casey/just)
Make sure to `just install`
1. [foundry](https://getfoundry.sh)
Foundry is built with [rust](https://www.rust-lang.org/tools/install), and this project uses a pinned version of foundry. Install the rust toolchain with `rustup`.
Make sure to install the version of foundry used by `ci-builder`, defined in the `versions.json` file in the root of this repo under the `foundry` key. Once you have `foundryup` installed, there is a helper to do this: `just install-foundry`
1. [golang](https://golang.org/doc/install)
1. [python](https://www.python.org/downloads/)
Our [Style Guide](STYLE_GUIDE.md) contains information about the project structure, syntax preferences, naming conventions, and more. Please take a look at it before submitting a PR, and let us know if you spot inconsistencies!
Once you've read the style guide and are ready to work on your PR, there are a plethora of useful `just` scripts to know about that will help you with development.
You can run `just -l` to list them all, some of the key ones are:
1. `just build` Builds the smart contracts.
1. `just test` Runs the full `forge` test suite.
1. `just gas-snapshot` Generates the gas snapshot for the smart contracts.
1. `just semver-lock` Generates the semver lockfile.
1. `just snapshots` Generates the storage and ABI snapshots.
1. `just clean` Removes all build artifacts for `forge` and `go` compilations.
1. `just validate-spacers` Validates the positions of the storage slot spacers.
1. `just validate-deploy-configs` Validates the deployment configurations in `deploy-config`
1. `just lint` Runs the linter on the smart contracts and scripts.
1. `just pre-pr` Runs most checks, generators, and linters prior to a PR. For most PRs, this is sufficient to pass CI if everything is in order.
1. `just pre-pr-full` Runs all checks, generators, and linters prior to a PR.
### Improving The Documentation
Documentation improvements are more than welcome! If you see a typo or feel that a code comment describes something poorly or incorrectly, please submit a PR with a fix.
### Deploying on Devnet
To deploy the smart contracts on a local devnet, run `make devnet-up` in the monorepo root. For more information on the local devnet, see [dev-node](https://docs.optimism.io/chain/testing/dev-node).
### Tools
#### Validate Spacing
In order to make sure that we don't accidentally overwrite storage slots, contract storage layouts are checked to make sure spacing is correct.
This uses the `snapshots/storageLayout` directory to check contract spacing. Run `just validate-spacers` to check the spacing of all contracts.
#### Gas Snapshots
We use forge's `gas-snapshot` subcommand to produce a gas snapshot for tests in `Benchmark.t.sol`. CI will check that the gas snapshot has been updated properly when it runs, so make sure to run `just gas-snapshot`!
#### Semver Locking
Many of our smart contracts are semantically versioned. To make sure that changes are not made to a contract without deliberately bumping its version, we commit to the source code and the creation bytecode of its dependencies in a lockfile. Consult the [Style Guide](./STYLE_GUIDE.md#Versioning) for more information about how our contracts are versioned.
#### Storage Snapshots
Due to the many proxied contracts in Optimism's protocol, we automate tracking the diff to storage layouts of the contracts in the project. This is to ensure that we don't break a proxy by upgrading its implementation to a contract with a different storage layout. To generate the storage lockfile, run `just snapshots`.
...@@ -48,10 +48,9 @@ The directory is structured as follows ...@@ -48,10 +48,9 @@ The directory is structured as follows
### Installation ### Installation
1. `cd` to the root of this repo. 1. Make sure that the dependencies for the Optimism Monorepo are installed with `mise`.
2. Install Foundry by running `just install-foundry`. This installs `foundryup`, the foundry toolchain installer, then installs the required foundry version. 1. Install [`kup`](https://github.com/runtimeverification/k/releases/tag/v7.1.180).
3. Install Kontrol by running `just install-kontrol`. This installs `kup`, the package manager for RV tools, then installs the required kontrol version. 1. Use `kup` to [install `kontrol`](https://github.com/runtimeverification/kontrol?tab=readme-ov-file#fast-installation)
4. Install Docker.
## Usage ## Usage
......
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