Skip to content

Commit f17eaca

Browse files
authored
Use Espresso Network Go (#586)
* initial commit * Use espresso network go library directly * lint * fix dockerfile * fix dockerfile * debug and free up space in the runner * fix ci * use tar file instead of git submodules * remove espresso network go from dockerfile * fix dockerfile * dockerfile update * fix makefile * fix tests * fix arch * fix triple code * address comments and fix dockerfile * fix dockerfile again * fix dockerfile again-1 * add makefile as well in docker build * make path relative * use workspace * fix makefile * revert to using curl * lint * add curl
1 parent 6d6746e commit f17eaca

29 files changed

+125
-13568
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ concurrency:
1717
cancel-in-progress: true
1818

1919
jobs:
20+
free-disk-space:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Free Disk Space (Ubuntu)
24+
uses: jlumbroso/free-disk-space@main
25+
with:
26+
tool-cache: true
2027
test:
28+
needs: free-disk-space
2129
name: Go Tests
2230
runs-on: ubuntu-latest
2331

.github/workflows/create-asana-attachment.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/docker.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ on:
1111
- develop
1212

1313
jobs:
14+
free-disk-space:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Free Disk Space (Ubuntu)
18+
uses: jlumbroso/free-disk-space@main
19+
with:
20+
tool-cache: true
1421
docker:
22+
needs: free-disk-space
1523
name: Docker build
1624
runs-on: ubuntu-latest
1725
services:

.github/workflows/espresso-docker.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ concurrency:
2727
cancel-in-progress: true
2828

2929
jobs:
30+
free-disk-space:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Free Disk Space (Ubuntu)
34+
uses: jlumbroso/free-disk-space@main
35+
with:
36+
tool-cache: true
3037
docker_build:
38+
needs: free-disk-space
3139
strategy:
3240
matrix:
3341
platform: [linux/amd64, linux/arm64]

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ system_tests/test-data/*
2424
system_tests/testdata/*
2525
arbos/testdata/*
2626

27-
/.pre-commit-config.yaml
27+
/.pre-commit-config.yaml
28+
espresso-network-go
29+
*.tar.gz

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
path = bold
4141
url = https://github.com/EspressoSystems/bold.git
4242
branch = integration
43+

Dockerfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ COPY arbitrator/prover arbitrator/prover
5656
COPY arbitrator/wasm-libraries arbitrator/wasm-libraries
5757
COPY arbitrator/tools/wasmer arbitrator/tools/wasmer
5858
COPY brotli brotli
59+
ARG ESPRESSO_NETWORK_GO_VER=0.0.36
60+
ADD https://github.com/EspressoSystems/espresso-network-go/archive/refs/tags/v$ESPRESSO_NETWORK_GO_VER.tar.gz .
61+
RUN tar -xzf v${ESPRESSO_NETWORK_GO_VER}.tar.gz && \
62+
mv espresso-network-go-${ESPRESSO_NETWORK_GO_VER} espresso-network-go
5963
COPY scripts/build-brotli.sh scripts/
6064
COPY scripts/remove_reference_types.sh scripts/
6165
COPY --from=brotli-wasm-export / target/
@@ -90,6 +94,10 @@ COPY ./safe-smart-account ./safe-smart-account
9094
COPY ./solgen/gen.go ./solgen/
9195
COPY ./fastcache ./fastcache
9296
COPY ./go-ethereum ./go-ethereum
97+
ARG ESPRESSO_NETWORK_GO_VER=0.0.36
98+
ADD https://github.com/EspressoSystems/espresso-network-go/archive/refs/tags/v$ESPRESSO_NETWORK_GO_VER.tar.gz .
99+
RUN tar -xzf v${ESPRESSO_NETWORK_GO_VER}.tar.gz && \
100+
mv espresso-network-go-${ESPRESSO_NETWORK_GO_VER} espresso-network-go
93101
COPY scripts/remove_reference_types.sh scripts/
94102
COPY --from=brotli-wasm-export / target/
95103
COPY --from=contracts-builder workspace/contracts/build/contracts/src/precompiles/ contracts/build/contracts/src/precompiles/
@@ -114,7 +122,6 @@ COPY arbitrator/wasm-libraries arbitrator/wasm-libraries
114122
COPY arbitrator/jit arbitrator/jit
115123
COPY arbitrator/stylus arbitrator/stylus
116124
COPY arbitrator/tools/wasmer arbitrator/tools/wasmer
117-
COPY espressocrypto espressocrypto
118125
COPY --from=brotli-wasm-export / target/
119126
COPY scripts/build-brotli.sh scripts/
120127
COPY brotli brotli
@@ -125,9 +132,11 @@ RUN apt-get update && \
125132
apt-get install -y \
126133
libssl-dev \
127134
pkg-config \
135+
curl \
128136
perl \
129137
perl-modules-5.36 \
130138
libfindbin-libs-perl
139+
131140
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-espresso-crypto-lib
132141

133142
FROM scratch AS prover-header-export
@@ -255,6 +264,10 @@ COPY go.mod go.sum ./
255264
COPY go-ethereum/go.mod go-ethereum/go.sum go-ethereum/
256265
COPY fastcache/go.mod fastcache/go.sum fastcache/
257266
COPY bold/go.mod bold/go.sum bold/
267+
ARG ESPRESSO_NETWORK_GO_VER=0.0.36
268+
ADD https://github.com/EspressoSystems/espresso-network-go/archive/refs/tags/v$ESPRESSO_NETWORK_GO_VER.tar.gz .
269+
RUN tar -xzf v${ESPRESSO_NETWORK_GO_VER}.tar.gz && \
270+
mv espresso-network-go-${ESPRESSO_NETWORK_GO_VER} espresso-network-go
258271
RUN go mod download
259272
COPY . ./
260273
COPY --from=contracts-builder workspace/contracts/build/ contracts/build/
@@ -281,7 +294,7 @@ ENTRYPOINT [ "/usr/local/bin/fuzz.bash", "FuzzStateTransition", "--binary-path",
281294

282295
FROM debian:bookworm-slim AS nitro-node-slim
283296
WORKDIR /home/user
284-
COPY --from=node-builder /workspace/target/lib/libespresso_crypto_helper.so /usr/local/lib/
297+
COPY --from=node-builder /workspace/target/lib/libespresso_crypto_helper-*.so /usr/local/lib/
285298
RUN ldconfig
286299
COPY --from=node-builder /workspace/target/bin/nitro /usr/local/bin/
287300
COPY --from=node-builder /workspace/target/bin/relay /usr/local/bin/

Makefile

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ ifneq ($(origin GOLANG_LDFLAGS),undefined)
3232
endif
3333

3434
UNAME_S := $(shell uname -s)
35+
UNAME_M := $(shell uname -m)
36+
3537

3638
# In Mac OSX, there are a lot of warnings emitted if these environment variables aren't set.
3739
ifeq ($(UNAME_S), Darwin)
3840
export MACOSX_DEPLOYMENT_TARGET := $(shell sw_vers -productVersion)
3941
export CGO_LDFLAGS := -Wl,-no_warn_duplicate_libraries
4042
endif
4143

44+
4245
precompile_names = AddressTable Aggregator BLS Debug FunctionTable GasInfo Info osTest Owner RetryableTx Statistics Sys
4346
precompiles = $(patsubst %,./solgen/generated/%.go, $(precompile_names))
4447

4548
output_root=target
4649
output_latest=$(output_root)/machines/latest
4750

48-
repo_dirs = arbos arbcompress arbnode arbutil arbstate cmd das espressocrypto precompiles solgen system_tests util validator wavmio
51+
repo_dirs = arbos arbcompress arbnode arbutil arbstate cmd das precompiles solgen system_tests util validator wavmio
4952
go_source.go = $(wildcard $(patsubst %,%/*.go, $(repo_dirs)) $(patsubst %,%/*/*.go, $(repo_dirs)))
5053
go_source.s = $(wildcard $(patsubst %,%/*.s, $(repo_dirs)) $(patsubst %,%/*/*.s, $(repo_dirs)))
5154
go_source = $(go_source.go) $(go_source.s)
@@ -154,27 +157,76 @@ stylus_test_hostio-test_src = $(call get_stylus_test_rust,hostio-test)
154157

