Skip to content

Commit

Permalink
Merge branch 'master' into das-migrate-off-badgerdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-Wilson authored Jul 10, 2024
2 parents 920ce7b + de3dcff commit 232d9ad
Show file tree
Hide file tree
Showing 81 changed files with 1,672 additions and 693 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arbitrator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Setup nodejs
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup nodejs
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
run: |
packages=`go list ./...`
stdbuf -oL gotestsum --format short-verbose --packages="$packages" --rerun-fails=1 --no-color=false -- ./... -timeout 60m -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...,./go-ethereum/... -parallel=8 -tags=stylustest -run="TestProgramLong" > >(stdbuf -oL tee full.log | grep -vE "INFO|seal")
- name: Archive detailed run log
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Setup nodejs
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ jobs:
run: |
cd nitro-testnode
./test-node.bash --init --dev &
- name: Wait for rpc to come up
shell: bash
run: |
${{ github.workspace }}/.github/workflows/waitForNitro.sh
- name: Print WAVM module root
id: module-root
run: |
# Unfortunately, `docker cp` seems to always result in a "permission denied"
# We work around this by piping a tarball through stdout
docker run --rm --entrypoint tar localhost:5000/nitro-node-dev:latest -cf - target/machines/latest | tar xf -
module_root="$(cat "target/machines/latest/module-root.txt")"
echo "name=module-root=$module_root" >> $GITHUB_STATE
echo "module-root=$module_root" >> "$GITHUB_OUTPUT"
echo -e "\x1b[1;34mWAVM module root:\x1b[0m $module_root"
- name: Upload WAVM machine as artifact
Expand Down
40 changes: 31 additions & 9 deletions .github/workflows/merge-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@ on:
branches: [ master ]
types: [synchronize, opened, reopened, labeled, unlabeled]

permissions:
statuses: write

jobs:
design-approved-check:
if: ${{ !contains(github.event.*.labels.*.name, 'design-approved') }}
name: Design Approved Check
check-design-approved:
name: Check if Design Approved
runs-on: ubuntu-latest
steps:
- name: Check for design-approved label
- name: Check if design approved and update status
run: |
echo "Pull request is missing the 'design-approved' label"
echo "This workflow fails so that the pull request cannot be merged"
exit 1
set -x pipefail
status_state="pending"
if ${{ contains(github.event.*.labels.*.name, 'design-approved') }}; then
status_state="success"
else
resp="$(curl -sSL --fail-with-body \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/commits/${{ github.event.pull_request.head.sha }}/statuses")"
if ! jq -e '.[] | select(.context == "Design Approved Check")' > /dev/null <<< "$resp"; then
# Design not approved yet and no status exists
# Keep it without a status to keep the green checkmark appearing
# Otherwise, the commit and PR's CI will appear to be indefinitely pending
# Merging will still be blocked until the required status appears
exit 0
fi
fi
curl -sSL --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ github.event.pull_request.head.sha }}" \
-d '{"context":"Design Approved Check","state":"'"$status_state"'"}'
51 changes: 26 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:bookworm-slim as brotli-wasm-builder
FROM debian:bookworm-slim AS brotli-wasm-builder
WORKDIR /workspace
RUN apt-get update && \
apt-get install -y cmake make git lbzip2 python3 xz-utils && \
Expand All @@ -10,21 +10,21 @@ COPY scripts/build-brotli.sh scripts/
COPY brotli brotli
RUN cd emsdk && . ./emsdk_env.sh && cd .. && ./scripts/build-brotli.sh -w -t /workspace/install/

FROM scratch as brotli-wasm-export
FROM scratch AS brotli-wasm-export
COPY --from=brotli-wasm-builder /workspace/install/ /

FROM debian:bookworm-slim as brotli-library-builder
FROM debian:bookworm-slim AS brotli-library-builder
WORKDIR /workspace
COPY scripts/build-brotli.sh scripts/
COPY brotli brotli
RUN apt-get update && \
apt-get install -y cmake make gcc git && \
./scripts/build-brotli.sh -l -t /workspace/install/

FROM scratch as brotli-library-export
FROM scratch AS brotli-library-export
COPY --from=brotli-library-builder /workspace/install/ /

FROM node:16-bookworm-slim as contracts-builder
FROM node:18-bookworm-slim AS contracts-builder
RUN apt-get update && \
apt-get install -y git python3 make g++ curl
RUN curl -L https://foundry.paradigm.xyz | bash && . ~/.bashrc && ~/.foundry/bin/foundryup
Expand All @@ -35,11 +35,11 @@ COPY contracts contracts/
COPY Makefile .
RUN . ~/.bashrc && NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity

