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

ZIR-236: Create a new Zirgen Standard Library #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions zirgen/circuit/keccak/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ package(
)

KECCAK_ZIR_FILES = [
"bits.zir",
"keccak.zir",
"one_hot.zir",
"sha256_for_keccak.zir",
]

glob_lit_tests(
# TODO: shorten timeout once zirgen is faster
timeout = "long",
data = KECCAK_ZIR_FILES,
data = KECCAK_ZIR_FILES + ["//zirgen/dsl/Library/src"],
exclude = KECCAK_ZIR_FILES,
test_file_exts = ["zir"],
)
Expand All @@ -33,10 +31,12 @@ build_circuit(
name = "keccak",
outs = KECCAK_OUTS,
bin = "//zirgen/Main:gen_zirgen",
data = KECCAK_ZIR_FILES,
data = KECCAK_ZIR_FILES + ["//zirgen/dsl/Library/src"],
extra_args = [
"zirgen/circuit/keccak/keccak.zir",
"-I",
"zirgen/dsl/Library/src",
"-I",
"zirgen/circuit/keccak",
"--validity-split-count=5",
],
Expand Down
16 changes: 8 additions & 8 deletions zirgen/circuit/keccak/keccak.zir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080578951e24efd62a3d63a86f7cd19aaa53c898fe287d2Q552133220370240b572d0000000000000000
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080578951e24efd62a3d63a86f7cd19aaa53c898fe287d2Q552133220370240b572d0000000000000000

import sha256_for_keccak;
import one_hot;
Expand Down Expand Up @@ -755,7 +755,7 @@ component chi_minor0<X: Val, Y: Val>(rvpstate: RetTuple,

withrs_d := Concatenate<BLEN(),2>(unpack_0xp1, result);
Z := (X-1)*(X-3);
minor_new := [Isz(Z), 1-Isz(Z)] -> (3*(1+(X-1)/2), 1+3*(X/2));
minor_new := [Isz(Z), 1-Isz(Z)] -> (3*(1+(X-1)/2), 1+3*(X/2));
a := ConcatZeros<SLEN(),BLEN()-SLEN()>(unpack_1xp1);
c := ConcatZeros<SLEN(),BLEN()-SLEN()>(unpack_1xp2);
f := ConcatZeros<SLEN(),BLEN()-SLEN()>(unpack_1x);
Expand Down Expand Up @@ -942,7 +942,7 @@ component chi_minor2<Y: Val>(rvals: RetTuple, auxr: Array<NondetReg, AUXLEN()>)
{ rs1 := [Reg(rvprev07.arr_a[0+SLEN()]),Reg(rvprev07.arr_b[0+SLEN()]),
Reg(rvprev07.arr_c[0+SLEN()]),Reg(rvprev06.arr_d[0+BLEN()]),
Reg(rvprev06.arr_d[1+BLEN()]),Reg(rvprev07.arr_d[0+SLEN()])];
c := Concatenate<16, 6>(for i : 0..16 {Reg(rvpstate.arr_c[i])}, rs1);
c := Concatenate<16, 6>(for i : 0..16 {Reg(rvpstate.arr_c[i])}, rs1);
rs2 := [Reg(rvprev04.arr_a[0+SLEN()]),Reg(rvprev04.arr_b[0+SLEN()]),
Reg(rvprev04.arr_c[0+SLEN()]),Reg(rvprev03.arr_d[0+BLEN()]),
Reg(rvprev03.arr_d[1+BLEN()]),Reg(rvprev04.arr_d[0+SLEN()]),
Expand All @@ -952,7 +952,7 @@ component chi_minor2<Y: Val>(rvals: RetTuple, auxr: Array<NondetReg, AUXLEN()>)
unpack_round := OneHotU<24>(rvprev01.rnd);
rnd_1 := for i : 0..2 { NondetReg(unpack_round[i]) };
for i : 0..2 { AliasLayout!(rnd_1[i], unpack_round[i]); };
rnd_2 := for i : 0..BLEN() { NondetReg(unpack_round[i+2]) };
rnd_2 := for i : 0..BLEN() { NondetReg(unpack_round[i+2]) };
for i : 0..22 { AliasLayout!(rnd_2[i], unpack_round[i+2]); };

tmp_d := ConcatZeros<9,RLEN()-9-2>(rs2);
Expand Down Expand Up @@ -1116,8 +1116,8 @@ component absorb_word<X: Val, Y: Val>(rvprev: RetTuple,
inc_idx := X+5*Y+1;
in_first := InRange(0,inc_idx,10);
nxt_major := 1 - in_first;
nxt_in := [in_first, nxt_major] -> (inc_idx, inc_idx-9);
nxt_in := [in_first, nxt_major] -> (inc_idx, inc_idx-9);

RetTuple(unpack_a, arr12, padded23, withr34, padded_e, padded_f,
nxt_in, 14+nxt_major, 0, rvprev.blk, rvprev.midx, auxr)
}
Expand Down Expand Up @@ -1377,15 +1377,15 @@ component mem_padding_sha256(rvprev01: RetTuple,
a_tmp := for i : 0 .. SLEN() { NondetReg(unpack_bitlen[i]) };
for i : 0 .. SLEN() { AliasLayout!(a_tmp[i], unpack_bitlen[i]); };
a := ConcatZeros<SLEN(),BLEN()-SLEN()>(a_tmp);

d_tmp := for i : SLEN() .. F { NondetReg(unpack_bitlen[i]) };
for i : SLEN() .. F {
AliasLayout!(d_tmp[i-SLEN()], unpack_bitlen[i]); };
d_tmp2 := Concatenate<BABYMAX()-SLEN(),3>(d_tmp, unpack_nskip);
ntmp := BABYMAX()-SLEN()+3;
d_tmp3 := ConcatZeros<ntmp,RLEN()-3-ntmp>(d_tmp2);
d := Concatenate<RLEN()-3,3>(d_tmp3, [invn, invnNxt, prodNxt]);

[1-prod, prod] -> (
{ WriteMemory(memidx, MemDigest([0,0,b34,b12]));
RetTuple(a, dummyB(), dummyB(), d, dummyB(), dummyB(),
Expand Down
2 changes: 1 addition & 1 deletion zirgen/circuit/keccak/test0k.nop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4700000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4700000000000000000 2>&1 | FileCheck %s

import keccak;

Expand Down
2 changes: 1 addition & 1 deletion zirgen/circuit/keccak/test0s.nop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a0000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a0000000000000000 2>&1 | FileCheck %s

import keccak;

Expand Down
2 changes: 1 addition & 1 deletion zirgen/circuit/keccak/test1k.zir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d0000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d0000000000000000 2>&1 | FileCheck %s

import keccak;

Expand Down
2 changes: 1 addition & 1 deletion zirgen/circuit/keccak/test1s.nop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a80f839cd4f83f6c3dafc87feae470045e4eb0d366397d5c6ce34ba1739f734d0000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 3000 --input-data-hex 010000000000000054686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E0600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a80f839cd4f83f6c3dafc87feae470045e4eb0d366397d5c6ce34ba1739f734d0000000000000000 2>&1 | FileCheck %s

import keccak;

Expand Down
2 changes: 1 addition & 1 deletion zirgen/circuit/keccak/test2k.zir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: zirgen -I %S --test %s --test-cycles 23000 --input-data-hex 0600000000000000436F6D6D616E64657220526F64657269636B20426C61696E65206C6F6F6B6564206672616E746963616C6C792061726F756E6420746865206272696467652E20776865726520686973206F66666963657273207765726520646972656374696E6720726570616972732077697468206C6F7720616E6420757267656E7420766F696365732C2073757267656F6E7320617373697374696E67206174206120646966666963756C74206F7065726174696F6E2E20546865206772617920737465656C20636F6D706172746D656E7420776173206120636F6E667573696F6E206F6620616374697669746965732C2065616368206F726465726C7920627920697473656C662062757420746865206F766572616C6C20696D7072657373696F6E20776173206F66206368616F732E2053637265656E732061626F7665206F6E652068656C6D736D616E27732073746174696F6E2073686F7765642074686520706C616E65742062656C6F7720616E6420746865206F746865722C20736869707320696E206F72626974206E656172204D61634172746875722C20627574206576657279776865726520656C7365207468652070616E656C20636F7665727320686164206265656E2072656D6F7665642066726F6D20636F6E736F6C65732C207465737420696E737472756D656E7473207765726520636C697070656420696E746F20746865697220696E73696465732C20616E6420746563686E696369616E732073746F6F64206279207769746820636F6C6F722D636F64656420656C656374726F6E696320617373656D626C69657320746F207265706C6163652065766572797468696E672074686174207365656D656420646F75627466756C2E205468756D707320616E64207768696E657320736F756E646564207468726F75676820746865207368697020383920736F6D657768657265206166742074686520656E67696E656572696E67206372657720776F726B6564206F6E207468652068756C6C2E01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008028c3f5c69c21be780e5508d355ebf7d5e060f203ca8717447b71cb44544df5c70200000000000000546865736520776F7264732077657265207574746572656420696E204A756C79203138303520627920416E6E61205061766C6F766E6120536368657265722C20612064697374696E67756973686564206C616479206F662074686520636F7572742C20616E6420636F6E666964656E7469616C206D6169642D6F662D686F6E6F757220746F2074686520456D7072657373204D617279612046796F646F726F766E612E2049742077617320686572206772656574696E6720746F205072696E63652056617373696C792C2061206D616E206869676820696E2072616E6B20616E64206F66666963652C2077686F207761732074686520666972737420746F2061727269766520617401000000000000804bdc1874a3125f1f911fe8c76ac8443a6ec623ef91bc58eabf54c5762097894d0000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 23000 --input-data-hex 0600000000000000436F6D6D616E64657220526F64657269636B20426C61696E65206C6F6F6B6564206672616E746963616C6C792061726F756E6420746865206272696467652E20776865726520686973206F66666963657273207765726520646972656374696E6720726570616972732077697468206C6F7720616E6420757267656E7420766F696365732C2073757267656F6E7320617373697374696E67206174206120646966666963756C74206F7065726174696F6E2E20546865206772617920737465656C20636F6D706172746D656E7420776173206120636F6E667573696F6E206F6620616374697669746965732C2065616368206F726465726C7920627920697473656C662062757420746865206F766572616C6C20696D7072657373696F6E20776173206F66206368616F732E2053637265656E732061626F7665206F6E652068656C6D736D616E27732073746174696F6E2073686F7765642074686520706C616E65742062656C6F7720616E6420746865206F746865722C20736869707320696E206F72626974206E656172204D61634172746875722C20627574206576657279776865726520656C7365207468652070616E656C20636F7665727320686164206265656E2072656D6F7665642066726F6D20636F6E736F6C65732C207465737420696E737472756D656E7473207765726520636C697070656420696E746F20746865697220696E73696465732C20616E6420746563686E696369616E732073746F6F64206279207769746820636F6C6F722D636F64656420656C656374726F6E696320617373656D626C69657320746F207265706C6163652065766572797468696E672074686174207365656D656420646F75627466756C2E205468756D707320616E64207768696E657320736F756E646564207468726F75676820746865207368697020383920736F6D657768657265206166742074686520656E67696E656572696E67206372657720776F726B6564206F6E207468652068756C6C2E01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008028c3f5c69c21be780e5508d355ebf7d5e060f203ca8717447b71cb44544df5c70200000000000000546865736520776F7264732077657265207574746572656420696E204A756C79203138303520627920416E6E61205061766C6F766E6120536368657265722C20612064697374696E67756973686564206C616479206F662074686520636F7572742C20616E6420636F6E666964656E7469616C206D6169642D6F662D686F6E6F757220746F2074686520456D7072657373204D617279612046796F646F726F766E612E2049742077617320686572206772656574696E6720746F205072696E63652056617373696C792C2061206D616E206869676820696E2072616E6B20616E64206F66666963652C2077686F207761732074686520666972737420746F2061727269766520617401000000000000804bdc1874a3125f1f911fe8c76ac8443a6ec623ef91bc58eabf54c5762097894d0000000000000000 2>&1 | FileCheck %s

import keccak;

Expand Down
4 changes: 2 additions & 2 deletions zirgen/circuit/keccak/test2s.nop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: zirgen -I %S --test %s --test-cycles 23000 --input-data-hex 0600000000000000436F6D6D616E64657220526F64657269636B20426C61696E65206C6F6F6B6564206672616E746963616C6C792061726F756E6420746865206272696467652E20776865726520686973206F66666963657273207765726520646972656374696E6720726570616972732077697468206C6F7720616E6420757267656E7420766F696365732C2073757267656F6E7320617373697374696E67206174206120646966666963756C74206F7065726174696F6E2E20546865206772617920737465656C20636F6D706172746D656E7420776173206120636F6E667573696F6E206F6620616374697669746965732C2065616368206F726465726C7920627920697473656C662062757420746865206F766572616C6C20696D7072657373696F6E20776173206F66206368616F732E2053637265656E732061626F7665206F6E652068656C6D736D616E27732073746174696F6E2073686F7765642074686520706C616E65742062656C6F7720616E6420746865206F746865722C20736869707320696E206F72626974206E656172204D61634172746875722C20627574206576657279776865726520656C7365207468652070616E656C20636F7665727320686164206265656E2072656D6F7665642066726F6D20636F6E736F6C65732C207465737420696E737472756D656E7473207765726520636C697070656420696E746F20746865697220696E73696465732C20616E6420746563686E696369616E732073746F6F64206279207769746820636F6C6F722D636F64656420656C656374726F6E696320617373656D626C69657320746F207265706C6163652065766572797468696E672074686174207365656D656420646F75627466756C2E205468756D707320616E64207768696E657320736F756E646564207468726F75676820746865207368697020383920736F6D657768657265206166742074686520656E67696E656572696E67206372657720776F726B6564206F6E207468652068756C6C2E0600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000805db9add409333e7f0834569e8e0f6825d684a88363d398b1d0ead06e01d03c1e0200000000000000546865736520776F7264732077657265207574746572656420696E204A756C79203138303520627920416E6E61205061766C6F766E6120536368657265722C20612064697374696E67756973686564206C616479206F662074686520636F7572742C20616E6420636F6E666964656E7469616C206D6169642D6F662D686F6E6F757220746F2074686520456D7072657373204D617279612046796F646F726F766E612E2049742077617320686572206772656574696E6720746F205072696E63652056617373696C792C2061206D616E206869676820696E2072616E6B20616E64206F66666963652C2077686F207761732074686520666972737420746F20617272697665206174060000000000008076d8ddb3fc6c9825ed4a81157c3486e4f35df5cdcf93df3b5c80f1d93ec144fb0000000000000000 2>&1 | FileCheck %s
// RUN: zirgen -I %S/../../dsl/Library/src -I %S --test %s --test-cycles 23000 --input-data-hex 0600000000000000436F6D6D616E64657220526F64657269636B20426C61696E65206C6F6F6B6564206672616E746963616C6C792061726F756E6420746865206272696467652E20776865726520686973206F66666963657273207765726520646972656374696E6720726570616972732077697468206C6F7720616E6420757267656E7420766F696365732C2073757267656F6E7320617373697374696E67206174206120646966666963756C74206F7065726174696F6E2E20546865206772617920737465656C20636F6D706172746D656E7420776173206120636F6E667573696F6E206F6620616374697669746965732C2065616368206F726465726C7920627920697473656C662062757420746865206F766572616C6C20696D7072657373696F6E20776173206F66206368616F732E2053637265656E732061626F7665206F6E652068656C6D736D616E27732073746174696F6E2073686F7765642074686520706C616E65742062656C6F7720616E6420746865206F746865722C20736869707320696E206F72626974206E656172204D61634172746875722C20627574206576657279776865726520656C7365207468652070616E656C20636F7665727320686164206265656E2072656D6F7665642066726F6D20636F6E736F6C65732C207465737420696E737472756D656E7473207765726520636C697070656420696E746F20746865697220696E73696465732C20616E6420746563686E696369616E732073746F6F64206279207769746820636F6C6F722D636F64656420656C656374726F6E696320617373656D626C69657320746F207265706C6163652065766572797468696E672074686174207365656D656420646F75627466756C2E205468756D707320616E64207768696E657320736F756E646564207468726F75676820746865207368697020383920736F6D657768657265206166742074686520656E67696E656572696E67206372657720776F726B6564206F6E207468652068756C6C2E0600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000805db9add409333e7f0834569e8e0f6825d684a88363d398b1d0ead06e01d03c1e0200000000000000546865736520776F7264732077657265207574746572656420696E204A756C79203138303520627920416E6E61205061766C6F766E6120536368657265722C20612064697374696E67756973686564206C616479206F662074686520636F7572742C20616E6420636F6E666964656E7469616C206D6169642D6F662D686F6E6F757220746F2074686520456D7072657373204D617279612046796F646F726F766E612E2049742077617320686572206772656574696E6720746F205072696E63652056617373696C792C2061206D616E206869676820696E2072616E6B20616E64206F66666963652C2077686F207761732074686520666972737420746F20617272697665206174060000000000008076d8ddb3fc6c9825ed4a81157c3486e4f35df5cdcf93df3b5c80f1d93ec144fb0000000000000000 2>&1 | FileCheck %s

import keccak;

test TestKeccak02s { // test_cycles >= 22773
Expand Down
2 changes: 1 addition & 1 deletion zirgen/docs/01_Getting_Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tests defined in the file we're running. Typically, the output of Zirgen is a
generated Rust or C++ library that then needs to be integrated with the RISC
Zero proof system. For the sake of simplicity here and as a useful practice
during the development, it is easiest to experiment with Zirgen by writing tests
alongside your circuit code, which can be run in the builtin interpreter without
alongside your circuit code, which can be run in the built-in interpreter without
doing this integration work using the `--test` option. Now, the important part
of the file is the following:

Expand Down
Loading
Loading