diff --git a/.gitignore b/.gitignore index dfb5825..cd1e9ad 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ go.work.sum # env file .env + +target diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f478d71 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: static-link +static-link: + @cd link/bindgen; cargo build --release; + @cp link/bindgen/target/release/libbindgen.a link/osx.a + @rm -rf link/bindgen/target + +.PHONY: static-link-linux-amd64 +static-link-linux-amd64: + @cd link/bindgen; cargo build --release; + @cp link/bindgen/target/release/libbindgen.a link/linux_amd64.a + @rm -rf link/bindgen/target + +.PHONY: static-link-linux-arm64 +static-link-linux-arm64: + @cd link/bindgen; cargo build --release; + @cp link/bindgen/target/release/libbindgen.a link/linux_arm64.a + @rm -rf link/bindgen/target + +.PHONY: test +test: + @go test -v ./... diff --git a/hash/poseidon2_goldilocks/poseidon2.go b/hash/poseidon2_goldilocks/poseidon2.go index 9ca4ed0..652701d 100644 --- a/hash/poseidon2_goldilocks/poseidon2.go +++ b/hash/poseidon2_goldilocks/poseidon2.go @@ -6,6 +6,7 @@ import ( g "github.com/elliottech/poseidon_crypto/field/goldilocks" gFp5 "github.com/elliottech/poseidon_crypto/field/goldilocks_quintic_extension" + link "github.com/elliottech/poseidon_crypto/link" ) type HashOut [4]g.Element @@ -20,9 +21,20 @@ func (h HashOut) ToUint64Array() [4]uint64 { return [4]uint64{h[0].Uint64(), h[1].Uint64(), h[2].Uint64(), h[3].Uint64()} } -func HashToQuinticExtension(m []g.Element) gFp5.Element { - res := HashNToMNoPad(m, 5) - return gFp5.Element(res[:]) +func HashToQuinticExtension(input []g.Element) gFp5.Element { + in := make([]uint64, 0, len(input)) + for _, elem := range input { + in = append(in, elem.Uint64()) + } + + res := link.HashToQuinticExtension(in) + return gFp5.Element([5]g.Element{ + g.FromUint64(res[0]), + g.FromUint64(res[1]), + g.FromUint64(res[2]), + g.FromUint64(res[3]), + g.FromUint64(res[4]), + }) } func HashOutFromUint64Array(arr [4]uint64) HashOut { @@ -66,121 +78,12 @@ func HashTwoToOne(input1, input2 HashOut) HashOut { } func HashNToHashNoPad(input []g.Element) HashOut { - res := HashNToMNoPad(input, 4) - return HashOut{res[0], res[1], res[2], res[3]} -} - -func HashNToMNoPad(input []g.Element, numOutputs int) []g.Element { - var perm [WIDTH]g.Element - for i := 0; i < len(input); i += RATE { - for j := 0; j < RATE && i+j < len(input); j++ { - perm[j].Set(&input[i+j]) - } - Permute(&perm) - } - - outputs := make([]g.Element, 0, numOutputs) - for { - for i := 0; i < RATE; i++ { - outputs = append(outputs, perm[i]) - if len(outputs) == numOutputs { - return outputs - } - } - Permute(&perm) - } -} - -func Permute(input *[WIDTH]g.Element) { - externalLinearLayer(input) - fullRounds(input, 0) - partialRounds(input) - fullRounds(input, ROUNDS_F_HALF) -} - -func fullRounds(state *[WIDTH]g.Element, start int) { - for r := start; r < start+ROUNDS_F_HALF; r++ { - addRC(state, r) - sbox(state) - externalLinearLayer(state) - } -} - -func partialRounds(state *[WIDTH]g.Element) { - for r := 0; r < ROUNDS_P; r++ { - addRCI(state, r) - sboxP(0, state) - internalLinearLayer(state) - } -} - -func externalLinearLayer(s *[WIDTH]g.Element) { - for i := 0; i < 3; i++ { // 4 size window - var t0, t1, t2, t3, t4, t5, t6 g.Element - t0.Add(&s[4*i], &s[4*i+1]) // s0+s1 - t1.Add(&s[4*i+2], &s[4*i+3]) // s2+s3 - t2.Add(&t0, &t1) // t0+t1 = s0+s1+s2+s3 - t3.Add(&t2, &s[4*i+1]) // t2+s1 = s0+2s1+s2+s3 - t4.Add(&t2, &s[4*i+3]) // t2+s3 = s0+s1+s2+2s3 - t5.Double(&s[4*i]) // 2s0 - t6.Double(&s[4*i+2]) // 2s2 - s[4*i].Add(&t3, &t0) - s[4*i+1].Add(&t6, &t3) - s[4*i+2].Add(&t1, &t4) - s[4*i+3].Add(&t5, &t4) - } - - sums := [4]g.Element{} - for k := 0; k < 4; k++ { - for j := 0; j < WIDTH; j += 4 { - sums[k].Add(&sums[k], &s[j+k]) - } - } - for i := 0; i < WIDTH; i++ { - s[i].Add(&s[i], &sums[i%4]) - } -} - -func internalLinearLayer(state *[WIDTH]g.Element) { - var sum g.Element - sum.Set(&state[0]) - for i := 1; i < WIDTH; i++ { - sum.Add(&sum, &state[i]) - } - for i := 0; i < WIDTH; i++ { - state[i].Mul(&state[i], &MATRIX_DIAG_12_U64[i]). - Add(&state[i], &sum) - } -} - -func addRC(state *[WIDTH]g.Element, externalRound int) { - for i := 0; i < WIDTH; i++ { - state[i].Add(&state[i], &EXTERNAL_CONSTANTS[externalRound][i]) + in := make([]uint64, 0, len(input)) + for _, elem := range input { + in = append(in, elem.Uint64()) } -} - -func addRCI(state *[WIDTH]g.Element, round int) { - state[0].Add(&state[0], &INTERNAL_CONSTANTS[round]) -} - -func sbox(state *[WIDTH]g.Element) { - for i := range state { - sboxP(i, state) - } -} - -func sboxP(index int, state *[WIDTH]g.Element) { - var tmp g.Element - tmp.Set(&state[index]) - - var tmpSquare g.Element - tmpSquare.Square(&tmp) - - var tmpSixth g.Element - tmpSixth.Mul(&tmpSquare, &tmp) - tmpSixth.Square(&tmpSixth) - state[index].Mul(&tmpSixth, &tmp) + return HashOutFromUint64Array(link.HashNToHashNoPad(in)) } const BlockSize = g.Bytes // BlockSize size that poseidon consumes diff --git a/hash/poseidon2_goldilocks/poseidon2_purego.go b/hash/poseidon2_goldilocks/poseidon2_purego.go new file mode 100644 index 0000000..38edf13 --- /dev/null +++ b/hash/poseidon2_goldilocks/poseidon2_purego.go @@ -0,0 +1,118 @@ +package poseidon2 + +import ( + g "github.com/elliottech/poseidon_crypto/field/goldilocks" +) + +func HashNToMNoPad(input []g.Element, numOutputs int) []g.Element { + var perm [WIDTH]g.Element + for i := 0; i < len(input); i += RATE { + for j := 0; j < RATE && i+j < len(input); j++ { + perm[j].Set(&input[i+j]) + } + Permute(&perm) + } + + outputs := make([]g.Element, 0, numOutputs) + for { + for i := 0; i < RATE; i++ { + outputs = append(outputs, perm[i]) + if len(outputs) == numOutputs { + return outputs + } + } + Permute(&perm) + } +} + +func Permute(input *[WIDTH]g.Element) { + externalLinearLayer(input) + fullRounds(input, 0) + partialRounds(input) + fullRounds(input, ROUNDS_F_HALF) +} + +func fullRounds(state *[WIDTH]g.Element, start int) { + for r := start; r < start+ROUNDS_F_HALF; r++ { + addRC(state, r) + sbox(state) + externalLinearLayer(state) + } +} + +func partialRounds(state *[WIDTH]g.Element) { + for r := 0; r < ROUNDS_P; r++ { + addRCI(state, r) + sboxP(0, state) + internalLinearLayer(state) + } +} + +func externalLinearLayer(s *[WIDTH]g.Element) { + for i := 0; i < 3; i++ { // 4 size window + var t0, t1, t2, t3, t4, t5, t6 g.Element + t0.Add(&s[4*i], &s[4*i+1]) // s0+s1 + t1.Add(&s[4*i+2], &s[4*i+3]) // s2+s3 + t2.Add(&t0, &t1) // t0+t1 = s0+s1+s2+s3 + t3.Add(&t2, &s[4*i+1]) // t2+s1 = s0+2s1+s2+s3 + t4.Add(&t2, &s[4*i+3]) // t2+s3 = s0+s1+s2+2s3 + t5.Double(&s[4*i]) // 2s0 + t6.Double(&s[4*i+2]) // 2s2 + s[4*i].Add(&t3, &t0) + s[4*i+1].Add(&t6, &t3) + s[4*i+2].Add(&t1, &t4) + s[4*i+3].Add(&t5, &t4) + } + + sums := [4]g.Element{} + for k := 0; k < 4; k++ { + for j := 0; j < WIDTH; j += 4 { + sums[k].Add(&sums[k], &s[j+k]) + } + } + for i := 0; i < WIDTH; i++ { + s[i].Add(&s[i], &sums[i%4]) + } +} + +func internalLinearLayer(state *[WIDTH]g.Element) { + var sum g.Element + sum.Set(&state[0]) + for i := 1; i < WIDTH; i++ { + sum.Add(&sum, &state[i]) + } + for i := 0; i < WIDTH; i++ { + state[i].Mul(&state[i], &MATRIX_DIAG_12_U64[i]). + Add(&state[i], &sum) + } +} + +func addRC(state *[WIDTH]g.Element, externalRound int) { + for i := 0; i < WIDTH; i++ { + state[i].Add(&state[i], &EXTERNAL_CONSTANTS[externalRound][i]) + } +} + +func addRCI(state *[WIDTH]g.Element, round int) { + state[0].Add(&state[0], &INTERNAL_CONSTANTS[round]) +} + +func sbox(state *[WIDTH]g.Element) { + for i := range state { + sboxP(i, state) + } +} + +func sboxP(index int, state *[WIDTH]g.Element) { + var tmp g.Element + tmp.Set(&state[index]) + + var tmpSquare g.Element + tmpSquare.Square(&tmp) + + var tmpSixth g.Element + tmpSixth.Mul(&tmpSquare, &tmp) + tmpSixth.Square(&tmpSixth) + + state[index].Mul(&tmpSixth, &tmp) +} diff --git a/hash/poseidon2_goldilocks/poseidon2_test.go b/hash/poseidon2_goldilocks/poseidon2_test.go index f13f936..ab40387 100644 --- a/hash/poseidon2_goldilocks/poseidon2_test.go +++ b/hash/poseidon2_goldilocks/poseidon2_test.go @@ -1,30 +1,11 @@ package poseidon2 import ( - "fmt" "testing" g "github.com/elliottech/poseidon_crypto/field/goldilocks" ) -func TestGetNilTreeLevels(t *testing.T) { - res := []HashOut{EmptyHashOut()} - for i := 1; i < 128; i++ { - res = append(res, HashTwoToOne(res[i-1], res[i-1])) - } - - fmt.Println() - for i := 0; i < len(res); i++ { - fmt.Printf("Level %d: ", i) - leBytes := res[i].ToLittleEndianBytes() - for j := 0; j < len(leBytes); j++ { - fmt.Printf("%d ", leBytes[j]) - } - fmt.Println() - } - fmt.Println() -} - func TestPermute(t *testing.T) { inp := [WIDTH]g.Element{ g.FromUint64(5417613058500526590), diff --git a/link/bindgen/Cargo.lock b/link/bindgen/Cargo.lock new file mode 100644 index 0000000..3a954ac --- /dev/null +++ b/link/bindgen/Cargo.lock @@ -0,0 +1,1365 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addchain" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2e69442aa5628ea6951fa33e24efe8313f4321a91bd729fc2f75bdfc858570" +dependencies = [ + "num-bigint 0.3.3", + "num-integer", + "num-traits", +] + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "const-random", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bindgen" +version = "0.0.1" +dependencies = [ + "circuit", + "plonky2", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + +[[package]] +name = "circuit" +version = "0.0.1" +source = "git+https://github.com/elliottech/zklighter-perps-circuits-plonky.git?rev=195c1423f0f88bf64e4bf4856e4364591b987700#195c1423f0f88bf64e4bf4856e4364591b987700" +dependencies = [ + "anyhow", + "bincode", + "clap", + "clap_derive", + "env_logger", + "ff", + "hashbrown 0.14.5", + "hex", + "itertools 0.13.0", + "lazy_static", + "log", + "num", + "plonky2", + "rand", + "rayon", + "serde", + "serde_json", + "serde_with", + "sha2", + "tiny-keccak", +] + +[[package]] +name = "clap" +version = "4.5.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.96", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "byteorder", + "ff_derive", + "rand_core", + "subtle", +] + +[[package]] +name = "ff_derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f54704be45ed286151c5e11531316eaef5b8f5af7d597b806fdb8af108d84a" +dependencies = [ + "addchain", + "cfg-if", + "num-bigint 0.3.3", + "num-integer", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "fixed-hash" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "rayon", + "serde", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", + "serde", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "keccak-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2bd4c29270e724d3eaadf7bdc8700af4221fc0ed771b855eadcd1b98d52851" +dependencies = [ + "primitive-types", + "tiny-keccak", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "log" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint 0.4.6", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", + "rand", + "serde", +] + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", + "rand", + "serde", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint 0.4.6", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "plonky2" +version = "0.2.2" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" +dependencies = [ + "ahash", + "anyhow", + "getrandom", + "hashbrown 0.14.5", + "itertools 0.11.0", + "keccak-hash", + "log", + "num", + "plonky2_field", + "plonky2_maybe_rayon", + "plonky2_util", + "rand", + "rand_chacha", + "serde", + "static_assertions", + "unroll", + "web-time", +] + +[[package]] +name = "plonky2_field" +version = "0.2.2" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" +dependencies = [ + "anyhow", + "itertools 0.11.0", + "num", + "plonky2_util", + "rand", + "serde", + "static_assertions", + "unroll", +] + +[[package]] +name = "plonky2_maybe_rayon" +version = "0.2.0" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" +dependencies = [ + "rayon", +] + +[[package]] +name = "plonky2_util" +version = "0.2.0" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "primitive-types" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" +dependencies = [ + "fixed-hash", + "uint", +] + +[[package]] +name = "proc-macro2" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "serde_json" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.7.1", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "unroll" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ad948c1cb799b1a70f836077721a92a35ac177d4daddf4c20a633786d4cf618" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn 2.0.96", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] diff --git a/link/bindgen/Cargo.toml b/link/bindgen/Cargo.toml new file mode 100644 index 0000000..83ef8ab --- /dev/null +++ b/link/bindgen/Cargo.toml @@ -0,0 +1,24 @@ +cargo-features = ["edition2024"] + +[package] +edition = "2024" +name = "bindgen" +version = "0.0.1" +authors = ["Ahmet Yasin Alp "] +license = "MIT OR Apache-2.0" +homepage = "https://github.com/elliottech/zklighter-perps-circuits-plonky" +repository = "https://github.com/elliottech/zklighter-perps-circuits-plonky" +keywords = ["zkLighter"] +categories = ["zkLighter"] + +[lib] +# If you only wanted dynamic library, you'd use only "cdylib". +# If you only wanted static library, you'd use only "staticlib". +# This demo shows both. See https://doc.rust-lang.org/reference/linkage.html +# for more information. +crate-type = ["cdylib", "staticlib"] + +[dependencies] +plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdacd49ede15737bc1172546d82e9521b79b" } +circuit = { git = "https://github.com/elliottech/zklighter-perps-circuits-plonky.git", rev = "195c1423f0f88bf64e4bf4856e4364591b987700", default-features = true } + diff --git a/link/bindgen/src/lib.rs b/link/bindgen/src/lib.rs new file mode 100644 index 0000000..0bd23c3 --- /dev/null +++ b/link/bindgen/src/lib.rs @@ -0,0 +1,127 @@ +extern crate circuit; +extern crate plonky2; + +use circuit::eddsa::curve::scalar_field::ECgFp5Scalar; +use circuit::poseidon2::hash::Poseidon2Hash; +use circuit::poseidon2::hash::Poseidon2Permutation; +use circuit::types::config::{const_f, F}; +use plonky2::field::extension::quintic::QuinticExtension; +use plonky2::field::types::{Field, PrimeField64}; +use plonky2::plonk::config::Hasher; +use std::slice; + +#[no_mangle] +pub extern "C" fn hash_n_to_hash_no_pad(data: *const u64, len: usize, dst: *mut u64) { + if data.is_null() || dst.is_null() { + return; + } + + let output_slice = unsafe { slice::from_raw_parts_mut(dst, 4) }; + for (i, &value) in plonky2::hash::hashing::hash_n_to_hash_no_pad::>( + &unsafe { slice::from_raw_parts(data, len) } + .iter() + .map(|&x| const_f(x)) + .collect::>(), + ) + .elements + .iter() + .enumerate() + { + output_slice[i] = value.to_canonical_u64(); + } +} + +#[no_mangle] +pub extern "C" fn hash_no_pad(input: *const u64, input_len: usize, dst: *mut u64) { + if input.is_null() || dst.is_null() { + return; + } + + let output_slice = unsafe { slice::from_raw_parts_mut(dst, 4) }; + for (i, &value) in Poseidon2Hash::hash_no_pad( + &unsafe { slice::from_raw_parts(input, input_len) } + .iter() + .map(|&x| F::from_canonical_u64(x)) + .collect::>(), + ) + .elements + .iter() + .enumerate() + { + output_slice[i] = value.to_canonical_u64(); + } +} + +#[no_mangle] +pub extern "C" fn schnorr_sign_hashed_message(m_hashed: *const u64, sk: *const u64, sig: *mut u64) { + if m_hashed.is_null() || sk.is_null() || sig.is_null() { + return; + } + + let m_hashed_slice = unsafe { slice::from_raw_parts(m_hashed, 5) }; + let sk_slice = unsafe { slice::from_raw_parts(sk, 5) }; + let sig_slice = unsafe { slice::from_raw_parts_mut(sig, 10) }; + + let hashed_message = QuinticExtension([ + F::from_canonical_u64(m_hashed_slice[0]), + F::from_canonical_u64(m_hashed_slice[1]), + F::from_canonical_u64(m_hashed_slice[2]), + F::from_canonical_u64(m_hashed_slice[3]), + F::from_canonical_u64(m_hashed_slice[4]), + ]); + let sk = ECgFp5Scalar([ + sk_slice[0], + sk_slice[1], + sk_slice[2], + sk_slice[3], + sk_slice[4], + ]); + let schnorr_sig = circuit::eddsa::schnorr::schnorr_sign_hashed_message(&hashed_message, &sk); + for i in 0..5 { + sig_slice[i] = schnorr_sig.s.0[i]; + sig_slice[i + 5] = schnorr_sig.e.0[i]; + } +} + +#[no_mangle] +pub extern "C" fn hash_to_quintic_extension(input: *const u64, input_len: usize, dst: *mut u64) { + if input.is_null() || dst.is_null() { + return; + } + + let input_slice = unsafe { slice::from_raw_parts(input, input_len) }; + let dst_slice = unsafe { slice::from_raw_parts_mut(dst, 5) }; + + let result = circuit::eddsa::schnorr::hash_to_quintic_extension( + &input_slice + .iter() + .map(|&x| F::from_canonical_u64(x)) + .collect::>(), + ); + + for i in 0..5 { + dst_slice[i] = result.0[i].to_canonical_u64(); + } +} + +#[no_mangle] +pub extern "C" fn schnorr_pk_from_sk(input: *const u64, dst: *mut u64) { + if input.is_null() || dst.is_null() { + return; + } + + let input_slice = unsafe { slice::from_raw_parts(input, 5) }; + let dst_slice = unsafe { slice::from_raw_parts_mut(dst, 5) }; + + circuit::eddsa::schnorr::schnorr_pk_from_sk(&ECgFp5Scalar([ + input_slice[0], + input_slice[1], + input_slice[2], + input_slice[3], + input_slice[4], + ])) + .0 + .iter() + .enumerate() + .for_each(|(i, &x)| dst_slice[i] = x.to_canonical_u64()); +} diff --git a/link/link.go b/link/link.go new file mode 100644 index 0000000..c97f64b --- /dev/null +++ b/link/link.go @@ -0,0 +1,64 @@ +package link + +/* +#cgo darwin LDFLAGS: ${SRCDIR}/osx.a -ldl +#cgo linux,amd64 LDFLAGS: ${SRCDIR}/linux_amd64.a -ldl +#cgo linux,arm64 LDFLAGS: ${SRCDIR}/linux_arm64.a -ldl + +#include +#include +void hash_n_to_hash_no_pad(const uint64_t *data, size_t len, uint64_t *dst); +void hash_no_pad(const uint64_t *input, size_t input_len, uint64_t *dst); +void schnorr_sign_hashed_message(const uint64_t *m_hashed, const uint64_t *sk, uint64_t *sig); +void hash_to_quintic_extension(const uint64_t *input, size_t input_len, uint64_t *dst); +void schnorr_pk_from_sk(const uint64_t *input, uint64_t *dst); +*/ +import "C" +import ( + "unsafe" +) + +func HashNToHashNoPad(input []uint64) [4]uint64 { + inputLen := len(input) + inputC := make([]C.uint64_t, inputLen) + for i, elem := range input { + inputC[i] = C.uint64_t(elem) + } + + var outputC [4]C.uint64_t + C.hash_n_to_hash_no_pad( + (*C.uint64_t)(unsafe.Pointer(&inputC[0])), + C.size_t(inputLen), + (*C.uint64_t)(unsafe.Pointer(&outputC[0])), + ) + + return [4]uint64{ + uint64(outputC[0]), + uint64(outputC[1]), + uint64(outputC[2]), + uint64(outputC[3]), + } +} + +func HashToQuinticExtension(input []uint64) [5]uint64 { + inputLen := len(input) + inputC := make([]C.uint64_t, inputLen) + for i, elem := range input { + inputC[i] = C.uint64_t(elem) + } + + var outputC [5]C.uint64_t + C.hash_to_quintic_extension( + (*C.uint64_t)(unsafe.Pointer(&inputC[0])), + C.size_t(inputLen), + (*C.uint64_t)(unsafe.Pointer(&outputC[0])), + ) + + return [5]uint64{ + uint64(outputC[0]), + uint64(outputC[1]), + uint64(outputC[2]), + uint64(outputC[3]), + uint64(outputC[4]), + } +} diff --git a/link/linux_amd64.a b/link/linux_amd64.a new file mode 100644 index 0000000..e855c98 Binary files /dev/null and b/link/linux_amd64.a differ diff --git a/link/linux_arm64.a b/link/linux_arm64.a new file mode 100644 index 0000000..d6b931b Binary files /dev/null and b/link/linux_arm64.a differ diff --git a/link/osx.a b/link/osx.a new file mode 100644 index 0000000..e7847a4 Binary files /dev/null and b/link/osx.a differ