FROM debian:bookworm-20231218 as wasm-base
FROM debian:bookworm-20231218 AS wasm-base
WORKDIR /workspace
RUN apt-get update && apt-get install -y curl build-essential=12.9

FROM wasm-base as wasm-libs-builder
FROM wasm-base AS wasm-libs-builder
# clang / lld used by soft-float wasm
RUN apt-get update && \
apt-get install -y clang=1:14.0-55.7~deb12u1 lld=1:14.0-55.7~deb12u1 wabt
Expand All @@ -59,10 +59,10 @@ COPY --from=brotli-wasm-export / target/
RUN apt-get update && apt-get install -y cmake
RUN . ~/.cargo/env && NITRO_BUILD_IGNORE_TIMESTAMPS=1 RUSTFLAGS='-C symbol-mangling-version=v0' make build-wasm-libs

FROM scratch as wasm-libs-export
FROM scratch AS wasm-libs-export
COPY --from=wasm-libs-builder /workspace/ /

FROM wasm-base as wasm-bin-builder
FROM wasm-base AS wasm-bin-builder
# pinned go version
RUN curl -L https://golang.org/dl/go1.21.10.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf -
COPY ./Makefile ./go.mod ./go.sum ./
Expand Down Expand Up @@ -91,7 +91,7 @@ COPY --from=contracts-builder workspace/contracts/node_modules/@offchainlabs/upg
COPY --from=contracts-builder workspace/.make/ .make/
RUN PATH="$PATH:/usr/local/go/bin" NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-wasm-bin

FROM rust:1.75-slim-bookworm as prover-header-builder
FROM rust:1.75-slim-bookworm AS prover-header-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand All @@ -113,10 +113,10 @@ COPY brotli brotli
RUN apt-get update && apt-get install -y cmake
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-header

FROM scratch as prover-header-export
FROM scratch AS prover-header-export
COPY --from=prover-header-builder /workspace/target/ /

FROM rust:1.75-slim-bookworm as prover-builder
FROM rust:1.75-slim-bookworm AS prover-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand Down Expand Up @@ -156,10 +156,10 @@ RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-lib
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-bin
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-jit

FROM scratch as prover-export
FROM scratch AS prover-export
COPY --from=prover-builder /workspace/target/ /

FROM debian:bookworm-slim as module-root-calc
FROM debian:bookworm-slim AS module-root-calc
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand All @@ -181,7 +181,7 @@ COPY ./solgen ./solgen
COPY ./contracts ./contracts
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-replay-env

FROM debian:bookworm-slim as machine-versions
FROM debian:bookworm-slim AS machine-versions
RUN apt-get update && apt-get install -y unzip wget curl
WORKDIR /workspace/machines
# Download WAVM machines
Expand All @@ -206,7 +206,7 @@ COPY ./scripts/download-machine.sh .
#RUN ./download-machine.sh consensus-v20 0x8b104a2e80ac6165dc58b9048de12f301d70b02a0ab51396c22b4b4b802a16a4
RUN ./download-machine.sh consensus-v30 0xb0de9cb89e4d944ae6023a3b62276e54804c242fd8c4c2d8e6cc4450f5fa8b1b && true

FROM golang:1.21.10-bookworm as node-builder
FROM golang:1.21.10-bookworm AS node-builder
WORKDIR /workspace
ARG version=""
ARG datetime=""
Expand All @@ -233,17 +233,17 @@ RUN mkdir -p target/bin
COPY .nitro-tag.txt /nitro-tag.txt
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build

FROM node-builder as fuzz-builder
FROM node-builder AS fuzz-builder
RUN mkdir fuzzers/
RUN ./scripts/fuzz.bash --build --binary-path /workspace/fuzzers/

