diff --git a/.github/workflows/arithmetization-simple-zkc-binary-run-and-go-corset-check.yml b/.github/workflows/arithmetization-simple-zkc-binary-run-and-go-corset-check.yml new file mode 100644 index 0000000000..ea93db2061 --- /dev/null +++ b/.github/workflows/arithmetization-simple-zkc-binary-run-and-go-corset-check.yml @@ -0,0 +1,42 @@ +name: Tracer simple zkc binary run and go-corset check + +on: + pull_request: + branches: + - main + paths: + - 'arithmetization/**' + - '.github/actions/setup-arithmetization-riscv/**' + - '.github/workflows/arithmetization-*.yml' + push: + branches: + - main + paths: + - 'arithmetization/**' + - '.github/actions/setup-arithmetization-riscv/**' + - '.github/workflows/arithmetization-*.yml' + workflow_call: + workflow_dispatch: + +permissions: + contents: read + actions: read + +jobs: + build: + runs-on: gha-runner-scale-set-ubuntu-24-amd64-small + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + submodules: false + + - name: Setup Environment + uses: ./.github/actions/setup-arithmetization-riscv + + - name: Install zkc, compile risc binary for simple zkc test program and go-corset check it + run: make -C arithmetization zkc-compile-and-check + env: + ZKC_MAIN: src/test/examples/zkc/simple_add.zkc + ZKC_FILES: src/test/examples/zkc/simple_add.zkc + ZKC_INPUT: src/test/examples/zkc/simple_add.json diff --git a/arithmetization/Makefile b/arithmetization/Makefile index e931653dee..ec51967f70 100644 --- a/arithmetization/Makefile +++ b/arithmetization/Makefile @@ -16,12 +16,13 @@ GO_CORSET_REF_FOR_ZKC ?= # Used to install go-corset GO_CORSET_VERSION ?= v1.2.17 -ZKC_FILES := $(shell find $(MAKEFILE_DIR)src/main/riscv/* -name "*.zkc") -ZKC_MAIN := $(MAKEFILE_DIR)src/main/riscv/main.zkc -ZKC_BINDIR := $(MAKEFILE_DIR)bin -ZKC_BINARY := riscv.bin +ZKC_FILES ?= $(shell find $(MAKEFILE_DIR)src/main/riscv/* -name "*.zkc") +ZKC_MAIN ?= $(MAKEFILE_DIR)src/main/riscv/main.zkc +ZKC_BINDIR ?= $(MAKEFILE_DIR)bin +ZKC_BINARY ?= riscv.bin +ZKC_INPUT ?= input.json -.PHONY: checkout-go-corset install-go-corset install-zkc zkc-compile check +.PHONY: checkout-go-corset install-go-corset install-zkc zkc-compile zkc-check zkc-compile-and-check check # Fetch go-corset if missing (no-op when CI already checked it out into GO_CORSET). checkout-go-corset: @@ -41,17 +42,25 @@ checkout-go-corset: install-zkc: checkout-go-corset cd "$(GO_CORSET)" && go install ./cmd/zkc -# Compile the main RISC-V ZKC program. +# Compile zkc program in a binary file zkc-compile: $(ZKC_FILES) mkdir -p $(ZKC_BINDIR) zkc compile -o $(ZKC_BINDIR)/$(ZKC_BINARY) --wir $(ZKC_MAIN) +# Check execution of the compiled zkc binary against an input JSON +# Only works for small zkc programs for now +zkc-check: + zkc exec --check $(ZKC_INPUT) $(ZKC_BINDIR)/$(ZKC_BINARY) + +zkc-compile-and-check: install-zkc zkc-compile zkc-check + zkc-lint: zkc format --check $(ZKC_FILES) zkc-lint-apply: zkc format $(ZKC_FILES) +# Compile the main RISC-V zkc program in a binary file riscv-check-compilation: install-zkc zkc-compile riscv-check-lint: install-zkc zkc-lint diff --git a/arithmetization/src/test/examples/zkc/simple_add.json b/arithmetization/src/test/examples/zkc/simple_add.json new file mode 100644 index 0000000000..839b3eb2b1 --- /dev/null +++ b/arithmetization/src/test/examples/zkc/simple_add.json @@ -0,0 +1 @@ +{ "data": "0x0001_0002_0003" } \ No newline at end of file diff --git a/arithmetization/src/test/examples/zkc/simple_add.zkc b/arithmetization/src/test/examples/zkc/simple_add.zkc new file mode 100644 index 0000000000..f201f8bf07 --- /dev/null +++ b/arithmetization/src/test/examples/zkc/simple_add.zkc @@ -0,0 +1,13 @@ +// This main function is used for test purposes to integrate the different compilation steps in CI +pub input data(address:u16) -> (byte:u16) + +// prove that two numbers add up to a third. +fn main() { + var lhs:u16 = data[0] + var rhs:u16 = data[1] + var sum:u16 + sum = lhs + rhs + if sum != data[2] { + fail + } +} \ No newline at end of file