Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FFI bindings for Espresso validation #294

Merged
merged 26 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
471e726
Example call to espresso-crypto function stub in batch poster.
zacshowa Nov 1, 2024
28303dd
Result of `make fmt`
zacshowa Nov 1, 2024
730d37f
Make current lib.rs c abi compatible
zacshowa Nov 4, 2024
53120ad
result of make fmt
zacshowa Nov 4, 2024
9479e3a
Add C ABI ffi between rust crypto lib and espressocrypto go module.
zacshowa Nov 4, 2024
5badb7b
Build native.go successfully
ImJeremyHe Nov 5, 2024
cfbbfa7
Update the espresso-crypto and add test for merkle proof verification
ImJeremyHe Nov 5, 2024
acc8423
update flake.nix to new go version and fix errors
zacshowa Nov 5, 2024
15d1443
Current state of work
zacshowa Nov 6, 2024
8b72092
Update the flake.lock
ImJeremyHe Nov 6, 2024
96674ee
Add the namespace proof test
ImJeremyHe Nov 6, 2024
6962386
Current state of build system changes
zacshowa Nov 7, 2024
9bfb658
Build nitro docker image sucessfully
sveitser Nov 7, 2024
afac9b2
Fix LDFLAGS, remove unnecessary CFLAGS
sveitser Nov 7, 2024
7968f8b
Merge branch 'integration' of github.com:EspressoSystems/nitro-espres…
zacshowa Nov 7, 2024
c722a27
Fix some merge errors
sveitser Nov 8, 2024
8fb8a47
Fix merge errors
sveitser Nov 8, 2024
d7bc8ea
Remove FFI call in batch poster to expidite merge.
zacshowa Nov 8, 2024
93c87ba
Update bf submodule in arbitrator to match upstream version (This was…
zacshowa Nov 8, 2024
847ccc8
Remove extra change in espressocrypto_wasm.go
zacshowa Nov 8, 2024
d526c5c
Fix error with temporary espressocryptowasm directory preventing CI f…
zacshowa Nov 8, 2024
e71bd32
fix error of missing function definitions in espressocryptowasm direc…
zacshowa Nov 9, 2024
366648f
Merge branch 'integration' into batch-poster-validation
zacshowa Nov 9, 2024
11d63b2
Re-add nosec comment about gosec error that will be removed soon
zacshowa Nov 9, 2024
cf370a4
result of make fmt
zacshowa Nov 9, 2024
c5c05a7
Merge branch 'batch-poster-validation' of github.com:EspressoSystems/…
zacshowa Nov 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ 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
# pinned rust 1.80.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.80.1 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi
# pinned rust 1.81.0
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81.0 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi
COPY ./Makefile ./
COPY arbitrator/Cargo.* arbitrator/
COPY arbitrator/arbutil arbitrator/arbutil
Expand All @@ -73,6 +73,7 @@ COPY ./arbcompress ./arbcompress
COPY ./arbos ./arbos
COPY ./arbstate ./arbstate
COPY ./espressocrypto ./espressocrypto
COPY ./espressocryptowasm/ ./espressocryptowasm/
COPY ./arbutil ./arbutil
COPY ./gethhook ./gethhook
COPY ./blsSignatures ./blsSignatures
Expand All @@ -96,7 +97,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.80.1-slim-bookworm AS prover-header-builder
FROM rust:1.81.0-slim-bookworm AS prover-header-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand All @@ -114,16 +115,18 @@ COPY arbitrator/jit arbitrator/jit
COPY arbitrator/espresso-crypto-helper arbitrator/espresso-crypto-helper
COPY arbitrator/stylus arbitrator/stylus
COPY arbitrator/tools/wasmer arbitrator/tools/wasmer
COPY espressocrypto espressocrypto
COPY --from=brotli-wasm-export / target/
COPY scripts/build-brotli.sh scripts/
COPY brotli brotli
RUN apt-get update && apt-get install -y cmake
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-header
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-espresso-crypto-lib

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

FROM rust:1.80.1-slim-bookworm AS prover-builder
FROM rust:1.81.0-slim-bookworm AS prover-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand Down
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ precompiles = $(patsubst %,./solgen/generated/%.go, $(precompile_names))
output_root=target
output_latest=$(output_root)/machines/latest

repo_dirs = arbos arbcompress arbnode arbutil arbstate cmd das precompiles solgen system_tests util validator wavmio
repo_dirs = arbos arbcompress arbnode arbutil arbstate cmd das espressocrypto precompiles solgen system_tests util validator wavmio
go_source.go = $(wildcard $(patsubst %,%/*.go, $(repo_dirs)) $(patsubst %,%/*/*.go, $(repo_dirs)))
go_source.s = $(wildcard $(patsubst %,%/*.s, $(repo_dirs)) $(patsubst %,%/*/*.s, $(repo_dirs)))
go_source = $(go_source.go) $(go_source.s)
Expand Down Expand Up @@ -153,7 +153,18 @@ stylus_test_read-return-data_src = $(call get_stylus_test_rust,read-return-data
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_bfs:.b=.wasm)
stylus_benchmarks = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(stylus_test_wasms)

espresso_crypto_dir = ./espressocrypto/lib/espresso-crypto-helper
espresso_crypto_files = $(wildcard $(espresso_crypto_dir)/*.toml $(espresso_crypto_dir)/src/*.rs)
espresso_crypto_lib = $(output_root)/lib/libespresso_crypto_helper.a

# user targets
.PHONY: build-espresso-crypto-lib
build-espresso-crypto-lib: $(espresso_crypto_lib)

$(espresso_crypto_lib): $(DEP_PREDICATE) $(espresso_crypto_files)
mkdir -p `dirname $(espresso_crypto_lib)`
cargo build --release --manifest-path $(espresso_crypto_dir)/Cargo.toml
install $(espresso_crypto_dir)/target/release/libespresso_crypto_helper.a $@

.PHONY: push
push: lint test-go .make/fmt
Expand All @@ -169,7 +180,7 @@ build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool seq
@printf $(done)

.PHONY: build-node-deps
build-node-deps: $(go_source) build-prover-header build-prover-lib build-jit .make/solgen .make/cbrotli-lib
build-node-deps: $(go_source) build-prover-header build-prover-lib build-jit .make/solgen .make/cbrotli-lib build-espresso-crypto-lib

.PHONY: test-go-deps
test-go-deps: \
Expand Down Expand Up @@ -286,7 +297,9 @@ clean:
@rm -rf contracts/build contracts/cache solgen/go/
@rm -f .make/*
rm -rf brotli/buildfiles
# Ensure lib64 is a symlink to lib
cargo clean --manifest-path $(espresso_crypto_dir)/Cargo.toml

# Ensure lib64 is a symlink to lib
mkdir -p $(output_root)/lib
ln -s lib $(output_root)/lib64

Expand Down
2 changes: 1 addition & 1 deletion arbitrator/jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
arbutil = { path = "../arbutil/" }
espresso-crypto-helper = { path = "../espresso-crypto-helper/" }
espresso-crypto-helper = { path = "../espresso-crypto-helper/"}
brotli = { path = "../brotli/", features = ["wasmer_traits"] }
caller-env = { path = "../caller-env/", features = ["wasmer_traits"] }
prover = { path = "../prover/", default-features = false, features = ["native"] }
Expand Down
1 change: 1 addition & 0 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ func (b *BatchPoster) addEspressoBlockMerkleProof(
}
var newMsg arbostypes.L1IncomingMessage
jst.BlockMerkleJustification = &arbostypes.BlockMerkleJustification{BlockMerkleProof: &proof, BlockMerkleComm: nextHeader.BlockMerkleTreeRoot}

if arbos.IsEspressoSovereignMsg(msg.Message) {
// Passing an empty byte slice as payloadSignature because txs[0] already contains the payloadSignature here
newMsg, err = arbos.MessageFromEspressoSovereignTx(txs[0], jst, []byte{}, msg.Message.Header)
Expand Down
6 changes: 3 additions & 3 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/das/dastree"
"github.com/offchainlabs/nitro/espressocrypto"
"github.com/offchainlabs/nitro/espressocryptowasm"
"github.com/offchainlabs/nitro/gethhook"
"github.com/offchainlabs/nitro/wavmio"
)
Expand Down Expand Up @@ -322,14 +322,14 @@ func main() {
if err != nil {
panic("unable to serialize header")
}
espressocrypto.VerifyMerkleProof(
espressocryptowasm.VerifyMerkleProof(
jst.BlockMerkleJustification.BlockMerkleProof.Proof,
jsonHeader,
*jst.BlockMerkleJustification.BlockMerkleComm,
commitment,
)
if jst.Proof != nil {
espressocrypto.VerifyNamespace(chainConfig.ChainID.Uint64(), *jst.Proof, *jst.Header.PayloadCommitment, *jst.Header.NsTable, txs, *jst.VidCommon)
espressocryptowasm.VerifyNamespace(chainConfig.ChainID.Uint64(), *jst.Proof, *jst.Header.PayloadCommitment, *jst.Header.NsTable, txs, *jst.VidCommon)
}

}
Expand Down
9 changes: 5 additions & 4 deletions espressocrypto/espressocrypto_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ func VerifyNamespace(
ns_table espressoTypes.NsTable,
txs []espressoTypes.Bytes,
common_data json.RawMessage,
) {
) bool {
// TODO: this code will likely no longer be used in the STF soon.
// G115: integer overflow conversion uint64 -> uint32 (gosec)
// #nosec G115
var txnComm = hashTxns(uint32(namespace), txs)
verifyNamespace(
res := verifyNamespace(
namespace,
proof,
[]byte(block_comm.String()),
ns_table.Bytes,
[]byte(txnComm),
common_data,
)
return res
}

func VerifyMerkleProof(
proof json.RawMessage,
header json.RawMessage,
blockComm espressoTypes.TaggedBase64,
circuit_comm_bytes espressoTypes.Commitment,
) {
verifyMerkleProof(proof, header, []byte(blockComm.String()), circuit_comm_bytes[:])
) bool {
return verifyMerkleProof(proof, header, []byte(blockComm.String()), circuit_comm_bytes[:])
}
Loading
Loading