From b2b2ddd8aa546525d517f016f15f0ac05cc1c26e Mon Sep 17 00:00:00 2001 From: Gautam Botrel Date: Fri, 13 Sep 2024 10:48:39 -0500 Subject: [PATCH] feat: replace stats gob format with csv for easier diffs (#1276) * feat: replace stats gob format with csv for easier diffs * feat: add latest_stats.csv * fix: sort circuitNames to have deterministic output of stats * build: make linter happier --- backend/backend.go | 12 ++ doc.go | 10 +- internal/stats/generate/main.go | 28 ++-- internal/stats/latest.stats | Bin 2135 -> 0 bytes internal/stats/latest_stats.csv | 253 ++++++++++++++++++++++++++++++++ internal/stats/stats.go | 101 ++++++++----- internal/stats/stats_test.go | 4 +- 7 files changed, 356 insertions(+), 52 deletions(-) delete mode 100644 internal/stats/latest.stats create mode 100644 internal/stats/latest_stats.csv diff --git a/backend/backend.go b/backend/backend.go index 7c427e5825..5bcfc7bc20 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -48,6 +48,18 @@ func (id ID) String() string { } } +// IDFromString returns the ID of a proof system from its string representation +func IDFromString(s string) ID { + switch s { + case "groth16": + return GROTH16 + case "plonk": + return PLONK + default: + return UNKNOWN + } +} + // ProverOption defines option for altering the behavior of the prover in // Prove, ReadAndProve and IsSolved methods. See the descriptions of functions // returning instances of this type for implemented options. diff --git a/doc.go b/doc.go index e067f90998..02a9a13d57 100644 --- a/doc.go +++ b/doc.go @@ -26,5 +26,13 @@ var Version = semver.MustParse("0.11.0") // Curves return the curves supported by gnark func Curves() []ecc.ID { - return []ecc.ID{ecc.BN254, ecc.BLS12_377, ecc.BLS12_381, ecc.BW6_761, ecc.BLS24_315, ecc.BW6_633, ecc.BLS24_317} + return []ecc.ID{ + ecc.BN254, + ecc.BLS12_377, + ecc.BLS12_381, + ecc.BLS24_315, + ecc.BLS24_317, + ecc.BW6_761, + ecc.BW6_633, + } } diff --git a/internal/stats/generate/main.go b/internal/stats/generate/main.go index 251af22562..d1f73b7221 100644 --- a/internal/stats/generate/main.go +++ b/internal/stats/generate/main.go @@ -1,9 +1,11 @@ package main import ( + "bytes" "flag" "fmt" "log" + "os" "regexp" "sync" @@ -51,25 +53,23 @@ func main() { } wg.Wait() - fmt.Println("id,curve,backend,nbConstraints,nbWires") - for name, c := range snippets { - if r != nil && !r.MatchString(name) { - continue - } - ss := s.Stats[name] - for _, curve := range c.Curves { - for _, backendID := range backend.Implemented() { - cs := ss[backendID][stats.CurveIdx(curve)] - fmt.Printf("%s,%s,%s,%d,%d\n", name, curve, backendID, cs.NbConstraints, cs.NbInternalWires) - } - } + // write csv to buffer + var buf bytes.Buffer + if _, err := s.WriteTo(&buf); err != nil { + log.Fatal(err) } + // print csv + fmt.Println(buf.String()) + if *fSave { - const refPath = "../latest.stats" - if err := s.Save(refPath); err != nil { + const refPath = "../latest_stats.csv" + // write buffer to file + + if err := os.WriteFile(refPath, buf.Bytes(), 0600); err != nil { log.Fatal(err) } + log.Println("successfully saved new reference stats file", refPath) } diff --git a/internal/stats/latest.stats b/internal/stats/latest.stats deleted file mode 100644 index 5465b427c0206bcb56134c67669ff905a3259844..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2135 zcmbVNPiP!f9Dcv~lilnl-Pi^b3l)u6ghIEwZIT{5)cP-hkctEfC3G{J3})NSY@C@@ z^iX43J%~yU#Y)M+UZg~k;30<`B$N_@NDrkH2_=Vu9@-)$NbyhRt>5qMOfpMs4qf=Y z{pS1q-h1D?_q{in+9w8SwNC}LQ0;;cnc8{6^94b*X=>uuWpFW3v8MA3rYhf(5_(tjjsW|Wv~phG%=V5vkK7kI~WOIGPumC>qz|~lu-c9hu{)- z0PZnZ0C>b;DP+=%*x{RCn&-ft=F}gmMm!fc^6?V;I9qj;Zazx(Sc6!Nr)9C)RRoLG z;Q=L9!|X~dj$U1?J{yYFZXi_`Yp!Ej7Hd8TrI~*zAu%R-D-@d;3B`srqT?~^+@LXy zHA?+}DblL|e1g)LH1$u!`~>jSkFfm;z^FC_1x{4V4Ar2}uCm{tv_U7JRHzo)mS z@m?Ahixgb?`=J_!yVC}p{$d?%-)}7u**tD}=f|;Q%oAasU{|IXE@LAw-&YZlF>*Tb<0ub)|5v z(~b?^vXk1y&W+f;-Nx~0qz;!UdCC{U*i zJFiYz6FXR)G9zSCi=lCouvh(*aj!?B!4&x3^!CQY@y3xnxx&F%nSuhE`9?KNWxTCx z@-5usvECGz^PLnl_nzWH{^5Rl`g|7!?Hij^idVniJ7v3-cvpizlRGvTY{$IHis$2t zAASrUe~D-$3D)4hWA(qrr#p2LhOAdY13F+Mrm;+P41kZ@|1h|K^aW1A&pNv>tP%eK Dh3ZhW diff --git a/internal/stats/latest_stats.csv b/internal/stats/latest_stats.csv new file mode 100644 index 0000000000..fbc129594e --- /dev/null +++ b/internal/stats/latest_stats.csv @@ -0,0 +1,253 @@ +circuit,curve,backend,nbConstraints,nbWires +api/AssertIsLessOrEqual,bn254,groth16,1523,1367 +api/AssertIsLessOrEqual,bls12_377,groth16,1517,1349 +api/AssertIsLessOrEqual,bls12_381,groth16,1529,1405 +api/AssertIsLessOrEqual,bls24_315,groth16,1517,1375 +api/AssertIsLessOrEqual,bls24_317,groth16,1529,1376 +api/AssertIsLessOrEqual,bw6_761,groth16,2265,2020 +api/AssertIsLessOrEqual,bw6_633,groth16,1893,1722 +api/AssertIsLessOrEqual,bn254,plonk,3199,3043 +api/AssertIsLessOrEqual,bls12_377,plonk,3199,3031 +api/AssertIsLessOrEqual,bls12_381,plonk,3179,3055 +api/AssertIsLessOrEqual,bls24_315,plonk,3173,3031 +api/AssertIsLessOrEqual,bls24_317,plonk,3208,3055 +api/AssertIsLessOrEqual,bw6_761,plonk,4764,4519 +api/AssertIsLessOrEqual,bw6_633,plonk,3946,3775 +api/AssertIsLessOrEqual/constant_bound_64_bits,bn254,groth16,587,353 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls12_377,groth16,588,339 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls12_381,groth16,611,387 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls24_315,groth16,600,365 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls24_317,groth16,610,358 +api/AssertIsLessOrEqual/constant_bound_64_bits,bw6_761,groth16,883,511 +api/AssertIsLessOrEqual/constant_bound_64_bits,bw6_633,groth16,755,461 +api/AssertIsLessOrEqual/constant_bound_64_bits,bn254,plonk,994,760 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls12_377,plonk,1006,757 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls12_381,plonk,987,763 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls24_315,plonk,992,757 +api/AssertIsLessOrEqual/constant_bound_64_bits,bls24_317,plonk,1015,763 +api/AssertIsLessOrEqual/constant_bound_64_bits,bw6_761,plonk,1501,1129 +api/AssertIsLessOrEqual/constant_bound_64_bits,bw6_633,plonk,1237,943 +api/IsZero,bn254,groth16,2,2 +api/IsZero,bls12_377,groth16,2,2 +api/IsZero,bls12_381,groth16,2,2 +api/IsZero,bls24_315,groth16,2,2 +api/IsZero,bls24_317,groth16,2,2 +api/IsZero,bw6_761,groth16,2,2 +api/IsZero,bw6_633,groth16,2,2 +api/IsZero,bn254,plonk,2,2 +api/IsZero,bls12_377,plonk,2,2 +api/IsZero,bls12_381,plonk,2,2 +api/IsZero,bls24_315,plonk,2,2 +api/IsZero,bls24_317,plonk,2,2 +api/IsZero,bw6_761,plonk,2,2 +api/IsZero,bw6_633,plonk,2,2 +api/Lookup2,bn254,groth16,5,3 +api/Lookup2,bls12_377,groth16,5,3 +api/Lookup2,bls12_381,groth16,5,3 +api/Lookup2,bls24_315,groth16,5,3 +api/Lookup2,bls24_317,groth16,5,3 +api/Lookup2,bw6_761,groth16,5,3 +api/Lookup2,bw6_633,groth16,5,3 +api/Lookup2,bn254,plonk,12,10 +api/Lookup2,bls12_377,plonk,12,10 +api/Lookup2,bls12_381,plonk,12,10 +api/Lookup2,bls24_315,plonk,12,10 +api/Lookup2,bls24_317,plonk,12,10 +api/Lookup2,bw6_761,plonk,12,10 +api/Lookup2,bw6_633,plonk,12,10 +hash/mimc,bn254,groth16,330,330 +hash/mimc,bls12_377,groth16,310,310 +hash/mimc,bls12_381,groth16,333,333 +hash/mimc,bls24_315,groth16,327,327 +hash/mimc,bls24_317,groth16,364,364 +hash/mimc,bw6_761,groth16,489,489 +hash/mimc,bw6_633,groth16,408,408 +hash/mimc,bn254,plonk,441,441 +hash/mimc,bls12_377,plonk,373,373 +hash/mimc,bls12_381,plonk,445,445 +hash/mimc,bls24_315,plonk,437,437 +hash/mimc,bls24_317,plonk,456,456 +hash/mimc,bw6_761,plonk,653,653 +hash/mimc,bw6_633,plonk,545,545 +math/bits.ToBinary,bn254,groth16,508,353 +math/bits.ToBinary,bls12_377,groth16,506,339 +math/bits.ToBinary,bls12_381,groth16,510,387 +math/bits.ToBinary,bls24_315,groth16,506,365 +math/bits.ToBinary,bls24_317,groth16,510,358 +math/bits.ToBinary,bw6_761,groth16,755,511 +math/bits.ToBinary,bw6_633,groth16,631,461 +math/bits.ToBinary,bn254,plonk,915,760 +math/bits.ToBinary,bls12_377,plonk,924,757 +math/bits.ToBinary,bls12_381,plonk,886,763 +math/bits.ToBinary,bls24_315,plonk,898,757 +math/bits.ToBinary,bls24_317,plonk,915,763 +math/bits.ToBinary,bw6_761,plonk,1373,1129 +math/bits.ToBinary,bw6_633,plonk,1113,943 +math/bits.ToBinary/unconstrained,bn254,groth16,354,353 +math/bits.ToBinary/unconstrained,bls12_377,groth16,340,339 +math/bits.ToBinary/unconstrained,bls12_381,groth16,388,387 +math/bits.ToBinary/unconstrained,bls24_315,groth16,366,365 +math/bits.ToBinary/unconstrained,bls24_317,groth16,359,358 +math/bits.ToBinary/unconstrained,bw6_761,groth16,512,511 +math/bits.ToBinary/unconstrained,bw6_633,groth16,462,461 +math/bits.ToBinary/unconstrained,bn254,plonk,761,760 +math/bits.ToBinary/unconstrained,bls12_377,plonk,758,757 +math/bits.ToBinary/unconstrained,bls12_381,plonk,764,763 +math/bits.ToBinary/unconstrained,bls24_315,plonk,758,757 +math/bits.ToBinary/unconstrained,bls24_317,plonk,764,763 +math/bits.ToBinary/unconstrained,bw6_761,plonk,1130,1129 +math/bits.ToBinary/unconstrained,bw6_633,plonk,944,943 +math/bits.ToTernary,bn254,groth16,484,483 +math/bits.ToTernary,bls12_377,groth16,481,480 +math/bits.ToTernary,bls12_381,groth16,484,483 +math/bits.ToTernary,bls24_315,groth16,481,480 +math/bits.ToTernary,bls24_317,groth16,484,483 +math/bits.ToTernary,bw6_761,groth16,715,714 +math/bits.ToTernary,bw6_633,groth16,598,597 +math/bits.ToTernary,bn254,plonk,966,965 +math/bits.ToTernary,bls12_377,plonk,960,959 +math/bits.ToTernary,bls12_381,plonk,966,965 +math/bits.ToTernary,bls24_315,plonk,960,959 +math/bits.ToTernary,bls24_317,plonk,966,965 +math/bits.ToTernary,bw6_761,plonk,1428,1427 +math/bits.ToTernary,bw6_633,plonk,1194,1193 +math/bits.ToTernary/unconstrained,bn254,groth16,1,161 +math/bits.ToTernary/unconstrained,bls12_377,groth16,1,160 +math/bits.ToTernary/unconstrained,bls12_381,groth16,1,161 +math/bits.ToTernary/unconstrained,bls24_315,groth16,1,160 +math/bits.ToTernary/unconstrained,bls24_317,groth16,1,161 +math/bits.ToTernary/unconstrained,bw6_761,groth16,1,238 +math/bits.ToTernary/unconstrained,bw6_633,groth16,1,199 +math/bits.ToTernary/unconstrained,bn254,plonk,161,321 +math/bits.ToTernary/unconstrained,bls12_377,plonk,160,319 +math/bits.ToTernary/unconstrained,bls12_381,plonk,161,321 +math/bits.ToTernary/unconstrained,bls24_315,plonk,160,319 +math/bits.ToTernary/unconstrained,bls24_317,plonk,161,321 +math/bits.ToTernary/unconstrained,bw6_761,plonk,238,475 +math/bits.ToTernary/unconstrained,bw6_633,plonk,199,397 +math/emulated/secp256k1_64,bn254,groth16,1070,1950 +math/emulated/secp256k1_64,bls12_377,groth16,1070,1950 +math/emulated/secp256k1_64,bls12_381,groth16,1070,1950 +math/emulated/secp256k1_64,bls24_315,groth16,1070,1950 +math/emulated/secp256k1_64,bls24_317,groth16,1070,1950 +math/emulated/secp256k1_64,bw6_761,groth16,1070,1950 +math/emulated/secp256k1_64,bw6_633,groth16,1070,1950 +math/emulated/secp256k1_64,bn254,plonk,4497,4388 +math/emulated/secp256k1_64,bls12_377,plonk,4497,4388 +math/emulated/secp256k1_64,bls12_381,plonk,4497,4388 +math/emulated/secp256k1_64,bls24_315,plonk,4497,4388 +math/emulated/secp256k1_64,bls24_317,plonk,4497,4388 +math/emulated/secp256k1_64,bw6_761,plonk,4497,4388 +math/emulated/secp256k1_64,bw6_633,plonk,4497,4388 +pairing_bls12377,bn254,groth16,0,0 +pairing_bls12377,bls12_377,groth16,0,0 +pairing_bls12377,bls12_381,groth16,0,0 +pairing_bls12377,bls24_315,groth16,0,0 +pairing_bls12377,bls24_317,groth16,0,0 +pairing_bls12377,bw6_761,groth16,11236,11236 +pairing_bls12377,bw6_633,groth16,0,0 +pairing_bls12377,bn254,plonk,0,0 +pairing_bls12377,bls12_377,plonk,0,0 +pairing_bls12377,bls12_381,plonk,0,0 +pairing_bls12377,bls24_315,plonk,0,0 +pairing_bls12377,bls24_317,plonk,0,0 +pairing_bls12377,bw6_761,plonk,51280,51280 +pairing_bls12377,bw6_633,plonk,0,0 +pairing_bls12381,bn254,groth16,1429070,2382640 +pairing_bls12381,bls12_377,groth16,0,0 +pairing_bls12381,bls12_381,groth16,0,0 +pairing_bls12381,bls24_315,groth16,0,0 +pairing_bls12381,bls24_317,groth16,0,0 +pairing_bls12381,bw6_761,groth16,0,0 +pairing_bls12381,bw6_633,groth16,0,0 +pairing_bls12381,bn254,plonk,5629807,5285448 +pairing_bls12381,bls12_377,plonk,0,0 +pairing_bls12381,bls12_381,plonk,0,0 +pairing_bls12381,bls24_315,plonk,0,0 +pairing_bls12381,bls24_317,plonk,0,0 +pairing_bls12381,bw6_761,plonk,0,0 +pairing_bls12381,bw6_633,plonk,0,0 +pairing_bls24315,bn254,groth16,0,0 +pairing_bls24315,bls12_377,groth16,0,0 +pairing_bls24315,bls12_381,groth16,0,0 +pairing_bls24315,bls24_315,groth16,0,0 +pairing_bls24315,bls24_317,groth16,0,0 +pairing_bls24315,bw6_761,groth16,0,0 +pairing_bls24315,bw6_633,groth16,28928,28928 +pairing_bls24315,bn254,plonk,0,0 +pairing_bls24315,bls12_377,plonk,0,0 +pairing_bls24315,bls12_381,plonk,0,0 +pairing_bls24315,bls24_315,plonk,0,0 +pairing_bls24315,bls24_317,plonk,0,0 +pairing_bls24315,bw6_761,plonk,0,0 +pairing_bls24315,bw6_633,plonk,141249,141249 +pairing_bn254,bn254,groth16,969638,1614382 +pairing_bn254,bls12_377,groth16,0,0 +pairing_bn254,bls12_381,groth16,0,0 +pairing_bn254,bls24_315,groth16,0,0 +pairing_bn254,bls24_317,groth16,0,0 +pairing_bn254,bw6_761,groth16,0,0 +pairing_bn254,bw6_633,groth16,0,0 +pairing_bn254,bn254,plonk,3798583,3560759 +pairing_bn254,bls12_377,plonk,0,0 +pairing_bn254,bls12_381,plonk,0,0 +pairing_bn254,bls24_315,plonk,0,0 +pairing_bn254,bls24_317,plonk,0,0 +pairing_bn254,bw6_761,plonk,0,0 +pairing_bn254,bw6_633,plonk,0,0 +pairing_bw6761,bn254,groth16,3014749,4979960 +pairing_bw6761,bls12_377,groth16,0,0 +pairing_bw6761,bls12_381,groth16,0,0 +pairing_bw6761,bls24_315,groth16,0,0 +pairing_bw6761,bls24_317,groth16,0,0 +pairing_bw6761,bw6_761,groth16,0,0 +pairing_bw6761,bw6_633,groth16,0,0 +pairing_bw6761,bn254,plonk,11486969,10777222 +pairing_bw6761,bls12_377,plonk,0,0 +pairing_bw6761,bls12_381,plonk,0,0 +pairing_bw6761,bls24_315,plonk,0,0 +pairing_bw6761,bls24_317,plonk,0,0 +pairing_bw6761,bw6_761,plonk,0,0 +pairing_bw6761,bw6_633,plonk,0,0 +scalar_mul_G1_bn254,bn254,groth16,99938,159576 +scalar_mul_G1_bn254,bls12_377,groth16,0,0 +scalar_mul_G1_bn254,bls12_381,groth16,0,0 +scalar_mul_G1_bn254,bls24_315,groth16,0,0 +scalar_mul_G1_bn254,bls24_317,groth16,0,0 +scalar_mul_G1_bn254,bw6_761,groth16,0,0 +scalar_mul_G1_bn254,bw6_633,groth16,0,0 +scalar_mul_G1_bn254,bn254,plonk,381115,356144 +scalar_mul_G1_bn254,bls12_377,plonk,0,0 +scalar_mul_G1_bn254,bls12_381,plonk,0,0 +scalar_mul_G1_bn254,bls24_315,plonk,0,0 +scalar_mul_G1_bn254,bls24_317,plonk,0,0 +scalar_mul_G1_bn254,bw6_761,plonk,0,0 +scalar_mul_G1_bn254,bw6_633,plonk,0,0 +scalar_mul_P256,bn254,groth16,186380,301997 +scalar_mul_P256,bls12_377,groth16,0,0 +scalar_mul_P256,bls12_381,groth16,0,0 +scalar_mul_P256,bls24_315,groth16,0,0 +scalar_mul_P256,bls24_317,groth16,0,0 +scalar_mul_P256,bw6_761,groth16,0,0 +scalar_mul_P256,bw6_633,groth16,0,0 +scalar_mul_P256,bn254,plonk,737681,687661 +scalar_mul_P256,bls12_377,plonk,0,0 +scalar_mul_P256,bls12_381,plonk,0,0 +scalar_mul_P256,bls24_315,plonk,0,0 +scalar_mul_P256,bls24_317,plonk,0,0 +scalar_mul_P256,bw6_761,plonk,0,0 +scalar_mul_P256,bw6_633,plonk,0,0 +scalar_mul_secp256k1,bn254,groth16,100948,161209 +scalar_mul_secp256k1,bls12_377,groth16,0,0 +scalar_mul_secp256k1,bls12_381,groth16,0,0 +scalar_mul_secp256k1,bls24_315,groth16,0,0 +scalar_mul_secp256k1,bls24_317,groth16,0,0 +scalar_mul_secp256k1,bw6_761,groth16,0,0 +scalar_mul_secp256k1,bw6_633,groth16,0,0 +scalar_mul_secp256k1,bn254,plonk,385109,359843 +scalar_mul_secp256k1,bls12_377,plonk,0,0 +scalar_mul_secp256k1,bls12_381,plonk,0,0 +scalar_mul_secp256k1,bls24_315,plonk,0,0 +scalar_mul_secp256k1,bls24_317,plonk,0,0 +scalar_mul_secp256k1,bw6_761,plonk,0,0 +scalar_mul_secp256k1,bw6_633,plonk,0,0 diff --git a/internal/stats/stats.go b/internal/stats/stats.go index bb3d9e4f4f..75db39af06 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -1,9 +1,12 @@ package stats import ( - "encoding/gob" + "encoding/csv" "fmt" + "io" "os" + "sort" + "strconv" "sync" "github.com/consensys/gnark" @@ -16,27 +19,6 @@ import ( const nbCurves = 7 -func CurveIdx(curve ecc.ID) int { - switch curve { - case ecc.BN254: - return 0 - case ecc.BLS12_377: - return 1 - case ecc.BLS12_381: - return 2 - case ecc.BLS24_315: - return 3 - case ecc.BW6_761: - return 4 - case ecc.BW6_633: - return 5 - case ecc.BLS24_317: - return 6 - default: - panic("not implemented") - } -} - func init() { if nbCurves != len(gnark.Curves()) { panic("expected nbCurves == len(gnark.Curves())") @@ -49,16 +31,45 @@ func NewGlobalStats() *globalStats { } } -func (s *globalStats) Save(path string) error { - fStats, err := os.Create(path) //#nosec G304 -- ignoring internal package s - if err != nil { - return err +func (s *globalStats) WriteTo(w io.Writer) (int64, error) { + csvWriter := csv.NewWriter(w) + + // write header + if err := csvWriter.Write([]string{"circuit", "curve", "backend", "nbConstraints", "nbWires"}); err != nil { + return 0, err } - encoder := gob.NewEncoder(fStats) - err = encoder.Encode(s.Stats) - _ = fStats.Close() - return err + // sort circuits names to have a deterministic output + var circuitNames []string + for circuitName := range s.Stats { + circuitNames = append(circuitNames, circuitName) + } + + sort.Strings(circuitNames) + + // write data + for _, circuitName := range circuitNames { + innerStats := s.Stats[circuitName] + for backendID, s := range innerStats { + if backendID == 0 { + continue + } + backend := backend.ID(backendID).String() + for curveIdx, stats := range s { + if curveIdx == 0 { + continue + } + curve := ecc.ID(curveIdx).String() + + if err := csvWriter.Write([]string{circuitName, curve, backend, strconv.Itoa(stats.NbConstraints), strconv.Itoa(stats.NbInternalWires)}); err != nil { + return 0, err + } + } + } + } + + csvWriter.Flush() + return 0, nil } func (s *globalStats) Load(path string) error { @@ -67,10 +78,30 @@ func (s *globalStats) Load(path string) error { return err } - decoder := gob.NewDecoder(fStats) - err = decoder.Decode(&s.Stats) - _ = fStats.Close() - return err + defer fStats.Close() + + csvReader := csv.NewReader(fStats) + records, err := csvReader.ReadAll() + if err != nil { + return err + } + + s.Stats = make(map[string][backend.PLONK + 1][nbCurves + 1]snippetStats) + + for _, record := range records { + // we don't do validation here, we assume the file is correct;; + circuitName := record[0] + curveID, _ := ecc.IDFromString(record[1]) + backendID := backend.IDFromString(record[2]) + nbConstraints, _ := strconv.Atoi(record[3]) + nbWires, _ := strconv.Atoi(record[4]) + + rs := s.Stats[circuitName] + rs[backendID][curveID] = snippetStats{nbConstraints, nbWires} + s.Stats[circuitName] = rs + } + + return nil } func NewSnippetStats(curve ecc.ID, backendID backend.ID, circuit frontend.Circuit) (snippetStats, error) { @@ -101,7 +132,7 @@ func (s *globalStats) Add(curve ecc.ID, backendID backend.ID, cs snippetStats, c s.Lock() defer s.Unlock() rs := s.Stats[circuitName] - rs[backendID][CurveIdx(curve)] = cs + rs[backendID][curve] = cs s.Stats[circuitName] = rs } diff --git a/internal/stats/stats_test.go b/internal/stats/stats_test.go index 8251304ce6..4fbcf7ac55 100644 --- a/internal/stats/stats_test.go +++ b/internal/stats/stats_test.go @@ -9,7 +9,7 @@ import ( ) func TestCircuitStatistics(t *testing.T) { - const refPath = "latest.stats" + const refPath = "latest_stats.csv" assert := require.New(t) // load reference @@ -35,7 +35,7 @@ func TestCircuitStatistics(t *testing.T) { circuit := c.Circuit t.Run(fmt.Sprintf("%s/%s/%s", name, curve.String(), backendID.String()), func(t *testing.T) { assert := require.New(t) - rs := ref[backendID][CurveIdx(curve)] + rs := ref[backendID][curve] s, err := NewSnippetStats(curve, backendID, circuit) assert.NoError(err, "building stats for circuit "+name)