155158
stylus_test_wasms = $(stylus_test_keccak_wasm) $(stylus_test_keccak-100_wasm) $(stylus_test_fallible_wasm) $(stylus_test_storage_wasm) $(stylus_test_multicall_wasm) $(stylus_test_log_wasm) $(stylus_test_create_wasm) $(stylus_test_math_wasm) $(stylus_test_sdk-storage_wasm) $(stylus_test_erc20_wasm) $(stylus_test_read-return-data_wasm) $(stylus_test_evm-data_wasm) $(stylus_test_hostio-test_wasm) $(stylus_test_bfs:.b=.wasm)
156159
stylus_benchmarks = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(stylus_test_wasms)
160+
CBROTLI_WASM_BUILD_ARGS ?=-d
161+
162+
163+
ESPRESSO_NETWORK_GO_VER ?= 0.0.36
164+
ESPRESSO_TAR = espresso-network-go-$(ESPRESSO_NETWORK_GO_VER).tar.gz
165+
ESPRESSO_URL = https://github.com/EspressoSystems/espresso-network-go/archive/refs/tags/v$(ESPRESSO_NETWORK_GO_VER).tar.gz
166+
ESPRESSO_DIR = espresso-network-go
157167

158-
espresso_crypto_dir = ./espressocrypto/lib/espresso-crypto-helper
168+
# Download the tarball
169+
$(ESPRESSO_TAR):
170+
curl -L -o $@ $(ESPRESSO_URL)
171+
172+
# Extract into target directory (strip the top-level folder)
173+
$(ESPRESSO_DIR): $(ESPRESSO_TAR)
174+
@echo "Extracting $(ESPRESSO_TAR) into $(ESPRESSO_DIR)/..."
175+
rm -rf $(ESPRESSO_DIR)
176+
mkdir -p $(ESPRESSO_DIR)
177+
tar -xzf $(ESPRESSO_TAR) --strip-components=1 -C $(ESPRESSO_DIR)
178+
179+
espresso_crypto_dir = $(ESPRESSO_DIR)/verification/rust
159180
espresso_crypto_files = $(wildcard $(espresso_crypto_dir)/*.toml $(espresso_crypto_dir)/src/*.rs)
160181
espresso_crypto_lib = $(output_root)/lib/libespresso_crypto_helper
161182
espresso_crypto_filename = libespresso_crypto_helper.so
162-
ifeq ($(UNAME_S), Darwin)
183+
espresso_target_lib = $(ESPRESSO_DIR)/target/lib
184+
185+
186+
# Normalize architecture names
187+
ifeq ($(UNAME_M),arm64)
188+
# Apple Silicon reports as arm64, but Rust uses aarch64
189+
DETECTED_ARCH := aarch64
190+
else
191+
DETECTED_ARCH := $(UNAME_M)
192+
endif
193+
194+
# Determine target triple
195+
ifeq ($(DETECTED_ARCH),aarch64)
196+
ifeq ($(UNAME_S),Darwin)
197+
TRIPLE := aarch64-apple-darwin
198+
else
199+
TRIPLE := aarch64-unknown-linux-gnu
200+
endif
201+
else ifeq ($(DETECTED_ARCH),x86_64)
202+
ifeq ($(UNAME_S),Darwin)
203+
TRIPLE := x86_64-apple-darwin
204+
else
205+
TRIPLE := x86_64-unknown-linux-gnu
206+
endif
207+
else
208+
$(error Architecture $(DETECTED_ARCH) is not supported)
209+
endif
210+
211+
# Set library extension based on OS
212+
ifeq ($(UNAME_S),Darwin)
213+
LIB_EXT := dylib
163214
espresso_crypto_filename = libespresso_crypto_helper.dylib
164215
else
216+
LIB_EXT := so
165217
export LD_LIBRARY_PATH := $(shell pwd)/target/lib:$LD_LIBRARY_PATH
166218
endif
167219

168-
CBROTLI_WASM_BUILD_ARGS ?=-d
169220

170221
# user targets
171222
.PHONY: build-espresso-crypto-lib
172-
build-espresso-crypto-lib: $(espresso_crypto_lib)
173-
174-
$(espresso_crypto_lib): $(DEP_PREDICATE) $(espresso_crypto_files)
223+
build-espresso-crypto-lib: $(ESPRESSO_DIR)
175224
mkdir -p `dirname $(espresso_crypto_lib)`
176225
cargo build --release --manifest-path $(espresso_crypto_dir)/Cargo.toml
177-
install $(espresso_crypto_dir)/target/release/$(espresso_crypto_filename) $(output_root)/lib/$(espresso_crypto_filename)
226+
mkdir -p $(espresso_target_lib)
227+
install $(espresso_crypto_dir)/target/release/libespresso_crypto_helper.$(LIB_EXT) \
228+
$(espresso_target_lib)/libespresso_crypto_helper-$(TRIPLE).$(LIB_EXT)
229+
install $(espresso_crypto_dir)/target/release/$(espresso_crypto_filename) $(output_root)/lib/libespresso_crypto_helper-$(TRIPLE).$(LIB_EXT)
178230

179231
.PHONY: push
180232
push: lint test-go .make/fmt
@@ -308,8 +360,9 @@ clean:
308360
@rm -rf contracts/build contracts/cache solgen/go/
309361
@rm -f .make/*
310362
rm -rf brotli/buildfiles
311-
cargo clean --manifest-path $(espresso_crypto_dir)/Cargo.toml
312-
363+
@rm -f $(output_root)/lib/$(espresso_crypto_filename)
364+
rm -f $(ESPRESSO_TAR)
365+
rm -rf $(ESPRESSO_DIR)
313366
# Ensure lib64 is a symlink to lib
314367
mkdir -p $(output_root)/lib
315368
ln -s lib $(output_root)/lib64

arbnode/batch_poster.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ type BatchPosterConfig struct {
186186
// Espresso specific flags
187187
LightClientAddress string `koanf:"light-client-address"`
188188
HotShotUrl string `koanf:"hotshot-url"`
189-
FallBackUrl string `koanf:"fall-back-url"`
190189
UseEscapeHatch bool `koanf:"use-escape-hatch"`
191190
EspressoTxnsPollingInterval time.Duration `koanf:"espresso-txns-polling-interval"`
192191
ResubmitEspressoTxDeadline time.Duration `koanf:"resubmit-espresso-tx-deadline"`
@@ -388,7 +387,7 @@ func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, e
388387
lightClientAddr := opts.Config().LightClientAddress
389388

390389
if hotShotUrl != "" {
391-
hotShotClient := hotshotClient.NewClient(hotShotUrl, opts.Config().FallBackUrl)
390+
hotShotClient := hotshotClient.NewClient(hotShotUrl)
392391
opts.Streamer.espressoClient = hotShotClient
393392
}
394393

arbnode/transaction_streamer.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
lightclient "github.com/EspressoSystems/espresso-network-go/light-client"
2424
tagged_base64 "github.com/EspressoSystems/espresso-network-go/tagged-base64"
2525
espressoTypes "github.com/EspressoSystems/espresso-network-go/types"
26+
espressoVerification "github.com/EspressoSystems/espresso-network-go/verification"
2627
"github.com/ccoveille/go-safecast"
2728
flag "github.com/spf13/pflag"
2829

@@ -37,7 +38,6 @@ import (
3738
"github.com/offchainlabs/nitro/arbutil"
3839
"github.com/offchainlabs/nitro/broadcaster"
3940
m "github.com/offchainlabs/nitro/broadcaster/message"
40-
"github.com/offchainlabs/nitro/espressocrypto"
4141
"github.com/offchainlabs/nitro/execution"
4242
"github.com/offchainlabs/nitro/staker"
4343
"github.com/offchainlabs/nitro/util"
@@ -1452,10 +1452,10 @@ func (s *TransactionStreamer) checkSubmittedTransactionForFinality(ctx context.C
14521452

14531453
blockMerkleTreeRoot := nextHeader.Header.GetBlockMerkleTreeRoot()
14541454

1455-
ok := espressocrypto.VerifyMerkleProof(proof.Proof, jsonHeader, *blockMerkleTreeRoot, snapshot.Root)
1456-
if !ok {
1457-
log.Info("error validating merkle proof", "root", snapshot.Root, "height", height)
1458-
return fmt.Errorf("error validating merkle proof (height: %d, snapshot height: %d)", height, snapshot.Height)
1455+
ok, err := espressoVerification.VerifyMerkleProof(proof.Proof, jsonHeader, *blockMerkleTreeRoot, snapshot.Root)
1456+
if err != nil || !ok {
1457+
log.Error("error validating merkle proof", "root", snapshot.Root, "height", height, "err", err)
1458+
return fmt.Errorf("error validating merkle proof (height: %d, snapshot height: %d): %w", height, snapshot.Height, err)
14591459
}
14601460

14611461
// Verify the namespace proof
@@ -1464,7 +1464,7 @@ func (s *TransactionStreamer) checkSubmittedTransactionForFinality(ctx context.C
14641464
return fmt.Errorf("failed to fetch the transactions in block (height: %d): %w", height, err)
14651465
}
14661466

1467-
namespaceOk := espressocrypto.VerifyNamespace(
1467+
namespaceOk, err := espressoVerification.VerifyNamespace(
14681468
s.chainConfig.ChainID.Uint64(),
14691469
resp.Proof,
14701470
*header.Header.GetPayloadCommitment(),
@@ -1473,8 +1473,9 @@ func (s *TransactionStreamer) checkSubmittedTransactionForFinality(ctx context.C
14731473
resp.VidCommon,
14741474
)
14751475

1476-
if !namespaceOk {
1477-
return fmt.Errorf("error validating namespace proof (height: %d)", height)
1476+
if err != nil || !namespaceOk {
1477+
log.Error("error validating namespace proof", "root", snapshot.Root, "height", height, "err", err)
1478+
return fmt.Errorf("error validating namespace proof (height: %d): %w", height, err)
14781479
}
14791480

14801481
submittedPayload := firstSubmitted.Payload

espressocrypto/espressocrypto_common.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)