Skip to content

Feat/Proof mode and secure run functionality #531

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

Merged
merged 9 commits into from
Jul 18, 2024
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Run all benchmarks and compare:
make build-compare-benchmarks
```

Run all programs and compare output memory/trace for Zig/Rust cairo-vm:
```bash
make build-compare-output
```


Run all unit tests with test summary:

Expand Down
9 changes: 9 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.name = "unit_tests",
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
Expand All @@ -155,6 +156,13 @@ pub fn build(b: *std.Build) void {
mod.module,
);

const build_unit_tests = b.addInstallArtifact(unit_tests, .{});

// Creating run step for building unit tests
const build_test_step = b.step("build-test", "Build test binary");
build_test_step.dependOn(&lib.step);
build_test_step.dependOn(&build_unit_tests.step);

const run_unit_tests = b.addRunArtifact(unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
Expand All @@ -164,6 +172,7 @@ pub fn build(b: *std.Build) void {
"test",
"Run unit tests",
);

test_step.dependOn(&lib.step);
test_step.dependOn(&run_unit_tests.step);
}
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
.hash = "1220ab73fb7cc11b2308edc3364988e05efcddbcac31b707f55e6216d1b9c0da13f1",
},
.starknet = .{
.url = "https://github.com/StringNick/starknet-zig/archive/7d51aed59982146df3581d3d3320d509b0b10f54.zip",
.hash = "1220b00c055ce40da237598e0f1c8758e3434470be648816fa4701a09f683146d4cd",
.url = "https://github.com/StringNick/starknet-zig/archive/d9e95579ce9f61a8acf42da03d9371af62925a9e.zip",
.hash = "12205f6b98ed2d3b99420d95f94a28d4e2f25f49001aca5db539d6a23e7b1840710e",
},
},
}
4 changes: 2 additions & 2 deletions scripts/benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ for file in $(ls ${BENCH_DIR} | grep .cairo | sed -E 's/\.cairo//'); do
cairo-compile --cairo_path="${CAIRO_DIR}:../${CAIRO_DIR}" ${BENCH_DIR}/${file}.cairo --output ${BENCH_DIR}/${file}.json --proof_mode
echo "Running ${file} benchmark"
hyperfine --show-output --warmup 2 \
-n "cairo-vm (Rust)" "${CAIRO_VM_CLI} ${BENCH_DIR}/${file}.json --memory_file /dev/null --trace_file /dev/null --layout all_cairo" \
-n "cairo-vm (Zig)" "${ZIG_CLI} execute --filename ${BENCH_DIR}/${file}.json --enable-trace=true --output-memory=/dev/null --output-trace=/dev/null --layout all_cairo"
-n "cairo-vm (Rust)" "${CAIRO_VM_CLI} ${BENCH_DIR}/${file}.json --memory_file /dev/null --trace_file /dev/null --proof_mode --layout all_cairo" \
-n "cairo-vm (Zig)" "${ZIG_CLI} execute --filename ${BENCH_DIR}/${file}.json --memory-file=/dev/null --trace-file=/dev/null --proof-mode=true --layout all_cairo"
done
18 changes: 11 additions & 7 deletions scripts/test_compare_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ ZIG_MEMORY_OUTPUT="./tmp/zig_memory.tmp"
RUST_TRACE_OUTPUT="./tmp/rust_trace.tmp"
ZIG_TRACE_OUTPUT="./tmp/zig_trace.tmp"

Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
NC='\033[0m' # No Color

trap ctrl_c INT

ctrl_c() {
Expand All @@ -32,24 +36,24 @@ ctrl_c() {
mkdir tmp

for file in $(ls ${CAIRO_PROGRAMS_DIR} | grep .cairo | sed -E 's/\.cairo//'); do
echo "Compiling ${file} program..."
echo "${NC}Compiling ${file} program..."
cairo-compile --cairo_path="${CAIRO_DIR}:" ${CAIRO_PROGRAMS_DIR}/${file}.cairo --output ${CAIRO_PROGRAMS_DIR}/${file}.json --proof_mode
echo "Running ${file}"

${CAIRO_VM_CLI} ${CAIRO_PROGRAMS_DIR}/${file}.json --memory_file $RUST_MEMORY_OUTPUT --trace_file $RUST_TRACE_OUTPUT --layout all_cairo
${CAIRO_VM_CLI} ${CAIRO_PROGRAMS_DIR}/${file}.json --memory_file $RUST_MEMORY_OUTPUT --trace_file $RUST_TRACE_OUTPUT --proof_mode --layout all_cairo

${ZIG_CLI} execute --filename ${CAIRO_PROGRAMS_DIR}/${file}.json --enable-trace=true --output-memory=$ZIG_MEMORY_OUTPUT --output-trace=$ZIG_TRACE_OUTPUT --layout all_cairo
${ZIG_CLI} execute --filename ${CAIRO_PROGRAMS_DIR}/${file}.json --memory-file=$ZIG_MEMORY_OUTPUT --trace-file=$ZIG_TRACE_OUTPUT --proof-mode=true --layout=all_cairo

if sameContents $RUST_TRACE_OUTPUT $ZIG_TRACE_OUTPUT; then
echo "Rust & Zig output trace is same"
echo "${Green}Rust & Zig output trace is same"
else
echo "Zig have different output trace"
echo "${Red}Zig have different output trace"
fi

if sameContents $RUST_MEMORY_OUTPUT $ZIG_MEMORY_OUTPUT; then
echo "Rust & Zig memory output is same"
echo "${Green}Rust & Zig memory output is same"
else
echo "Zig have different output memory"
echo "${Red}Zig have different output memory"
fi
done

Expand Down
7 changes: 0 additions & 7 deletions src/build_options.zig

This file was deleted.

Loading
Loading