Skip to content

Commit 32a29ff

Browse files
feat(galois): upgrade gnark and improve circuit/tests (#1135)
towards #1114
2 parents 78970b1 + 384e1b5 commit 32a29ff

File tree

327 files changed

+17379
-9930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+17379
-9930
lines changed

dictionary.txt

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ cosmrs
233233
cosmwasm
234234
cosmwasmclient
235235
counterparty
236+
cover
237+
coverpkg
238+
coverprofile
236239
cpufeatures
237240
cratedir
238241
crisiskeeper

evm/contracts/clients/Verifier.sol

+26-26
Original file line numberDiff line numberDiff line change
@@ -47,65 +47,65 @@ contract Verifier is IZKVerifierV2 {
4747

4848
// Groth16 alpha point in G1
4949
uint256 constant ALPHA_X =
50-
19681918582342826141927615585844819827950494091197079841581098590160509489088;
50+
12953796731566255356153533186899970596541789506787316310421265866460204452345;
5151
uint256 constant ALPHA_Y =
52-
18976290249472753264792873488771466812990993964894861063003977176791880491271;
52+
16108099332627179116882890117640860610766253379177782725877946988741043002151;
5353

5454
// Groth16 beta point in G2 in powers of i
5555
uint256 constant BETA_NEG_X_0 =
56-
17542740552152507448113209307107151415915067720344615090625491194497459342657;
56+
7189998629544061358868906102425391182345467937747171889044260956112296857453;
5757
uint256 constant BETA_NEG_X_1 =
58-
7391419840357209888406550113304609596117324320456425532340186750677647200951;
58+
11715211044976611849279736941659181461607821837429796658922621107593979258018;
5959
uint256 constant BETA_NEG_Y_0 =
60-
19792144694189938307894275195643141100067567927017820917795773938883367365412;
60+
21619939555605977664462722857628766746010558584894478667635551317055122810048;
6161
uint256 constant BETA_NEG_Y_1 =
62-
17211163405892785765064384698545439693511041026525583483293852246253094999960;
62+
17744148816587107869967191160344383643814015065165838706210713825793780643664;
6363

6464
// Groth16 gamma point in G2 in powers of i
6565
uint256 constant GAMMA_NEG_X_0 =
66-
18606218405301761142065379515313210013062685838824185304765852768028043703753;
66+
3203739780556455486614737616951770238449562962366174174415509385502339079134;
6767
uint256 constant GAMMA_NEG_X_1 =
68-
14540190418613230568675456016157166803361906410442369269514923787931816842661;
68+
330365480594874048579972851352786169022705988981774516328112713209916814425;
6969
uint256 constant GAMMA_NEG_Y_0 =
70-
8951288781929330311740771353182492599878185290969923949343519917796557268219;
70+
20727415115882681892016430268352505550338140930514103693522477672680520482110;
7171
uint256 constant GAMMA_NEG_Y_1 =
72-
8812741715039891617796654796990655544152364726104502685064434338923152748332;
72+
11770494869568371860365301978617470999730178637197214918443012817597339833626;
7373

7474
// Groth16 delta point in G2 in powers of i
7575
uint256 constant DELTA_NEG_X_0 =
76-
4060446808760699692477462845230990229944734548192291022910719993807902355759;
76+
144471853326950176158652078814987832244858457888532278798444997831177703256;
7777
uint256 constant DELTA_NEG_X_1 =
78-
17803970575871171031178686612122420011629668206026599803865929512658387807614;
78+
11723967339734259367269684565753317343894480284660483851808778513760163502167;
7979
uint256 constant DELTA_NEG_Y_0 =
80-
17124643930680839105590130418783735638684807807530957846654257326870483890070;
80+
8658017305463622670988550192886929502068646694881738953533949013510868981849;
8181
uint256 constant DELTA_NEG_Y_1 =
82-
7629814864078422326695261874116750521593226108645261491403040533513921542483;
82+
14970547642275722192880833497617759418334101954226638914501320639527882466979;
8383

8484
// Constant and public input points
8585
uint256 constant CONSTANT_X =
86-
18676861125246766292059080199576268981667767278300819763274799276376054409743;
86+
468243475977942096739227064799809074577932864561864594431724289332044119393;
8787
uint256 constant CONSTANT_Y =
88-
5269797328666185490526867808814966151140271775451395274640052553630677159076;
88+
12026957193107468267989691684356505173830039075560970134183365962992276088502;
8989
uint256 constant PUB_0_X =
90-
3010349418202885908760025883515590778403141726894708222433169071368055690912;
90+
4273127142915912066836331589937887852131041396580330861495976561450995509060;
9191
uint256 constant PUB_0_Y =
92-
20724571387755619214201948546999886629454427058875835531981815961969686023639;
92+
20311891790436735379947440583419330671207702790700221333652972975201502172109;
9393
uint256 constant PUB_1_X =
94-
1718980496599153571806495443921791801530740535933073284474040850386158191735;
94+
5867078984367927991529260476370712193826388223706691841033290533650191497842;
9595
uint256 constant PUB_1_Y =
96-
3288376032837046783397899352143814445169932711782482341330476711768756263890;
96+
15457584854730416542120021991798916984793483604514831168874602434669080770632;
9797
uint256 constant PUB_2_X =
98-
9266521894078168597926726825960443668976816125222306871429246198851182099011;
98+
6073935183581261599921354767516829294802045150352674700000707907321520444286;
9999
uint256 constant PUB_2_Y =
100-
9416966066664703605394453818829209487654794520205974695819389893969431707374;
100+
19421513883482432722033354055257568460031664693915650865773106969145220560478;
101101
uint256 constant PUB_3_X =
102-
13194582768609510874189454527180276310818912484460263820189470814556014162264;
102+
6573761322005933095907247349767854226263237757268335098982485126002570113042;
103103
uint256 constant PUB_3_Y =
104-
15983647339013447433771242507224193645257463334651420839328305715367829062538;
104+
21648292561695958729986475933727235437209737383625151779025875934553286731278;
105105
uint256 constant PUB_4_X =
106-
13160686484300787492313686811371534896624215839999346591796239441200125629208;
106+
7850217296098862761033756178241744898548923761706289522462295413515747119164;
107107
uint256 constant PUB_4_Y =
108-
11709584278193617231017776985640196897412209200566866495381859539145549732339;
108+
15481433110471107159567305060748336299937224568483713663114311452391215471632;
109109

110110
/// Compute the public input linear combination.
111111
/// @notice Reverts with PublicInputNotInField if the input is not in the field.

evm/tests/src/Verifier.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ contract VerifierTests {
77

88
function testVerifier_ok() public {
99
new Verifier().verifyZKP(
10-
0x0472116C575F0FECF44ED4F91C34E9E7B67CE8C911FC67F304C2B804330B61F0,
11-
0x0472116C575F0FECF44ED4F91C34E9E7B67CE8C911FC67F304C2B804330B61F0,
12-
hex"650802113E0200000000000022480A20DFAD1A5E2BB2B94BD7ED5F4F85199E0DDD95FB4687CFBF19B36865845BD16E20122408011220E32B1FA520CE4F9D0C1A2C80D51FB1F09B9C241101BE70D5CE0DC0F11B009863320E756E696F6E2D6465766E65742D31",
13-
hex"19EB187C4EA70DA41CE1C2E9C81D7F4ACC9B8CD85A98AD59A64BD9D820A1D4E41DA150358EC5AFCBA7407D66AFABD59B1B92095D6A797572FAE6FE9C9A500E7C284C0AF8310181C072C1002961BE007DFC68DFDBD9CCF930410153829DA0E00D20ECDCE1DF5674D69A70BFB0891CE61888AADC6B362E27C6E4C9D1905ED327402EEE2EB635235068CBCBAB909D9A14A8992E74DE17D69269FC60CC448A832F8E1BCA6C3426A79029508AEE21DBB718F016FEC33A0A500EA14A05E3E19548634F04011075515FF876980559B120DC247A190BF699C2BA19ECDA92220AADAF3F5A1D502B8552BCC4BBDBA3C53EA39FAA5D6A7D23E06AE8F52AEECCED971D7D353613F7C750995DDD6BCCBB3E3185CF5B53EADAA6FA412665A0910FF709E49CFDFB0530B479EE5F0774588EE7397F7E050A9F4C87DB7989E2557E76353BF98CF7B922EB5DBE6D66AEA64C33AF7D6469BF3EFD5ACA10936CED35DAE692D489AAF8C2"
10+
0x09539669AC74E3530F2782443258734DABAC8B8E036ECB9BC378361016892156,
11+
0x09539669AC74E3530F2782443258734DABAC8B8E036ECB9BC378361016892156,
12+
hex"650802113E0200000000000022480A20B8C88CE47A2AC003E6736975F3AE14517A07E90CBF3293C8E073CF45FB371E79122408011220AC08E7599D7F5682B77E2293928D68A956B2A73E917E5B9F0DBA64B0ED8C2E2F320E756E696F6E2D6465766E65742D31",
13+
hex"21D80AACFCA03DC2B84881E3EF1A73C25D2D088E48AA35764A6B4485A78354F021C90A4CBAAB731658D13CE5152F147DF1734F0196031DAF918BF06DAEA1A4E9082959B87795E28482B4FE13AD4B777F9A2D4BFBC8C3FF2640A5DB5619A8F2DA04D6037DAEA584F0C93EDC769859BE695493F48813E491540C37587C2C3214490AE2C9DC087D8039CAF2BD181E289D60EA9AC8B4BF3411A9F9888DC9250525DD055143FE81924CF683CF8381167431A8CB0C984C9DB2BA13D6C9B2374FFD7323052586453C7C06E234B861E9E212EB4A8DF470BD9ADCDB759FED40E62004ECB8210E3A53A0D1F570552C5118521943BC2CC4BB1DA8A5877667A2800D4DF62665304E914F6631B3CE27C88F21E1E8FFAC6C0512D62AE00BEEA79F649BD6E139BD254011571644878C8A72D167D82B5F409360209E1B8E146457C1893769383F4F2F9C0E2EF22885F92672277AF244840CA6EB5298D74E73334BD88360D6B33681"
1414
);
1515
}
1616
}

flake.nix

+18-17
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,22 @@
397397

398398

399399
treefmt =
400-
# let
401-
# prettier-solidity = pkgs.buildNpmPackage {
402-
# name = "prettier-plugin-solidity";
403-
# version = "1.1.3";
404-
# nativeBuildInputs = [ pkgs.pkg-config pkgs.python3 ];
405-
# src = pkgs.fetchFromGitHub {
406-
# owner = "prettier-solidity";
407-
# repo = "prettier-plugin-solidity";
408-
# rev = "0f0b31bd1d76626cad4ce576d89088ef23ad87f3";
409-
# hash = "sha256-zodOB5hARb7Jrb6d4gqmBKEFKUg0ZNZKbTN7H4vJk2w=";
410-
# };
411-
# npmInstallFlags = "--include=dev";
412-
# npmDepsHash =
413-
# "sha256-Hzc4j9icNxTJNNaZ3PrmLKcUVR26nu4KqLireP4WmZM=";
414-
# };
415-
# in
400+
let
401+
prettier-solidity = pkgs.buildNpmPackage {
402+
name = "prettier-plugin-solidity";
403+
version = "1.1.3";
404+
nativeBuildInputs = [ pkgs.pkg-config pkgs.python3 ];
405+
src = pkgs.fetchFromGitHub {
406+
owner = "prettier-solidity";
407+
repo = "prettier-plugin-solidity";
408+
rev = "0f0b31bd1d76626cad4ce576d89088ef23ad87f3";
409+
hash = "sha256-zodOB5hARb7Jrb6d4gqmBKEFKUg0ZNZKbTN7H4vJk2w=";
410+
};
411+
npmInstallFlags = "--include=dev";
412+
npmDepsHash =
413+
"sha256-Hzc4j9icNxTJNNaZ3PrmLKcUVR26nu4KqLireP4WmZM=";
414+
};
415+
in
416416
{
417417
projectRootFile = "flake.nix";
418418
programs = {
@@ -438,7 +438,7 @@
438438
global.excludes = [ "**/vendor/**" ];
439439
formatter.prettier = {
440440
# TODO: Use settings.pluginSearchDirs
441-
# options = [ "--write" ] ++ (if pkgs.stdenv.isLinux then [ "--plugin-search-dir=${prettier-solidity}/lib" ] else [ ]);
441+
options = [ "--write" ] ++ (if pkgs.stdenv.isLinux then [ "--plugin-search-dir=${prettier-solidity}/lib" ] else [ ]);
442442
includes = [
443443
"*.css"
444444
"*.html"
@@ -455,6 +455,7 @@
455455
"*.d.ts"
456456
"*.yaml"
457457
"*.yml"
458+
"*.sol"
458459
];
459460
};
460461
};

galoisd/galoisd.nix

+72-67
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,82 @@
11
{ ... }: {
22
perSystem = { self', pkgs, proto, goPkgs, ... }: {
3-
packages =
4-
{
5-
galoisd = goPkgs.buildGoModule ({
6-
name = "galoisd";
7-
src = ./.;
8-
vendorHash = null;
9-
doCheck = false;
10-
meta = {
11-
mainProgram = "galoisd";
12-
};
13-
} // (if pkgs.stdenv.isLinux then {
14-
nativeBuildInputs = [ pkgs.musl ];
15-
CGO_ENABLED = 0;
16-
ldflags = [
17-
"-linkmode external"
18-
"-extldflags '-static -L${pkgs.musl}/lib -s -w'"
19-
];
20-
} else { }));
3+
packages = {
4+
galoisd-coverage =
5+
pkgs.runCommand
6+
"galoisd-coverage"
7+
{ buildInputs = [ goPkgs.go ]; }
8+
''
9+
HOME="$(mktemp -d)"
10+
cd ${./.}
11+
go test -v -coverpkg=./... -coverprofile=$out ./...
12+
'';
2113

22-
galoisd-image =
23-
pkgs.dockerTools.buildImage {
24-
name = "${self'.packages.galoisd.name}-image";
25-
copyToRoot = pkgs.buildEnv {
26-
name = "image-root";
27-
paths = [ pkgs.coreutils-full pkgs.cacert ];
28-
pathsToLink = [ "/bin" ];
29-
};
30-
config = {
31-
Entrypoint = [ (pkgs.lib.getExe self'.packages.galoisd) ];
32-
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
33-
};
34-
};
14+
galoisd = goPkgs.buildGoModule ({
15+
name = "galoisd";
16+
src = ./.;
17+
vendorHash = null;
18+
meta = { mainProgram = "galoisd"; };
19+
} // (if pkgs.stdenv.isLinux then {
20+
nativeBuildInputs = [ pkgs.musl ];
21+
CGO_ENABLED = 0;
22+
ldflags = [
23+
"-linkmode external"
24+
"-extldflags '-static -L${pkgs.musl}/lib -s -w'"
25+
];
26+
} else
27+
{ }));
3528

29+
galoisd-image = pkgs.dockerTools.buildImage {
30+
name = "${self'.packages.galoisd.name}-image";
31+
copyToRoot = pkgs.buildEnv {
32+
name = "image-root";
33+
paths = [ pkgs.coreutils-full pkgs.cacert ];
34+
pathsToLink = [ "/bin" ];
35+
};
36+
config = {
37+
Entrypoint = [ (pkgs.lib.getExe self'.packages.galoisd) ];
38+
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
39+
};
40+
};
3641

37-
generate-prover-proto = pkgs.writeShellApplication {
38-
name = "generate-prover-proto";
39-
runtimeInputs =
40-
[ pkgs.protobuf pkgs.protoc-gen-go pkgs.protoc-gen-go-grpc ];
42+
generate-prover-proto = pkgs.writeShellApplication {
43+
name = "generate-prover-proto";
44+
runtimeInputs =
45+
[ pkgs.protobuf pkgs.protoc-gen-go pkgs.protoc-gen-go-grpc ];
46+
text = ''
47+
find ${proto.galoisd} -type f -regex ".*proto" |\
48+
while read -r file; do
49+
echo "Generating $file"
50+
protoc \
51+
-I"${proto.cometbls}/proto" \
52+
-I"${proto.gogoproto}" \
53+
-I"${proto.galoisd}" \
54+
--go_out=./grpc --go_opt=paths=source_relative \
55+
--go-grpc_out=./grpc --go-grpc_opt=paths=source_relative \
56+
"$file"
57+
done
58+
'';
59+
};
60+
61+
download-circuit =
62+
let
63+
files = pkgs.writeText "files.txt" ''
64+
/vk.bin
65+
/pk.bin
66+
/r1cs.bin
67+
'';
68+
in
69+
pkgs.writeShellApplication {
70+
name = "download-circuit";
71+
runtimeInputs = [ pkgs.rclone ];
4172
text = ''
42-
find ${proto.galoisd} -type f -regex ".*proto" |\
43-
while read -r file; do
44-
echo "Generating $file"
45-
protoc \
46-
-I"${proto.cometbls}/proto" \
47-
-I"${proto.gogoproto}" \
48-
-I"${proto.galoisd}" \
49-
--go_out=./grpc --go_opt=paths=source_relative \
50-
--go-grpc_out=./grpc --go-grpc_opt=paths=source_relative \
51-
"$file"
52-
done
73+
if [[ "$#" -ne 1 ]]; then
74+
echo "Invalid arguments, must be: download-circuit [path]"
75+
exit 1
76+
fi
77+
rclone --progress --no-traverse --http-url "https://circuit.cryptware.io" copy :http:/ "$1" --files-from=${files}
5378
'';
5479
};
55-
56-
download-circuit =
57-
let
58-
files = pkgs.writeText "files.txt" ''
59-
/vk.bin
60-
/pk.bin
61-
/r1cs.bin
62-
'';
63-
in
64-
pkgs.writeShellApplication {
65-
name = "download-circuit";
66-
runtimeInputs = [ pkgs.rclone ];
67-
text = ''
68-
if [[ "$#" -ne 1 ]]; then
69-
echo "Invalid arguments, must be: download-circuit [path]"
70-
exit 1
71-
fi
72-
rclone --progress --no-traverse --http-url "https://circuit.cryptware.io" copy :http:/ "$1" --files-from=${files}
73-
'';
74-
};
75-
};
80+
};
7681
};
7782
}

galoisd/go.mod

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ require (
88
cosmossdk.io/math v1.2.0
99
github.com/cometbft/cometbft v0.38.2
1010
github.com/consensys/gnark v0.7.2-0.20230418172633-f83323bdf138
11-
github.com/consensys/gnark-crypto v0.12.2-0.20231012161402-206544105834
11+
github.com/consensys/gnark-crypto v0.12.2-0.20231221171913-5d5eded6bb15
1212
github.com/cosmos/cosmos-sdk v0.50.2
13-
github.com/gogo/protobuf v1.3.2
1413
github.com/rs/zerolog v1.31.0
1514
github.com/spf13/cobra v1.7.0
1615
github.com/stretchr/testify v1.8.4
@@ -58,6 +57,7 @@ require (
5857
github.com/go-kit/kit v0.12.0 // indirect
5958
github.com/go-kit/log v0.2.1 // indirect
6059
github.com/go-logfmt/logfmt v0.6.0 // indirect
60+
github.com/gogo/protobuf v1.3.2 // indirect
6161
github.com/golang/glog v1.2.0 // indirect
6262
github.com/golang/protobuf v1.5.3 // indirect
6363
github.com/golang/snappy v0.0.4 // indirect
@@ -70,6 +70,8 @@ require (
7070
github.com/holiman/uint256 v1.2.3 // indirect
7171
github.com/iancoleman/strcase v0.3.0 // indirect
7272
github.com/inconshreveable/mousetrap v1.1.0 // indirect
73+
github.com/ingonyama-zk/icicle v0.0.0-20230928131117-97f0079e5c71 // indirect
74+
github.com/ingonyama-zk/iciclegnark v0.1.0 // indirect
7375
github.com/jmhodges/levigo v1.0.0 // indirect
7476
github.com/klauspost/compress v1.17.4 // indirect
7577
github.com/kr/pretty v0.3.1 // indirect
@@ -96,7 +98,7 @@ require (
9698
github.com/tendermint/go-amino v0.16.0 // indirect
9799
github.com/x448/float16 v0.8.4 // indirect
98100
go.etcd.io/bbolt v1.3.8 // indirect
99-
golang.org/x/crypto v0.16.0 // indirect
101+
golang.org/x/crypto v0.17.0 // indirect
100102
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
101103
golang.org/x/sync v0.3.0 // indirect
102104
golang.org/x/sys v0.15.0 // indirect
@@ -112,9 +114,9 @@ require (
112114

113115
replace (
114116
github.com/cometbft/cometbft => github.com/unionlabs/cometbls v0.0.0-20240111183309-e159e964fa07
115-
github.com/consensys/gnark => github.com/consensys/gnark v0.9.1-0.20231013131835-4ebcccd9c0a8
117+
github.com/consensys/gnark => github.com/consensys/gnark v0.9.2-0.20240115131420-34fdb0391653
116118
// Fork of gnark crypto until https://github.com/ConsenSys/gnark-crypto/pull/314 is merged
117-
github.com/consensys/gnark-crypto => github.com/unionlabs/gnark-crypto v0.0.0-20231016072529-15c0507b6578
119+
github.com/consensys/gnark-crypto => github.com/unionlabs/gnark-crypto v0.0.0-20240112093739-635c1b6963c6
118120
github.com/cosmos/cosmos-sdk => github.com/unionlabs/cosmos-sdk v0.0.0-20240111183419-b58f90f260ce
119121
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.11
120122
)

0 commit comments

Comments
 (0)