FROM debian:bookworm-slim as nitro-fuzzer
FROM debian:bookworm-slim AS nitro-fuzzer
COPY --from=fuzz-builder /workspace/fuzzers/*.fuzz /usr/local/bin/
COPY ./scripts/fuzz.bash /usr/local/bin
RUN mkdir /fuzzcache
ENTRYPOINT [ "/usr/local/bin/fuzz.bash", "FuzzStateTransition", "--binary-path", "/usr/local/bin/", "--fuzzcache-path", "/fuzzcache" ]

FROM debian:bookworm-slim as nitro-node-slim
FROM debian:bookworm-slim AS nitro-node-slim
WORKDIR /home/user
COPY --from=node-builder /workspace/target/bin/nitro /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/relay /usr/local/bin/
Expand All @@ -255,7 +255,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y \
ca-certificates \
wabt && \
wabt \
sysstat && \
/usr/sbin/update-ca-certificates && \
useradd -s /bin/bash user && \
mkdir -p /home/user/l1keystore && \
Expand All @@ -270,9 +271,9 @@ USER user
WORKDIR /home/user/
ENTRYPOINT [ "/usr/local/bin/nitro" ]

FROM offchainlabs/nitro-node:v2.3.4-rc.5-b4cc111 as nitro-legacy
FROM offchainlabs/nitro-node:v2.3.4-rc.5-b4cc111 AS nitro-legacy

FROM nitro-node-slim as nitro-node
FROM nitro-node-slim AS nitro-node
USER root
COPY --from=prover-export /bin/jit /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/daserver /usr/local/bin/
Expand All @@ -292,7 +293,7 @@ ENTRYPOINT [ "/usr/local/bin/nitro" , "--validation.wasm.allowed-wasm-module-roo

USER user

FROM nitro-node as nitro-node-validator
FROM nitro-node AS nitro-node-validator
USER root
COPY --from=nitro-legacy /usr/local/bin/nitro-val /home/user/nitro-legacy/bin/nitro-val
COPY --from=nitro-legacy /usr/local/bin/jit /home/user/nitro-legacy/bin/jit
Expand All @@ -304,7 +305,7 @@ COPY scripts/split-val-entry.sh /usr/local/bin
ENTRYPOINT [ "/usr/local/bin/split-val-entry.sh" ]
USER user

FROM nitro-node-validator as nitro-node-dev
FROM nitro-node-validator AS nitro-node-dev
USER root
# Copy in latest WASM module root
RUN rm -f /home/user/target/machines/latest
Expand All @@ -328,5 +329,5 @@ RUN export DEBIAN_FRONTEND=noninteractive && \

USER user

FROM nitro-node as nitro-node-default
FROM nitro-node AS nitro-node-default
# Just to ensure nitro-node-dist is default
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test-go-deps: \
build-replay-env \
$(stylus_test_wasms) \
$(arbitrator_stylus_lib) \
$(arbitrator_generated_header) \
$(patsubst %,$(arbitrator_cases)/%.wasm, global-state read-inboxmsg-10 global-state-wrapper const)

build-prover-header: $(arbitrator_generated_header)
Expand Down
5 changes: 4 additions & 1 deletion arbitrator/prover/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ impl<'a> WasmBinary<'a> {
cached_init = cached_init.saturating_add(data_len.saturating_mul(75244) / 100_000);
cached_init = cached_init.saturating_add(footprint as u64 * 5);

let mut init = cached_init;
let mut init: u64 = 0;
if compile.version == 1 {
init = cached_init; // in version 1 cached cost is part of init cost
}
init = init.saturating_add(funcs.saturating_mul(8252) / 1000);
init = init.saturating_add(type_len.saturating_mul(1059) / 1000);
init = init.saturating_add(wasm_len.saturating_mul(1286) / 10_000);
Expand Down
3 changes: 1 addition & 2 deletions arbitrator/prover/src/programs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ impl CompileConfig {

match version {
0 => {}
1 => {
// TODO: settle on reasonable values for the v1 release
1 | 2 => {
config.bounds.heap_bound = Pages(128); // 8 mb
config.bounds.max_frame_size = 10 * 1024;
config.bounds.max_frame_contention = 4096;
Expand Down
71 changes: 71 additions & 0 deletions arbitrator/stylus/tests/return-size.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
;; Copyright 2024, Offchain Labs, Inc.
;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

(module
(import "vm_hooks" "pay_for_memory_grow" (func (param i32)))
(import "vm_hooks" "read_args" (func $read_args (param i32)))
(import "vm_hooks" "write_result" (func $write_result (param i32 i32)))
(func (export "user_entrypoint") (param $args_len i32) (result i32)
(local $size i32)

;; read input
i32.const 0
call $read_args

;; read the target size from the last 4 bytes of the input big endian
;; byte 1
local.get $args_len
i32.const 1
i32.sub
local.tee $size
i32.load8_u

;; byte 2
local.get $size
i32.const 1
i32.sub
local.tee $size
i32.load8_u
i32.const 8
i32.shl
i32.or

;; byte 3
local.get $size
i32.const 1
i32.sub
local.tee $size
i32.load8_u
i32.const 16
i32.shl
i32.or

;; byte 4
local.get $size
i32.const 1
i32.sub
local.tee $size
i32.load8_u
i32.const 32
i32.shl
i32.or

local.tee $size

;; grow memory enough to handle the output
;; we start with one page allocated, so no need to round up
i32.const 65536
i32.div_u
memory.grow
drop

;; set return data
i32.const 0
local.get $size
call $write_result

;; return success
i32.const 0
)
(memory (export "memory") 1)
)
Loading

0 comments on commit 232d9ad

Please sign in to comment.