Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
133 changes: 133 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
members = [
"crates/decoder/core",
"crates/decoder/zstd-ffi",
"crates/encoder/core",
"crates/encoder/zstd-ffi",
"crates/codec-ffi",
]
resolver = "3"

Expand All @@ -12,6 +15,20 @@ license = "MIT OR Apache-2.0"
publish = false

[workspace.dependencies]
# Internal crates: pure-Rust logic lives in the `core` crates (reusable by other
# Rust projects as plain rlibs); the `ffi` crates hold the C ABI; `codec-ffi` is
# the single staticlib aggregator linked by Go.
morph-da-decoder-core = { path = "crates/decoder/core" }
morph-da-decoder-ffi = { path = "crates/decoder/zstd-ffi" }
morph-da-encoder-core = { path = "crates/encoder/core" }
morph-da-encoder-ffi = { path = "crates/encoder/zstd-ffi" }

# External: decoder uses the pure-Rust `ruzstd`; encoder wraps the C `libzstd`
# via the `zstd` crate. Their C symbols do not overlap.
ruzstd = "0.8.3"
hex = "0.4.3"
# `experimental` exposes LiteralCompressionMode / include_magicbytes (Magicless
# frame format), required by the Morph DA encoder parameter rules.
zstd = { git = "https://github.com/morph-l2/zstd-rs.git", branch = "zstd-dev", features = [
"experimental",
] }
Comment on lines +31 to +33
hex = "0.4.3"
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ else
GOARCH := unsupported
endif

FFI_LIB := target/release/libmorph_da_zstd_decode.a
GO_LIB := bindings/decoder/zstd/libmorph_da_zstd_decode_$(GOOS)_$(GOARCH).a
LINUX_AMD64_LIB := bindings/decoder/zstd/libmorph_da_zstd_decode_linux_amd64.a
FFI_LIB := target/release/libmorph_da_zstd.a
GO_LIB := bindings/codec/zstd/libmorph_da_zstd_$(GOOS)_$(GOARCH).a
LINUX_AMD64_LIB := bindings/codec/zstd/libmorph_da_zstd_linux_amd64.a
CENTOS7_BUILD_OUT := build/out
CENTOS7_FFI_LIB := $(CENTOS7_BUILD_OUT)/libmorph_da_zstd_decode_linux_amd64.a
CENTOS7_FFI_LIB := $(CENTOS7_BUILD_OUT)/libmorph_da_zstd_linux_amd64.a
DARWIN_DEPLOYMENT_TARGET ?= 11.0

ifeq ($(GOOS),darwin)
FFI_BUILD_ENV := MACOSX_DEPLOYMENT_TARGET=$(DARWIN_DEPLOYMENT_TARGET)
endif

.PHONY: build-zstd-ffi install-decoder-bindings build-zstd-ffi-linux-amd64 install-decoder-bindings-linux-amd64 linux-amd64-decoder-bindings test rust-test go-test clean
.PHONY: build-zstd-ffi install-codec-bindings build-zstd-ffi-linux-amd64 install-codec-bindings-linux-amd64 linux-amd64-codec-bindings test rust-test go-test clean

build-zstd-ffi:
$(FFI_BUILD_ENV) cargo build -p morph-da-decoder-ffi --release
$(FFI_BUILD_ENV) cargo build -p morph-da-codec-ffi --release

install-decoder-bindings: build-zstd-ffi
install-codec-bindings: build-zstd-ffi
cp $(FFI_LIB) $(GO_LIB)

build-zstd-ffi-linux-amd64:
Expand All @@ -45,19 +45,19 @@ build-zstd-ffi-linux-amd64:
--output type=local,dest=$(CENTOS7_BUILD_OUT) \
.

install-decoder-bindings-linux-amd64: build-zstd-ffi-linux-amd64
install-codec-bindings-linux-amd64: build-zstd-ffi-linux-amd64
cp $(CENTOS7_FFI_LIB) $(LINUX_AMD64_LIB)


rust-test:
cargo test --workspace

go-test: install-decoder-bindings
cd bindings/decoder && go test ./...
go-test: install-codec-bindings
cd bindings/codec && go test ./...

test: rust-test go-test

clean:
cargo clean
rm -f bindings/decoder/zstd/*.a
rm -f bindings/codec/zstd/*.a
rm -rf $(CENTOS7_BUILD_OUT)
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# morph-da-codec

Morph DA zstd decoder shared by Rust zkVM guest code and Go node code.(There will be encoder in the future)
Morph DA zstd codec (encoder + decoder) shared by Rust zkVM guest code and Go node code.

The encoder and decoder are compiled into a single staticlib and exposed to Go through the `bindings/codec/zstd` package:

- `CompressMorphDABatch` — compress a batch into a magic-less zstd frame;
- `DecompressMorphDABatch` — decompress a frame produced by the encoder.

## Semantics

- input payload omits zstd magic bytes;
- decoder prepends `28 b5 2f fd` internally;
- only the first complete zstd frame is decoded;
- bytes after the first frame are ignored;
Encoder and decoder share the same frame format:

- the frame omits the zstd magic bytes (`28 b5 2f fd`); the decoder prepends them internally;
- a single frame is produced, with content size included so the decoder can validate it;
- literal compression is disabled (raw literal bytes) and the window log is capped at 17.

Decoder specifics:

- only the first complete frame is decoded; bytes after it are ignored;
- first frame content size is required and validated.

## Build

```sh
make build-zstd-ffi
make install-decoder-bindings
make install-codec-bindings
make test
```
Loading