diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index fed2177..1b2b812 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -1,10 +1,12 @@ on: push: branches: + - '**' - "!master" pull_request: branches: + - '**' - "!master" jobs: @@ -19,6 +21,11 @@ jobs: targets: wasm32-unknown-unknown components: rustfmt, clippy + - name: Run the license check + run: | + cargo install --locked cargo-about + cargo about generate --format json --fail --all-features > /dev/null + - name: Run cargo test run: cargo test --all-features diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index beee7c9..824fb26 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -19,6 +19,11 @@ jobs: targets: wasm32-unknown-unknown components: rustfmt, clippy + - name: Run the license check + run: | + cargo install --locked cargo-about + cargo about generate --format json --fail --all-features > /dev/null + - name: Run cargo test run: cargo test --all-features diff --git a/Cargo.toml b/Cargo.toml index 5543e56..c40eca3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ resolver = "2" [workspace.dependencies] anyhow = "1.0.86" -ark-ff = "0.4.2" -ark-poly = "0.4.2" +ark-ff = { git = "https://github.com/jaehunkim/algebra", branch = "v0.4.2-fix" } +ark-poly = { git = "https://github.com/jaehunkim/algebra", branch = "v0.4.2-fix" } sha3 = "0.10.8" blake2 = "0.10.6" hex-literal = "0.4.1" diff --git a/about.toml b/about.toml new file mode 100644 index 0000000..905185a --- /dev/null +++ b/about.toml @@ -0,0 +1,10 @@ +accepted = [ + "Apache-2.0", + "MIT", + "BSD-3-Clause", + "Unicode-DFS-2016" +] +ignore-transitive-dependencies = false +ignore-build-dependencies = false +ignore-dev-dependencies = false +no-clearly-defined = true diff --git a/channel/Cargo.toml b/channel/Cargo.toml index 1610fce..cb7eb93 100644 --- a/channel/Cargo.toml +++ b/channel/Cargo.toml @@ -2,6 +2,7 @@ name = "channel" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] ark-ff.workspace = true diff --git a/channel/src/fs_prover_channel.rs b/channel/src/fs_prover_channel.rs index 29af584..21928c8 100644 --- a/channel/src/fs_prover_channel.rs +++ b/channel/src/fs_prover_channel.rs @@ -133,6 +133,7 @@ impl ProverChannel for FSProverChannel { data_queries: BTreeSet, integrity_queries: BTreeSet, all_query_rows: BTreeSet, + mont_r: F, } -impl TableProver { +impl TableProver { pub fn new( + n_segments: usize, + n_rows_per_segment: usize, n_columns: usize, - commitment_scheme: Box>, + field_element_size_in_bytes: usize, + n_verifier_friendly_commitment_layers: usize, + commitment_hashes: CommitmentHashes, + mont_r: F, ) -> Self { + let size_of_row = field_element_size_in_bytes * n_columns; + + let commitment_scheme: Box> = + make_commitment_scheme_prover( + size_of_row, + n_rows_per_segment, + n_segments, + n_verifier_friendly_commitment_layers, + commitment_hashes, + n_columns, + ); + Self { n_columns, commitment_scheme, data_queries: BTreeSet::new(), integrity_queries: BTreeSet::new(), all_query_rows: BTreeSet::new(), + mont_r, } } @@ -41,9 +61,10 @@ impl TableProver { "segment length is expected to be equal to the number of columns" ); + let serialised_segment = serialize_field_columns(segment, self.mont_r); let _ = &self .commitment_scheme - .add_segment_for_commitment(&serialize_field_columns(segment), segment_idx); + .add_segment_for_commitment(&serialised_segment, segment_idx); } pub fn commit(&mut self, channel: &mut FSProverChannel) -> Result<(), anyhow::Error> { @@ -120,14 +141,17 @@ impl TableProver { if let Some(&to_transmit_loc) = to_transmit_it.next() { assert!(to_transmit_loc == query_loc); - channel.send_felts(&[data[i]])?; + let data_mont = data[i] * self.mont_r; + channel.send_felts(&[data_mont])?; } } } } - self.commitment_scheme - .decommit(&serialize_field_columns(&elements_data_last_rows), channel)?; + self.commitment_scheme.decommit( + &serialize_field_columns(&elements_data_last_rows, self.mont_r), + channel, + )?; Ok(()) } @@ -146,7 +170,7 @@ fn verify_all_columns_same_length(columns: &[Vec]) columns.iter().all(|column| column.len() == n_rows) } -fn serialize_field_columns(segment: &[Vec]) -> Vec { +pub fn serialize_field_columns(segment: &[Vec], mont_r: F) -> Vec { let columns = segment; assert!( @@ -163,7 +187,8 @@ fn serialize_field_columns(segment: &[Vec]) -> Vec { for row in 0..n_rows { for col_data in columns.iter().take(n_columns) { - serialization.extend_from_slice(&col_data[row].into_bigint().to_bytes_be()); + let data_mont = col_data[row] * mont_r; + serialization.extend_from_slice(&data_mont.into_bigint().to_bytes_be()); } } diff --git a/commitment_scheme/src/table_verifier.rs b/commitment_scheme/src/table_verifier.rs index 8ccf1e1..6779f4e 100644 --- a/commitment_scheme/src/table_verifier.rs +++ b/commitment_scheme/src/table_verifier.rs @@ -128,10 +128,7 @@ impl TableVerifier { mod tests { use super::*; use crate::SupportedHashes; - use crate::{ - make_commitment_scheme_prover, make_commitment_scheme_verifier, table_prover::TableProver, - CommitmentHashes, - }; + use crate::{make_commitment_scheme_verifier, table_prover::TableProver, CommitmentHashes}; use ark_ff::UniformRand; use channel::fs_prover_channel::FSProverChannel; use channel::ProverChannel; @@ -150,7 +147,6 @@ mod tests { integrity_queries: &BTreeSet, ) -> Vec { let n_rows = n_rows_per_segment * n_segments; - let size_of_row = field_element_size * n_columns; assert_eq!(table_data.len(), n_columns); @@ -175,17 +171,16 @@ mod tests { let commitment_hashes = CommitmentHashes::from_single_hash(SupportedHashes::Blake2s256); - let commitment_scheme = make_commitment_scheme_prover( - size_of_row, - n_rows_per_segment, + let mut table_prover = TableProver::new( n_segments, + n_rows_per_segment, + n_columns, + field_element_size, 0, commitment_hashes, - n_columns, + felt::hex("0x7fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1"), ); - let mut table_prover = TableProver::new(n_columns, commitment_scheme); - for (i, segment) in segment_data.iter().enumerate() { let segment_slice: Vec> = segment.iter().map(|slice| slice.to_vec()).collect(); @@ -232,6 +227,8 @@ mod tests { integrity_queries: &BTreeSet, table_data: Vec>, ) { + let mont_r: Felt252 = + felt::hex("0x7fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1"); let n_rows = n_rows_per_segment * n_segments; let size_of_row = field_element_size * n_columns; @@ -257,16 +254,18 @@ mod tests { "Data query not found in response" ); + // channel receives data in Mont form thus data_for_verification is in Mont form + // Table Data is in Standard form, convert it to Mont form and then compare assert_eq!( *data_for_verification.get(q).unwrap(), - table_data[q.get_col()][q.get_row()], + mont_r * table_data[q.get_col()][q.get_row()], "Incorrect response to data query." ); } - // Check verification + // Check verification, convert data to Mont form and then insert for q in integrity_queries.iter() { - data_for_verification.insert(*q, table_data[q.get_col()][q.get_row()]); + data_for_verification.insert(*q, mont_r * table_data[q.get_col()][q.get_row()]); } assert!(table_verifier @@ -278,134 +277,35 @@ mod tests { fn test_table_verifier() { let field_element_size = 32; let n_columns = 2; - let n_segments = 4; - let n_rows_per_segment = 4; - let exp_proof = vec![ - 254, 54, 51, 40, 59, 10, 247, 47, 124, 35, 240, 199, 156, 65, 129, 175, 177, 74, 9, 96, - 120, 22, 21, 170, 31, 113, 140, 220, 114, 208, 220, 250, 6, 95, 109, 109, 251, 22, 153, - 161, 55, 125, 12, 95, 161, 104, 216, 183, 149, 115, 134, 247, 51, 163, 121, 233, 167, - 197, 132, 15, 182, 148, 117, 51, 1, 50, 67, 97, 181, 239, 72, 42, 190, 142, 239, 211, - 103, 154, 228, 168, 128, 141, 208, 173, 240, 244, 141, 181, 29, 12, 65, 197, 136, 42, - 145, 174, 6, 16, 45, 96, 119, 232, 106, 62, 44, 229, 78, 139, 155, 200, 136, 34, 17, 8, - 190, 184, 218, 52, 132, 122, 161, 121, 17, 210, 211, 74, 77, 77, 1, 107, 59, 186, 10, - 232, 45, 229, 118, 109, 108, 178, 92, 244, 148, 20, 124, 4, 160, 8, 228, 133, 118, 248, - 143, 159, 196, 141, 4, 226, 180, 147, 0, 40, 211, 121, 66, 64, 39, 25, 155, 97, 197, - 228, 152, 171, 194, 190, 100, 245, 24, 173, 188, 194, 64, 179, 104, 180, 80, 139, 169, - 34, 130, 107, 1, 171, 166, 71, 161, 193, 187, 14, 171, 177, 1, 219, 229, 30, 157, 11, - 85, 247, 93, 249, 198, 152, 177, 239, 120, 229, 120, 132, 127, 223, 218, 92, 2, 174, - 127, 23, 103, 12, 18, 62, 25, 124, 173, 148, 170, 156, 50, 90, 137, 199, 66, 125, 110, - 184, 86, 191, 35, 61, 146, 98, 34, 29, 210, 245, 124, 89, 215, 81, 31, 168, 250, 216, - 242, 206, 217, 243, 104, 110, 174, 232, 151, 108, 227, 167, 55, 188, 41, 123, 181, 143, - 107, 145, 23, 68, 72, 111, 247, 35, 58, 126, 64, 85, 91, 10, 161, 23, 64, 27, 85, 199, - 95, 174, 12, 158, 121, 194, 103, 165, 99, 100, 109, 11, 176, 187, 205, 102, 98, 194, - 86, 188, 199, 235, 147, 86, 98, 170, 224, 38, 254, 122, 27, 207, 160, 75, 221, 135, - 164, 212, 36, 210, 3, 229, 117, 44, 176, 3, 157, 9, 0, 107, 39, 186, 111, 153, 117, 32, - 131, 119, 234, 36, 0, 52, 255, 66, 106, 43, 232, 130, 89, 207, 110, 166, 220, 52, 252, - 123, 58, 129, 167, 32, 4, 17, 215, 137, 162, 238, 61, 225, 0, 235, 50, 138, 57, 175, - 96, 158, 43, 114, 241, 204, 179, 158, 98, 151, 196, 206, 180, 178, 105, 40, 22, 80, 70, - 133, 242, 83, 119, 80, 168, 206, 175, 233, 169, 116, 126, 68, 246, 128, 115, 186, 197, - 115, 58, 210, 235, 99, 203, 156, 28, 28, 193, 235, 215, 174, 97, 43, - ]; - let table_data: Vec> = vec![ - vec![ - felt::hex("0x65f6d6dfb1699a1377d0c5fa168d8b7957386f733a379e9a7c5840fb6947533"), - felt::hex("0x4ce193265b909a1b1f373f956b5c026cda37afe441a3379659120cf90867ebb"), - felt::hex("0x6102d6077e86a3e2ce54e8b9bc888221108beb8da34847aa17911d2d34a4d4d"), - felt::hex("0x7867f55a408590ccac3919bfe1040788453d4fb8b6ab705b2418bce53124ffe"), - felt::hex("0x15114125a3a1a01de81b8b5fc1384e7b7d4abca0f9f078f1fa189a59d3b90b8"), - felt::hex("0x24ab5ce86e9d9686df7734a44da1048c8b051a72234929c11e3468365e9b4a3"), - felt::hex("0x16b3bba0ae82de5766d6cb25cf494147c04a008e48576f88f9fc48d04e2b493"), - felt::hex("0x267ad9e76b76dc64ddeb1f41bf11164d99aef37fb56d7984a96119a42cde532"), - felt::hex("0x5a5a401f6ddb77e08f5009d681fff854c01192397585699b46fc2996c1208d9"), - felt::hex("0x71068b2c99ba944480fc9d0b7f78678ca49ebd2a47836f71c8c00a870eab999"), - felt::hex("0x39d59180ffb1c5a1a9198c05ed5e9d86965276304c1a66599994f39962022d4"), - felt::hex("0x48c660052643949216c449084afa58082ee4921bcf7f7ef2878a6580b1c89a0"), - felt::hex("0x66fdb7b072b4217309e3aa4c4a0b66a0e7624fc635c1f48864759589917f53a"), - felt::hex("0x33073c99572593b5f7585704eb11868234024bfbe034b7de3e2973f025ea21"), - felt::hex("0x336331fa834eeba35da2c5538707e9c864434596162308abd2de97827b9ec0a"), - felt::hex("0x360d067d8fa88671d6d7691dac08071b0777a5ee8e05f1f4da4c83abbe64c20"), - ], - vec![ - felt::hex("0x1324361b5ef482abe8eefd3679ae4a8808dd0adf0f48db51d0c41c5882a91ae"), - felt::hex("0x3ea787108255965c626316af351fc4ab788c61372eb43f46924281d24b440e1"), - felt::hex("0x34c8d9285643d3ef01bcea57dbcb9ab8cc7572140a9436758e10fe9aea9c06b"), - felt::hex("0x5b88c400264850250013e86e489ddedb5a2754f0d957d0047cc8dd06497528e"), - felt::hex("0x1143a9d6989475e6e319adfcb6be5a5f37465648a31537200412e3b1b6d6141"), - felt::hex("0x2efa7ae3601eb7ad91122b7a0a43bc06943dfd212e93bc84034b2f4b27b588d"), - felt::hex("0x28d379424027199b61c5e498abc2be64f518adbcc240b368b4508ba922826b"), - felt::hex("0x1aba647a1c1bb0eabb101dbe51e9d0b55f75df9c698b1ef78e578847fdfda5c"), - felt::hex("0x3ae328a629b7510829aa9f369bdbff56b88d04d763630a10915196ea915da19"), - felt::hex("0x508c970a69e629fcdab35e82eaadea45a57a2468bf2b8f77401cf6471eabf8e"), - felt::hex("0x6a8a3624b6e9801a2ff4d2f0f34ccfb7e22a2c055ac6071d9b99783f2c616c7"), - felt::hex("0x2ae7f17670c123e197cad94aa9c325a89c7427d6eb856bf233d9262221dd2f5"), - felt::hex("0x2e83b57723d7dd69378b113c4b50f15d2ef8b8550f8125d7f7076eeaafbd017"), - felt::hex("0x2c88cfd74c8e77b767fcac792b9a8a65a87393fefca890557df56f0ff8e9275"), - felt::hex("0x574248ac5a307e2ebf5070b5b3e3dc4661a652c6c9330e1c69d510ee91a8f4e"), - felt::hex("0x10f23fcd14fbeb174d90599d5fcd35ca93c0f860c48a9c8447bc1f3220f89cc"), - ], - ]; - let data_queries = BTreeSet::from([RowCol::new(0, 0), RowCol::new(6, 0)]); - let integrity_queries = - BTreeSet::from([RowCol::new(2, 1), RowCol::new(7, 0), RowCol::new(11, 0)]); - let proof = get_proof( - field_element_size, - n_columns, - n_segments, - n_rows_per_segment, - table_data.clone(), - &data_queries, - &integrity_queries, - ); - assert_eq!(proof, exp_proof); - test_table_verifier_with( - field_element_size, - n_columns, - n_segments, - n_rows_per_segment, - exp_proof, - &data_queries, - &integrity_queries, - table_data, - ); - - let field_element_size = 32; - let n_columns = 2; - let n_segments = 4; + let n_segments = 2; let n_rows_per_segment = 2; let exp_proof = vec![ - 193, 165, 8, 153, 66, 225, 55, 241, 104, 82, 160, 74, 149, 163, 243, 50, 11, 136, 152, - 41, 115, 95, 232, 181, 236, 195, 141, 18, 86, 71, 196, 24, 2, 242, 10, 108, 74, 153, - 114, 164, 139, 50, 123, 195, 68, 213, 156, 247, 134, 49, 255, 19, 201, 87, 214, 74, - 162, 52, 81, 192, 161, 90, 200, 29, 90, 234, 183, 140, 43, 51, 224, 71, 192, 111, 232, - 21, 40, 34, 8, 228, 159, 251, 208, 136, 158, 177, 78, 138, 247, 251, 234, 54, 118, 231, - 108, 205, 113, 133, 20, 120, 208, 210, 212, 69, 200, 241, 150, 184, 53, 49, 30, 119, - 160, 169, 145, 69, 70, 188, 154, 254, 220, 184, 71, 86, 181, 243, 118, 80, 183, 168, - 112, 218, 168, 45, 162, 19, 16, 56, 61, 192, 48, 201, 69, 221, 54, 206, 61, 103, 9, - 245, 149, 235, 90, 204, 14, 29, 49, 95, 7, 187, + 71, 132, 165, 10, 119, 246, 172, 81, 234, 60, 193, 139, 122, 35, 61, 93, 85, 9, 22, 34, + 250, 70, 170, 255, 82, 218, 88, 82, 84, 145, 39, 11, 4, 208, 101, 14, 35, 199, 138, + 153, 75, 54, 23, 135, 115, 134, 216, 97, 166, 88, 109, 18, 69, 44, 89, 44, 9, 201, 55, + 194, 209, 49, 166, 53, 2, 73, 17, 183, 56, 6, 227, 237, 209, 59, 211, 11, 109, 20, 169, + 85, 36, 173, 230, 149, 238, 111, 108, 232, 153, 214, 98, 11, 132, 91, 27, 200, 0, 27, + 43, 14, 57, 196, 188, 170, 115, 109, 60, 183, 208, 44, 115, 250, 44, 40, 67, 107, 124, + 247, 184, 4, 195, 58, 23, 195, 137, 187, 25, 111, 224, 9, 210, 47, 106, 211, 251, 35, + 206, 220, 172, 66, 250, 42, 183, 80, 205, 160, 148, 212, 135, 235, 23, 114, 243, 42, + 33, 247, 209, 236, 1, 107, 4, 119, 6, 89, 43, 202, 223, 252, 111, 129, 170, 229, 106, + 165, 229, 53, 186, 154, 219, 87, 23, 23, 172, 53, 211, 64, 58, 149, 134, 178, 200, 64, ]; let table_data: Vec> = vec![ vec![ - felt::hex("0x34b3c38e4e7aebf78bb19da93486e7c70046dd75ce5da061f1099782230ff30"), - felt::hex("0x2f20a6c4a9972a48b327bc344d59cf78631ff13c957d64aa23451c0a15ac81d"), - felt::hex("0xefa810976794351e5f2b78554c3d5bdc6dfbe76d441b33c47ce4364023042f"), - felt::hex("0x34145cb1422ba56f8bdae62be85e5b81b122e789826cf1966490ad8db0a42e5"), - felt::hex("0x101591ecb80ab91a577b9aad4ce5320ae793422f0534fdd2e2240d3ce530f47"), - felt::hex("0x51d9ae1e146544be7b08f30f786cc5bc8be2ebb0b0549e8d5904d2a286b2835"), - felt::hex("0x4da5aa9a59777642aa1a9b6701b351963f9d1f0e6226fe7ffc62fba1afb31b8"), - felt::hex("0x279ea5b964d189390793acbe470ce189fe198fe9badb09b4382981b55c3a18f"), + felt::hex("0x29ec2635fe381f6dc572588d9697f3347bf6bb6598c7ba0c42b797204249a2d"), + felt::hex("0x24c62770e0423fc3ff78c418d3036e3f435ac98c1e23eba93d2780b518486e2"), + felt::hex("0x3a79b8864902faa95a0a33d56fc94b271e18d09122d45f14ba4fcface76ebb0"), + felt::hex("0x60d1bc1595eddea3b03ba0161ea300b914f61a5f49f2f553e0d3e77aff026de"), ], vec![ - felt::hex("0xbca7e4d5c388df65db262f2f2581e7292865365f5852d4eea5fdec7c7ff2e"), - felt::hex("0x225f30f1c56910e184e49c3ecd669fefa8baca8e9c0f0ac90d9e62648ac5818"), - felt::hex("0x266efd21a0eb3dfce14f674587ff74ffab37e8744e5a8b8188a6f75474b1bb8"), - felt::hex("0x7f2cf6670d503fa47a2fcfe982ad520417694c981ec3213a6a0b315a91853f"), - felt::hex("0x1a04f47d001c1802b130735feb4cf8ac139d60409d1df0dbc84f0d11fe14fb2"), - felt::hex("0x14801d01e5a149db6a88d2ffb89c31c53f6f7e15ee11a0ed9c3c8a463c30a3b"), - felt::hex("0x14a6aab15336862b05fa608bfbf6af238512678f9f748e393b3f1bb669856f6"), - felt::hex("0x641b3182a1ecaa7770c6cdea8c5d52f9820aa511626fc7383bd8ea39d7d9556"), + felt::hex("0x4dfdff911ae2581ed87e19ff875034d604bc4fa4fb38f1299d41b989aa47250"), + felt::hex("0x5235d70e1f2230aea41a85f98316aab145f359e59942286adc8187d8005e454"), + felt::hex("0x37603476f5d3fa4ff2b8de6e7a5cb5d845db5afd1248ea2eb39b51e973eeee4"), + felt::hex("0x78b3b7931cdfd6cf65ffcd7a0c2c56efd7d1e718530e6b8ba2f13b32505983f"), ], ]; - let data_queries = BTreeSet::from([RowCol::new(1, 0)]); + let data_queries = BTreeSet::from([RowCol::new(2, 1)]); let integrity_queries = BTreeSet::from([RowCol::new(1, 1)]); let proof = get_proof( field_element_size, @@ -430,88 +330,68 @@ mod tests { let field_element_size = 32; let n_columns = 2; - let n_segments = 2; - let n_rows_per_segment = 2; - let exp_proof = vec![ - 163, 61, 160, 50, 58, 163, 46, 46, 144, 26, 189, 3, 73, 205, 186, 105, 80, 153, 14, 64, - 202, 89, 173, 132, 33, 0, 8, 209, 212, 80, 182, 192, 0, 210, 42, 48, 209, 245, 11, 243, - 202, 15, 91, 117, 182, 147, 221, 5, 146, 48, 120, 157, 62, 94, 190, 220, 29, 83, 207, - 175, 70, 69, 183, 180, 1, 40, 210, 59, 100, 158, 198, 58, 39, 236, 218, 238, 119, 54, - 0, 208, 242, 62, 75, 140, 46, 83, 252, 40, 207, 140, 175, 47, 214, 64, 54, 107, 6, 154, - 126, 47, 100, 203, 203, 119, 211, 24, 94, 121, 58, 135, 85, 52, 177, 154, 115, 70, 9, - 9, 240, 236, 162, 162, 154, 178, 216, 221, 148, 226, 48, 164, 217, 129, 217, 118, 121, - 65, 11, 7, 102, 122, 85, 63, 234, 229, 157, 120, 247, 56, 68, 38, 203, 203, 19, 45, 76, - 198, 216, 197, 202, 219, 48, 195, 62, 89, 68, 91, 79, 254, 27, 2, 193, 140, 159, 123, - 81, 125, 215, 66, 149, 205, 50, 167, 187, 5, 192, 3, 241, 33, 212, 82, 160, 167, - ]; - let data_queries = BTreeSet::from([RowCol::new(0, 1)]); - let integrity_queries = BTreeSet::from([RowCol::new(2, 1)]); - let table_data = vec![ - vec![ - felt::hex("0xd22a30d1f50bf3ca0f5b75b693dd059230789d3e5ebedc1d53cfaf4645b7b4"), - felt::hex("0x1ac1fb9d0eeafa19dfc56830ff2edbf581f26d789da1d3ae07b63c759378593"), - felt::hex("0x69a7e2f64cbcb77d3185e793a875534b19a73460909f0eca2a29ab2d8dd94e2"), - felt::hex("0x4e89b01367ed9a45b9b10975fae4d5e2d29d0f7d668651af3a5860c703ebd0e"), - ], - vec![ - felt::hex("0x128d23b649ec63a27ecdaee773600d0f23e4b8c2e53fc28cf8caf2fd640366b"), - felt::hex("0x38ef7a0b6c3ec5326f1b7085f8b386772c40aa489bb6bc696b6d6a6641b58f"), - felt::hex("0x14e5560b7d64f357ba56f9d7e1069cddd7077b08946774a6526f49e6a52df6"), - felt::hex("0x8e3860d765b88c45198a0389f9e70fc3f80dd4ca9e3122086f3b2fd46cd49b"), - ], - ]; - let proof = get_proof( - field_element_size, - n_columns, - n_segments, - n_rows_per_segment, - table_data.clone(), - &data_queries, - &integrity_queries, - ); - assert_eq!(proof, exp_proof); - test_table_verifier_with( - field_element_size, - n_columns, - n_segments, - n_rows_per_segment, - exp_proof, - &data_queries, - &integrity_queries, - table_data, - ); - - let field_element_size = 32; - let n_columns = 2; - let n_segments = 2; - let n_rows_per_segment = 2; + let n_segments = 4; + let n_rows_per_segment = 4; let exp_proof = vec![ - 117, 154, 26, 12, 245, 174, 21, 247, 76, 146, 171, 173, 168, 69, 77, 201, 119, 255, - 216, 16, 224, 24, 236, 246, 26, 172, 156, 20, 2, 158, 208, 116, 6, 51, 58, 116, 136, - 76, 255, 130, 148, 164, 10, 94, 142, 63, 57, 36, 91, 80, 135, 9, 107, 19, 89, 70, 171, - 179, 138, 203, 65, 56, 71, 206, 0, 131, 236, 251, 134, 226, 39, 8, 28, 73, 163, 251, - 31, 136, 75, 227, 194, 44, 68, 26, 123, 71, 244, 25, 247, 87, 203, 86, 54, 207, 89, - 227, 7, 16, 235, 177, 127, 237, 120, 2, 189, 43, 76, 147, 187, 27, 40, 129, 93, 70, 78, - 114, 123, 236, 35, 190, 180, 223, 22, 244, 44, 110, 143, 211, 139, 213, 109, 53, 238, - 63, 71, 189, 49, 121, 83, 216, 81, 171, 110, 63, 244, 210, 142, 99, 113, 41, 18, 221, - 79, 229, 148, 185, 143, 115, 204, 12, + 213, 213, 177, 165, 226, 238, 237, 187, 239, 75, 171, 237, 159, 224, 47, 210, 113, 120, + 159, 234, 156, 171, 107, 153, 45, 134, 125, 185, 165, 124, 165, 233, 5, 237, 195, 55, + 176, 18, 11, 121, 210, 192, 153, 60, 189, 117, 57, 66, 231, 84, 41, 84, 66, 206, 224, + 249, 109, 41, 65, 150, 14, 148, 211, 232, 2, 216, 198, 72, 53, 212, 63, 183, 4, 146, + 91, 35, 60, 83, 218, 79, 179, 20, 126, 153, 119, 40, 177, 254, 36, 28, 161, 238, 102, + 198, 127, 135, 1, 200, 118, 247, 247, 78, 83, 73, 118, 161, 178, 159, 159, 65, 4, 41, + 45, 82, 178, 167, 234, 206, 188, 116, 56, 147, 74, 178, 145, 204, 2, 153, 178, 45, 50, + 72, 90, 79, 144, 182, 0, 244, 104, 208, 111, 85, 29, 175, 116, 104, 65, 57, 18, 107, + 89, 146, 44, 229, 213, 220, 123, 72, 12, 212, 252, 85, 91, 203, 200, 5, 229, 236, 68, + 173, 25, 237, 210, 121, 5, 52, 247, 90, 21, 103, 127, 84, 37, 37, 69, 40, 140, 181, 87, + 195, 90, 108, 114, 65, 181, 9, 236, 138, 141, 73, 182, 146, 120, 44, 92, 138, 222, 131, + 83, 19, 247, 213, 203, 250, 148, 186, 41, 191, 150, 119, 100, 228, 98, 126, 130, 237, + 197, 61, 214, 140, 250, 143, 57, 36, 44, 144, 103, 140, 113, 11, 207, 171, 86, 24, 246, + 39, 241, 166, 125, 204, 64, 237, 68, 32, 248, 107, 0, 139, 2, 33, 73, 191, 229, 208, + 174, 238, 94, 47, 252, 55, 92, 213, 9, 66, 150, 58, 127, 228, 239, 204, 37, 17, 54, 39, + 91, 166, 17, 185, 71, 34, 116, 141, 254, 25, 176, 131, 165, 139, 132, 173, 34, 200, + 157, 75, 92, 80, 245, 30, 92, 14, 238, 6, 61, 228, 51, 215, 105, 230, 54, 23, ]; - let data_queries = BTreeSet::from([RowCol::new(2, 0)]); - let integrity_queries = BTreeSet::from([RowCol::new(3, 0)]); let table_data: Vec> = vec![ vec![ - felt::hex("0x6511595ef10430d2f8528d0acec2e81be1ee9e76186f6e8b2c891b6dfceda8d"), - felt::hex("0x5022a1b86e36fd3dec29562add968244cd5ad09bbb2aa2ee918ba700fd651f0"), - felt::hex("0x6333a74884cff8294a40a5e8e3f39245b5087096b135946abb38acb413847ce"), - felt::hex("0x372aeaa69f776f2b6e5b18a6fa433b6dc209657bb8097f52dd1833d2187f7f0"), + felt::hex("0x6b61e5e37d71e0664a158a6b0b40746ca94948919796e73542f93e17d5a3607"), + felt::hex("0x2f398bd491bd26dc058c2ecd7bcf0258449b5014394d1f542dd7dd6d5a810f"), + felt::hex("0x2ce4d6c5b0c41db23fc9a7d0259c810a8bf78cba78693ce1de165e84ef331fb"), + felt::hex("0x1676f7e38853efe0993b0ca39770c85a2a74ab4410aff111ef09f731e3d8f02"), + felt::hex("0x3ce7cbdfa3e803f88330ee9dee4cc06e9fb31acc920bb86d7fff75adfce68d1"), + felt::hex("0x23ad43f3e074a0cabe1f4b71156ed8b3ba7c596b6093e458d4ee761ddeb54e1"), + felt::hex("0x76f3607f255412f819de7b7bcf7f7b382a35e632da12d2d6840dc7ff14ad425"), + felt::hex("0x569a30ef8867bf7ec22006eda33665baddc4c6821686f2d94c67dd0b2abd3f5"), + felt::hex("0x361e712a3255b0841239fcca9e774ee3b6e3350d1ec34c1f9bc6eadd81098a2"), + felt::hex("0x571887f985063922244e200898841d2a364397b7a06aac13e17eb0b733d2ac4"), + felt::hex("0x224465b14e6232f7f809e543d03e16cb632e0a206e94b5c56aabdfe98ec36cc"), + felt::hex("0x43ffbf71db9eed004425f8a2e215eb6d5d88dd12d5843605bbd8883d3b71c34"), + felt::hex("0x35d6274d307c0de2acb0aaafa0a576068a5f44f0f24070b5a415bb9b9015c9e"), + felt::hex("0x2ccc9300946d38a27347c686b1e065b9edfdf1a23154abc5d18ff273963bf73"), + felt::hex("0x2d244816b937b35975812b54429b9dd2cff556d25f87eb326f4e450507b104d"), + felt::hex("0x277c86abe7bde49b79da996f10b5907893b1af902c5a6df4b3a413ff238f73f"), ], vec![ - felt::hex("0x9ddc2089369cbd1d2291933e9c58c82c819a64d36d22d5781bee83670a5e5d"), - felt::hex("0x559f66594e0e5576e00f3d95e01bd6de98af0ab071bed5348e9d1d690ede347"), - felt::hex("0x83ecfb86e227081c49a3fb1f884be3c22c441a7b47f419f757cb5636cf59e3"), - felt::hex("0x710ebb17fed7802bd2b4c93bb1b28815d464e727bec23beb4df16f42c6e8fd3"), + felt::hex("0x26a8ebb2008def3d50fd4e88d07c96abaec6a5b9905040423eb3b7a1c1437b9"), + felt::hex("0x28fdc6a84a1e295866196d8e0ab5f0ab23aaafc2ba1aefad3ed3c9575da610e"), + felt::hex("0x5e7e4d6c8a5be024d40682dd5be4ce44fa28d24b4d1c89104d8eb4f5c2cd6b2"), + felt::hex("0x497dd7f9ecade7d73e5423b822caec6a77af0a1f999b4a3a8da9313b344e3e6"), + felt::hex("0x76d1cffe494038f439b328505a8639c0a3853002362a55575f5cd93918cdf51"), + felt::hex("0x5eb0dd4ad0149429efa97f9f0c197c45324b9aea2a8a13b6fd0b6ffc9705d26"), + felt::hex("0xa3dd054500d84ed78114835e82b8909e46dbd76a8d26fdcf8d712f702ed7c"), + felt::hex("0x4d86fd464ead1cc4bc9107d591b1d6d34af4eb432b53b252a82b2bfa315fa24"), + felt::hex("0x1bf62c26db7d75f955b5f8bc4a8baf22ab9ef0856e668d7abaece61bda4662f"), + felt::hex("0x36db5201aa25816e94904c9427518a8f69d79f91b28e8aa9e9022503e53ee2e"), + felt::hex("0x195c33f1b5aef25657215324a9f5fa84a44b0ab837651df2457eae90957747b"), + felt::hex("0x66e09f5b69171a5ebae282fdb794cccdb3eada1a82daceb701921db3012d292"), + felt::hex("0x1bcd3608703d59c5be5343b3dbe98b06af419c427b3db2bd3a68d1c3b26b7f1"), + felt::hex("0x78204fae7022e05499174460bf6de3901d8f71a530321942ed959e2a55f3ca1"), + felt::hex("0x47ad85f8d4b82ac6733f2fa54430e0887931c2552439509b6c1f3b9fd7b3326"), + felt::hex("0x28f69d8bb4a99e6ea11efbc845291958d83fabbfe2937be8616c62f02142c45"), ], ]; + let data_queries = BTreeSet::from([RowCol::new(7, 1), RowCol::new(11, 0)]); + let integrity_queries = + BTreeSet::from([RowCol::new(4, 1), RowCol::new(7, 0), RowCol::new(11, 1)]); let proof = get_proof( field_element_size, n_columns, @@ -531,7 +411,7 @@ mod tests { &data_queries, &integrity_queries, table_data, - ) + ); } fn get_random_queries( diff --git a/felt/Cargo.toml b/felt/Cargo.toml index 96e1a57..5951ae0 100644 --- a/felt/Cargo.toml +++ b/felt/Cargo.toml @@ -2,6 +2,7 @@ name = "felt" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] ark-ff.workspace = true diff --git a/fri/Cargo.toml b/fri/Cargo.toml index a984822..16899e1 100644 --- a/fri/Cargo.toml +++ b/fri/Cargo.toml @@ -2,6 +2,7 @@ name = "fri" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] ark-ff.workspace = true diff --git a/fri/src/committed_layers.rs b/fri/src/committed_layers.rs new file mode 100644 index 0000000..e79a781 --- /dev/null +++ b/fri/src/committed_layers.rs @@ -0,0 +1,101 @@ +use crate::{ + details::next_layer_data_and_integrity_queries, layers::FriLayer, parameters::FriParameters, +}; +use anyhow::Ok; +use ark_ff::PrimeField; +use ark_poly::EvaluationDomain; +use channel::fs_prover_channel::FSProverChannel; +use commitment_scheme::table_prover::TableProver; +use commitment_scheme::CommitmentHashes; +use randomness::Prng; +use sha3::Digest; +use std::sync::Arc; + +#[allow(dead_code)] +pub struct FriCommittedLayer, P: Prng, W: Digest> { + fri_step: usize, + layer: Arc>, + params: FriParameters, + layer_num: usize, + table_prover: TableProver, +} + +#[allow(dead_code)] +impl< + F: PrimeField, + E: EvaluationDomain, + P: Prng + Clone + 'static, + W: Digest + Clone + 'static, + > FriCommittedLayer +{ + #[allow(clippy::too_many_arguments)] + pub fn new( + fri_step: usize, + layer: Arc>, + params: FriParameters, + layer_num: usize, + field_element_size_in_bytes: usize, + n_verifier_friendly_commitment_layers: usize, + commitment_hashes: CommitmentHashes, + channel: &mut FSProverChannel, + mont_r: F, + ) -> Self { + let layer_size = layer.get_layer_size(); + + let mut table_prover = TableProver::new( + 1, + layer_size / (1 << fri_step), + 1 << fri_step, + field_element_size_in_bytes, + n_verifier_friendly_commitment_layers, + commitment_hashes, + mont_r, + ); + + let segment = layer.get_layer().unwrap(); + table_prover.add_segment_for_commitment(&[segment], 0, 1 << fri_step); + table_prover.commit(channel).unwrap(); + + Self { + fri_step, + layer, + params, + layer_num, + table_prover, + } + } + + pub fn eval_at_points(&self, required_row_indices: &[usize]) -> Vec> { + let coset_size = 1 << self.params.fri_step_list[self.layer_num]; + let mut elements_data_vectors = Vec::with_capacity(coset_size); + + for col in 0..coset_size { + let mut required_indices: Vec = Vec::new(); + + for &row in required_row_indices { + required_indices.push(row * coset_size + col); + } + + let eval_result = self.layer.eval_at_points(&required_indices); + elements_data_vectors.push(eval_result); + } + + elements_data_vectors + } + + pub fn decommit( + &mut self, + queries: &[u64], + channel: &mut FSProverChannel, + ) -> Result<(), anyhow::Error> { + let (data_queries, integrity_queries) = + next_layer_data_and_integrity_queries(&self.params, queries, self.layer_num); + let required_row_indices = self + .table_prover + .start_decommitment_phase(data_queries.clone(), integrity_queries.clone()); + + let elements_data = self.eval_at_points(&required_row_indices); + self.table_prover.decommit(channel, &elements_data)?; + Ok(()) + } +} diff --git a/fri/src/details.rs b/fri/src/details.rs index 9ada595..4ff9bce 100644 --- a/fri/src/details.rs +++ b/fri/src/details.rs @@ -50,6 +50,7 @@ pub fn apply_fri_layers>( let mut cur_layer = elements.to_vec(); for basis_index in cumulative_fri_step..(cumulative_fri_step + layer_fri_step) { let fft_domain = params.fft_domains[basis_index]; + let mut next_layer = Vec::with_capacity(cur_layer.len() / 2); for j in (0..cur_layer.len()).step_by(2) { let res = MultiplicativeFriFolder::next_layer_element_from_two_previous_layer_elements( @@ -162,6 +163,7 @@ mod tests { folder::MultiplicativeFriFolder, stone_domain::{get_field_element_at_index, make_fft_domains}, }; + use ark_ff::Field; use ark_ff::UniformRand; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, Polynomial}; use felt::Felt252; @@ -185,7 +187,9 @@ mod tests { elements[0], elements[1], eval_point, - get_field_element_at_index(&bases[0], coset_offset), + get_field_element_at_index(&bases[0], coset_offset) + .inverse() + .unwrap(), ); assert_eq!(fri_out, two_to_one_out); @@ -198,20 +202,26 @@ mod tests { elements2[0], elements2[1], eval_point, - get_field_element_at_index(&bases[1], coset_offset2), + get_field_element_at_index(&bases[1], coset_offset2) + .inverse() + .unwrap(), ); let fold_2_3 = MultiplicativeFriFolder::next_layer_element_from_two_previous_layer_elements( elements2[2], elements2[3], eval_point, - get_field_element_at_index(&bases[1], coset_offset2 + 2), + get_field_element_at_index(&bases[1], coset_offset2 + 2) + .inverse() + .unwrap(), ); let two_to_one_out2 = MultiplicativeFriFolder::next_layer_element_from_two_previous_layer_elements( fold_0_1, fold_2_3, eval_point * eval_point, - get_field_element_at_index(&bases[2], coset_offset2 / 2), + get_field_element_at_index(&bases[2], coset_offset2 / 2) + .inverse() + .unwrap(), ); assert_eq!(fri_out2, two_to_one_out2); } diff --git a/fri/src/folder.rs b/fri/src/folder.rs index 3b83a92..2a56063 100644 --- a/fri/src/folder.rs +++ b/fri/src/folder.rs @@ -2,7 +2,7 @@ use crate::stone_domain::get_field_element_at_index; use anyhow::Error; use ark_ff::fields::batch_inversion; use ark_ff::{FftField, PrimeField}; -use ark_poly::Radix2EvaluationDomain; +use ark_poly::EvaluationDomain; use std::sync::Arc; pub struct MultiplicativeFriFolder; @@ -11,13 +11,13 @@ pub struct MultiplicativeFriFolder; impl MultiplicativeFriFolder { // Computes the values of the next FRI layer given the values and domain of the current layer. pub fn compute_next_fri_layer( - domain: Radix2EvaluationDomain, + domain: impl EvaluationDomain, input_layer: &[F], eval_point: F, ) -> Result, Error> { - assert_eq!(input_layer.len(), domain.size as usize); + assert_eq!(input_layer.len(), domain.size()); - let mut elements: Vec = (0..domain.size as usize) + let mut elements: Vec = (0..domain.size()) .map(|i| get_field_element_at_index(&domain, i)) .collect(); batch_inversion(&mut elements); @@ -48,16 +48,14 @@ impl MultiplicativeFriFolder { Self::fold(f_x, f_minus_x, eval_point, x_inv) } - /// Interpolating a line through (x, f(x)) and (-x, f(-x)) - /// then evaluating it at "eval_point" - /// Multiplicative case folding formula: - /// f(x) = g(x^2) + xh(x^2) - /// f(-x) = g((-x)^2) - xh((-x)^2) = g(x^2) - xh(x^2) - /// => - /// 2g(x^2) = f(x) + f(-x) - /// 2h(x^2) = (f(x) - f(-x))/x - /// => - /// 2g(x^2) + 2ah(x^2) = f(x) + f(-x) + a(f(x) - f(-x))/x. + // Multiplicative case folding formula: + // f(x) = g(x^2) + xh(x^2) + // f(-x) = g((-x)^2) - xh((-x)^2) = g(x^2) - xh(x^2) + // => + // 2g(x^2) = f(x) + f(-x) + // 2h(x^2) = (f(x) - f(-x))/x + // => + // 2g(x^2) + 2ah(x^2) = f(x) + f(-x) + a(f(x) - f(-x))/x. fn fold(f_x: F, f_minus_x: F, eval_point: F, x_inv: F) -> F { f_x + f_minus_x + eval_point * (f_x - f_minus_x) * x_inv } diff --git a/fri/src/layers.rs b/fri/src/layers.rs new file mode 100644 index 0000000..709a602 --- /dev/null +++ b/fri/src/layers.rs @@ -0,0 +1,355 @@ +use crate::folder::MultiplicativeFriFolder; +use anyhow::Error; +use ark_ff::PrimeField; +use ark_poly::EvaluationDomain; +use std::sync::Arc; + +pub trait FriLayer> { + fn get_layer_size(&self) -> usize; + fn get_domain(&self) -> E; + fn get_layer(&self) -> Result, Error>; + fn eval_at_points(&self, required_indices: &[usize]) -> Vec; +} + +#[derive(Clone)] +pub struct FriLayerReal> { + domain: E, + evaluation: Vec, +} + +#[allow(dead_code)] +impl> FriLayerReal { + pub fn new(domain: E, evaluation: Vec) -> Self { + Self { domain, evaluation } + } + + pub fn new_from_prev_layer(prev_layer: &dyn FriLayer) -> Self { + Self { + domain: prev_layer.get_domain(), + evaluation: prev_layer.get_layer().unwrap(), + } + } +} + +impl + 'static> FriLayer for FriLayerReal { + fn get_layer_size(&self) -> usize { + self.domain.size() + } + + fn get_domain(&self) -> E { + self.domain + } + + fn get_layer(&self) -> Result, Error> { + Ok(self.evaluation.clone()) + } + + fn eval_at_points(&self, required_indices: &[usize]) -> Vec { + required_indices + .iter() + .map(|&i| self.evaluation[i]) + .collect() + } +} + +pub struct FriLayerProxy> { + domain: E, + prev_layer: Arc>, + eval_point: F, +} + +#[allow(dead_code)] +impl> FriLayerProxy { + pub fn new(prev_layer: Arc>, eval_point: F) -> Self { + let prev_layer_domain = prev_layer.get_domain(); + let current_domain = { + assert!(prev_layer_domain.size().is_power_of_two()); + let coset_size = prev_layer_domain.size() / 2; + let coset_offset = prev_layer_domain.coset_offset().square(); + E::new_coset(coset_size, coset_offset).unwrap() + }; + + Self { + domain: current_domain, + prev_layer, + eval_point, + } + } +} + +impl + 'static> FriLayer for FriLayerProxy { + fn get_layer_size(&self) -> usize { + self.domain.size() + } + + fn get_domain(&self) -> E { + self.domain + } + + fn get_layer(&self) -> Result, Error> { + let prev_layer_domain = self.prev_layer.get_domain(); + let prev_eval = self.prev_layer.get_layer()?; + + MultiplicativeFriFolder::compute_next_fri_layer( + prev_layer_domain, + &prev_eval, + self.eval_point, + ) + } + + fn eval_at_points(&self, _required_indices: &[usize]) -> Vec { + unimplemented!("Should never be called") + } +} + +#[cfg(test)] +mod test { + + use super::*; + use crate::lde::MultiplicativeLDE; + use crate::stone_domain::get_field_element_at_index; + + use ark_ff::Field; + use ark_ff::UniformRand; + use ark_poly::{ + domain::EvaluationDomain, univariate::DensePolynomial, DenseUVPolynomial, Polynomial, + Radix2EvaluationDomain, + }; + use felt::Felt252; + + fn init_test( + eval_point: Felt252, + coeffs: Vec, + log2_eval_domain: usize, + ) -> ( + FriLayerReal>, + FriLayerProxy>, + ) { + let n = 1 << log2_eval_domain; + + let offset = Felt252::ONE; + let domain = Radix2EvaluationDomain::new_coset(n, offset).unwrap(); + + let poly = DensePolynomial::from_coefficients_vec(coeffs); + let evals: Vec = { + let mut values = vec![]; + for i in 0..domain.size as usize { + let x = &get_field_element_at_index(&domain, i); + values.push(poly.evaluate(&x)); + } + values + }; + + let layer_0 = FriLayerReal::new(domain, evals); + let layer_1_proxy = FriLayerProxy::new(Arc::new(layer_0.clone()), eval_point); + + (layer_0, layer_1_proxy) + } + + fn init_more( + layer_1_proxy: &FriLayerProxy>, + eval_point: Felt252, + ) -> ( + FriLayerReal>, + FriLayerProxy>, + FriLayerReal>, + ) { + let layer_2 = FriLayerReal::new_from_prev_layer(layer_1_proxy); + let layer_3_proxy = FriLayerProxy::new(Arc::new(layer_2.clone()), eval_point); + let layer_4 = FriLayerReal::new_from_prev_layer(&layer_3_proxy); + (layer_2, layer_3_proxy, layer_4) + } + + #[test] + fn test_layers() { + let eval_point = + felt::hex("0x5603beb2e3083fd80de72875732256ff84981639ea7afd69efab1627aa8af1f"); + let coeffs = vec![ + felt::hex("0x2306affe402b4c69c033b8fbe082d4037e7a6daf1ebd5b9dc653d845f2cf4f9"), + felt::hex("0x75d89ba077ef16d757ca6fa2ec4d725af482ed3db12c20f33a489e97b18d8a7"), + felt::hex("0x68fc432c07c647486b44283bf8215ccd43deb6da7dae694b9eac6ffe4c3036c"), + felt::hex("0x5ef686e27d7630ea786125d1d8262b7539d13ce7532ad2e47ca7c0df44d5f8c"), + ]; + let exp_evals = vec![ + felt::hex("0xce883fcba8216bbe28c5bbd516b0afc7e18dcc9ffebd900931a9afc03cdeda"), + felt::hex("0xce883fcba8216bbe28c5bbd516b0afc7e18dcc9ffebd900931a9afc03cdeda"), + felt::hex("0xce883fcba8216bbe28c5bbd516b0afc7e18dcc9ffebd900931a9afc03cdeda"), + felt::hex("0xce883fcba8216bbe28c5bbd516b0afc7e18dcc9ffebd900931a9afc03cdeda"), + ]; + + let first_layer_degree_bound = coeffs.len(); + let (layer_0, layer_1_proxy) = init_test(eval_point, coeffs, 4); + let (layer_2, layer_3_proxy, layer_4) = init_more(&layer_1_proxy, eval_point); + + // Test get_layer_size() + assert_eq!(layer_0.get_layer_size(), 16); + assert_eq!(layer_1_proxy.get_layer_size(), 8); + assert_eq!(layer_2.get_layer_size(), 8); + assert_eq!(layer_3_proxy.get_layer_size(), 4); + assert_eq!(layer_4.get_layer_size(), 4); + + // Test first layer degree check + let layer_0_eval = layer_0.get_layer().unwrap(); + let mut layer_0_lde_manager = MultiplicativeLDE::new(layer_0.get_domain(), true); + layer_0_lde_manager.add_eval(&layer_0_eval); + let lde_manager_coef = layer_0_lde_manager.coeffs(0); + let layer_0_deg = { + let mut deg = 0; + for i in (0..lde_manager_coef.len()).rev() { + if lde_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_0_deg, first_layer_degree_bound - 1); + + // Test Proxy Layer + let layer_1_eval = layer_1_proxy.get_layer().unwrap(); + let mut layer_1_lde_manager = MultiplicativeLDE::new(layer_1_proxy.get_domain(), true); + layer_1_lde_manager.add_eval(&layer_1_eval); + let lde_1_manager_coef = layer_1_lde_manager.coeffs(0); + let layer_1_deg = { + let mut deg = 0; + for i in (0..lde_1_manager_coef.len()).rev() { + if lde_1_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_1_deg, first_layer_degree_bound / 2 - 1); + let folded_layer = MultiplicativeFriFolder::compute_next_fri_layer( + layer_0.get_domain(), + &layer_0_eval, + eval_point, + ) + .unwrap(); + assert_eq!(folded_layer, layer_1_eval); + + // Test Real Layer + let layer_2_eval = layer_2.get_layer().unwrap(); + let mut layer_2_lde_manager = MultiplicativeLDE::new(layer_2.get_domain(), true); + layer_2_lde_manager.add_eval(&layer_2_eval); + let lde_2_manager_coef = layer_2_lde_manager.coeffs(0); + let layer_2_deg = { + let mut deg = 0; + for i in (0..lde_2_manager_coef.len()).rev() { + if lde_2_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_2_deg, first_layer_degree_bound / 2 - 1); + let folded_layer = MultiplicativeFriFolder::compute_next_fri_layer( + layer_0.get_domain(), + &layer_0_eval, + eval_point, + ) + .unwrap(); + assert_eq!(folded_layer, layer_2_eval); + + // Test evaluations + let layer_eval = layer_4.get_layer().unwrap(); + let evals = layer_4.eval_at_points(&[0, 1, 2, 3]); + assert_eq!(layer_eval, exp_evals); + assert_eq!(layer_eval, evals); + } + + #[test] + fn test_layers_random() { + let mut rng = rand::thread_rng(); + + let log2_eval_domain = 10; + let first_layer_degree_bound = 320; + let eval_point = Felt252::rand(&mut rng); + let coeffs: Vec = (0..first_layer_degree_bound) + .map(|_| Felt252::rand(&mut rng)) + .collect(); + + let (layer_0, layer_1_proxy) = init_test(eval_point, coeffs, log2_eval_domain); + let (layer_2, layer_3_proxy, layer_4) = init_more(&layer_1_proxy, eval_point); + + // Test get_layer_size() + assert_eq!(layer_0.get_layer_size(), 1024); + assert_eq!(layer_1_proxy.get_layer_size(), 512); + assert_eq!(layer_2.get_layer_size(), 512); + assert_eq!(layer_3_proxy.get_layer_size(), 256); + assert_eq!(layer_4.get_layer_size(), 256); + + // Test first layer degree check + let layer_0_eval = layer_0.get_layer().unwrap(); + let mut layer_0_lde_manager = MultiplicativeLDE::new(layer_0.get_domain(), true); + layer_0_lde_manager.add_eval(&layer_0_eval); + let lde_manager_coef = layer_0_lde_manager.coeffs(0); + let layer_0_deg = { + let mut deg = 0; + for i in (0..lde_manager_coef.len()).rev() { + if lde_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_0_deg, first_layer_degree_bound - 1); + + // Test Proxy Layer + let layer_1_eval = layer_1_proxy.get_layer().unwrap(); + let mut layer_1_lde_manager = MultiplicativeLDE::new(layer_1_proxy.get_domain(), true); + layer_1_lde_manager.add_eval(&layer_1_eval); + let lde_1_manager_coef = layer_1_lde_manager.coeffs(0); + let layer_1_deg = { + let mut deg = 0; + for i in (0..lde_1_manager_coef.len()).rev() { + if lde_1_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_1_deg, first_layer_degree_bound / 2 - 1); + let folded_layer = MultiplicativeFriFolder::compute_next_fri_layer( + layer_0.get_domain(), + &layer_0_eval, + eval_point, + ) + .unwrap(); + assert_eq!(folded_layer, layer_1_eval); + + // Test Real Layer + let layer_2_eval = layer_2.get_layer().unwrap(); + let mut layer_2_lde_manager = MultiplicativeLDE::new(layer_2.get_domain(), true); + layer_2_lde_manager.add_eval(&layer_2_eval); + let lde_2_manager_coef = layer_2_lde_manager.coeffs(0); + let layer_2_deg = { + let mut deg = 0; + for i in (0..lde_2_manager_coef.len()).rev() { + if lde_2_manager_coef[i] != Felt252::ZERO { + deg = i; + break; + } + } + deg + }; + assert_eq!(layer_2_deg, first_layer_degree_bound / 2 - 1); + let folded_layer = MultiplicativeFriFolder::compute_next_fri_layer( + layer_0.get_domain(), + &layer_0_eval, + eval_point, + ) + .unwrap(); + assert_eq!(folded_layer, layer_2_eval); + + // Test evaluations + let layer_eval = layer_4.get_layer().unwrap(); + let index: Vec = (0..256).collect(); + let evals = layer_4.eval_at_points(&index); + assert_eq!(layer_eval, evals); + } +} diff --git a/fri/src/lib.rs b/fri/src/lib.rs index 7f96647..95f26cf 100644 --- a/fri/src/lib.rs +++ b/fri/src/lib.rs @@ -1,7 +1,10 @@ +mod committed_layers; mod details; mod folder; +mod layers; mod lde; mod parameters; +mod prover; mod stone_domain; mod test; mod verifier; diff --git a/fri/src/parameters.rs b/fri/src/parameters.rs index b0f034d..132b39f 100644 --- a/fri/src/parameters.rs +++ b/fri/src/parameters.rs @@ -4,8 +4,9 @@ use ark_ff::FftField; use ark_poly::EvaluationDomain; use serde::Deserialize; -#[derive(Deserialize, Clone)] +#[derive(Deserialize)] #[allow(dead_code)] +#[derive(Clone)] pub struct FriParameters> { #[serde(skip)] pub ph: PhantomData, @@ -71,17 +72,3 @@ impl> FriParameters { self } } - -#[allow(dead_code)] -pub struct FriProverConfig { - pub max_non_chunked_layer_size: u64, - pub n_chunks_between_layers: usize, - pub log_n_max_in_memory_fri_layer_elements: usize, -} - -#[allow(dead_code)] -impl FriProverConfig { - pub const DEFAULT_MAX_NON_CHUNKED_LAYER_SIZE: u64 = 32768; - pub const DEFAULT_NUMBER_OF_CHUNKS_BETWEEN_LAYERS: usize = 32; - pub const ALL_IN_MEMORY_LAYERS: usize = 63; -} diff --git a/fri/src/prover.rs b/fri/src/prover.rs new file mode 100644 index 0000000..d88e745 --- /dev/null +++ b/fri/src/prover.rs @@ -0,0 +1,651 @@ +use crate::{ + committed_layers::FriCommittedLayer, + details::choose_query_indices, + layers::{FriLayer, FriLayerProxy, FriLayerReal}, + lde::MultiplicativeLDE, + parameters::FriParameters, +}; +use anyhow::{Error, Ok}; +use ark_ff::PrimeField; +use ark_poly::{EvaluationDomain, Radix2EvaluationDomain}; +use channel::{fs_prover_channel::FSProverChannel, Channel, ProverChannel}; +use commitment_scheme::CommitmentHashes; +use num_bigint::BigUint; +use randomness::Prng; +use sha3::Digest; +use std::sync::Arc; + +#[allow(dead_code)] +pub struct FriProver { + params: FriParameters>, + witness: Vec, + n_layers: usize, + committed_layers: Vec, P, W>>, + mont_r: F, +} + +#[allow(dead_code)] +impl< + F: PrimeField>, + P: Prng + Clone + 'static, + W: Digest + Clone + 'static, + > FriProver +{ + fn new(params: FriParameters>, witness: Vec) -> Self { + let n_layers = params.fri_step_list.len(); + let committed_layers = Vec::with_capacity(n_layers - 1); + let mont_r = { + let size = F::MODULUS_BIT_SIZE.div_ceil(8) * 8; + let mont_bigint = BigUint::from(2u64).modpow(&BigUint::from(size), &F::MODULUS.into()); + F::from_bigint(::BigInt::try_from(mont_bigint.clone()).unwrap()) + .unwrap() + }; + Self { + params, + witness, + n_layers, + committed_layers, + mont_r, + } + } + + fn create_next_fri_layer( + channel: &mut FSProverChannel, + layer: Arc>>, + fri_step: usize, + ) -> Arc>> { + if fri_step != 0 { + let mut current_layer: Arc>> = layer; + + let mut eval_point = channel.draw_felem(); + + for _ in 0..fri_step { + current_layer = Arc::new(FriLayerProxy::new(current_layer, eval_point)); + eval_point = eval_point.square(); + } + + current_layer + } else { + layer + } + } + + fn commitment_phase( + &mut self, + channel: &mut FSProverChannel, + n_verifier_friendly_commitment_layers: usize, + commitment_hashes: CommitmentHashes, + ) -> Arc>> { + assert_eq!(self.witness.len(), self.params.fft_domains[0].size()); + + let first_layer: Arc>> = Arc::new( + FriLayerReal::new(self.params.fft_domains[0], self.witness.clone()), + ); + let mut current_layer = first_layer; + + for layer_num in 1..=self.n_layers { + let fri_step = self.params.fri_step_list[layer_num - 1]; + let next_fri_step = if layer_num < self.n_layers { + self.params.fri_step_list[layer_num] + } else { + 0 + }; + + assert!((layer_num == 1) || (fri_step != 0)); + + current_layer = + FriProver::::create_next_fri_layer(channel, current_layer, fri_step); + + current_layer = Arc::new(FriLayerReal::new_from_prev_layer(&*current_layer)); + + if layer_num == self.n_layers { + break; + } + + let committed_layer = FriCommittedLayer::new( + next_fri_step, + current_layer.clone(), + self.params.clone(), + layer_num, + F::MODULUS_BIT_SIZE.div_ceil(8) as usize, + n_verifier_friendly_commitment_layers, + commitment_hashes.clone(), + channel, + self.mont_r, + ); + + self.committed_layers.push(committed_layer); + } + + current_layer + } + + fn send_last_layer( + &self, + channel: &mut FSProverChannel, + last_layer: Arc>>, + ) -> Result<(), Error> { + let last_layer_basis_index: usize = self.params.fri_step_list.iter().sum(); + let last_layer_evaluations = last_layer.get_layer()?; + + let lde_domain = self.params.fft_domains[last_layer_basis_index]; + let mut lde_manager: MultiplicativeLDE = MultiplicativeLDE::new(lde_domain, true); + lde_manager.add_eval(&last_layer_evaluations); + + let coefficients = lde_manager.coeffs(0); + let degree = { + let mut deg = 0; + for i in (0..coefficients.len()).rev() { + if coefficients[i] != F::ZERO { + deg = i; + break; + } + } + deg + }; + let degree_bound = self.params.last_layer_degree_bound; + assert!(degree < degree_bound); + + let coeffs_mont = to_mont_repr(&[coefficients.to_vec()], self.mont_r); + + assert_eq!(coeffs_mont.len(), 1); + + channel.send_felts(&coeffs_mont[0][0..degree_bound])?; + + Ok(()) + } + + fn prove_fri( + &mut self, + channel: &mut FSProverChannel, + n_verifier_friendly_commitment_layers: usize, + commitment_hashes: CommitmentHashes, + ) -> Result<(), Error> { + // Commitment phase. + let last_layer = self.commitment_phase( + channel, + n_verifier_friendly_commitment_layers, + commitment_hashes, + ); + + self.send_last_layer(channel, last_layer.clone())?; + + // Query phase. + let queries = choose_query_indices(&self.params, channel); + + // Note: following this line, the verifier must not send randomness to the prover. + channel.states.begin_query_phase(); + + // Decommitment phase. + for layer in &mut self.committed_layers { + layer.decommit(&queries, channel)?; + } + + Ok(()) + } +} + +pub fn to_mont_repr(segment: &[Vec], mont_r: F) -> Vec> { + let mut result: Vec> = Vec::with_capacity(segment.len()); + + for row in segment.iter() { + result.push(row.iter().cloned().map(|e| e * mont_r).collect()); + } + + result +} + +#[cfg(test)] +mod test { + use super::*; + use ark_ff::Field; + + use ark_poly::{ + univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain, Polynomial, + Radix2EvaluationDomain, + }; + use channel::{fs_prover_channel::FSProverChannel, ProverChannel}; + use commitment_scheme::SupportedHashes; + use felt::Felt252; + use randomness::{keccak256::PrngKeccak256, Prng}; + use sha3::Keccak256; + + use crate::stone_domain::get_field_element_at_index; + use crate::stone_domain::make_fft_domains; + + fn test_fri_correctness_with( + log2_eval_domain: usize, + fri_step_list: Vec, + last_layer_degree_bound: usize, + n_queries: usize, + proof_of_work_bits: usize, + seed: u64, + offset: Felt252, + coeffs: Vec, + witness: Vec, + ) -> Vec { + // Check coeffs evaluate to witness + { + let domain = Radix2EvaluationDomain::new_coset(1 << log2_eval_domain, offset).unwrap(); + let poly = DensePolynomial::from_coefficients_vec(coeffs); + let evals: Vec = { + let mut values = vec![]; + for i in 0..domain.size as usize { + let x = &get_field_element_at_index(&domain, i); + values.push(poly.evaluate(&x)); + } + values + }; + assert_eq!(evals, witness); + } + + let domains = make_fft_domains::(log2_eval_domain, offset); + + let params = FriParameters::new( + fri_step_list, + last_layer_degree_bound, + n_queries, + domains, + proof_of_work_bits, + ); + + let channel_prng = PrngKeccak256::new_with_seed(&seed.to_be_bytes()); + let mut prover_channel: FSProverChannel = + FSProverChannel::new(channel_prng); + + let mut prover: FriProver = + FriProver::new(params, witness); + prover + .prove_fri( + &mut prover_channel, + 0, + CommitmentHashes::from_single_hash(SupportedHashes::Blake2s256), + ) + .unwrap(); + + let proof = prover_channel.get_proof(); + proof + } + + #[test] + fn test_fri_prover_correctness() { + let log2_eval_domain = 5; + let fri_step_list = vec![0, 2, 2]; + let last_layer_degree_bound = 2; + let n_queries = 4; + let proof_of_work_bits = 15; + let coeffs = vec![ + felt::hex("0x586486754eaf979eaeb1a8a2db3f3cd613a38a511bb9687f89a35808c47cb71"), + felt::hex("0x14fea6df1f7b6dc67b136b814d911817c794f8033fcd72f61c13346f4998228"), + felt::hex("0x25d85db841b0d20c357cd5d0b185a84ac2b58bf378d9016816c10de344bbb20"), + felt::hex("0x777c088396717c19e3afe003c757175214ee9efb76225504deff72032f55b68"), + felt::hex("0x3e9a7deba4957c1a11789ad85023e3b39286200306a5afe2b90fca856708254"), + felt::hex("0x2b3493f9ad93560969a2f4e3e883b92930589416a13a37d5fa3015158f0fa81"), + felt::hex("0x3cf1da7b26dcf7ae63af541d4b08740953fa85a7a6a83e4c9fa13b4c821fac5"), + felt::hex("0x14251a199fc5cfe5bdfcf5a7f639050edf7f5f4ca9b96983b27ae0821885606"), + felt::hex("0xf65e7f29ff7eeb57d1ff26b589d56a13b652c0a4b4994d26c386cb31e369f8"), + felt::hex("0x46abd1d9886774ed3434729100447968398a155f1c192c4b1927d1397af7f5b"), + felt::hex("0x4c1d6b93d502b35aa6b5fe9905f478d55310a2e736f6b95fded0db86c7917ba"), + felt::hex("0x3c20c2cee041eaef1349d9d071a7b9f4b550b91c21d14a79c8e0b9f02bb4da9"), + felt::hex("0x1e9c9d130ee18553dff0c021c7d7a0a78233da6553fbed2390676ca69a32db2"), + felt::hex("0x1545ebc9ea27c409dc96a420a5adafbdef1a59733cbbf9452f4e125934954dc"), + felt::hex("0x10ecbc496594aac6842f6ecd5f051c8ad8f160289efea0a0cc5bd8ae987601a"), + felt::hex("0x5ed2ef2751544ca33053a8d152715dc749ad400a6b3f17693e10a62de87da0a"), + felt::hex("0x32b3d2b61f9722a273d31f549a35fcbdcd12f9099d6b5ae554d06b2db2f4d28"), + felt::hex("0x2dcf34cbbc197cd1e82289950098ad8c673e67191a01f2ffe1521f6ca4c281e"), + felt::hex("0xca612cda0a7078fe7e71db617b00db4e93e773c41014a7e58da5dba50fc9f3"), + felt::hex("0x4ae586257c90ec66325c1e7a59183bf0f89a9e0c8240c1e57f312b809222130"), + felt::hex("0x22b814a3d4dee809b5c4bcd1f4afd3acfc9a26a7cebcf5f3576ead25808bcf4"), + felt::hex("0x6aeeeb3faaf43fd810ae5ac9c16f78c3588a24d829ee5a4871c9d8eb2292c7c"), + felt::hex("0x4c7729363b7d5774e8169422bf6f031a5a5866f1b4198e8b59bba5584c03e8b"), + felt::hex("0x7f2f9cf24dcd07127c18ee83993e38157838fb5c704f236e621bb321c4dd58e"), + felt::hex("0x31beabb789a131ff885a3d5ba75819d3189b867f1faa8a3daf54063090a84be"), + felt::hex("0xbe3886f70f55c1f4d92afee42571d7d1648bd008c83f207c7c935e184233"), + felt::hex("0x4d62517f2822c8607a458224f7e6c856e1665be764f42e7f2afc3c9e1bc599a"), + felt::hex("0x27b2d798d19f3f38391e0eebb0481ec2379debc7e72a1d868c9446fb5aa18e"), + felt::hex("0x72f4ef956cd59cfa048abefb013409c6803d6e91afde17043420892c69bc912"), + felt::hex("0x154a3c3b23f0ad50456519e8e701c5a819f1aea17205f3ac9a4ecc44e77ad5b"), + felt::hex("0x3476c5e82e824b1b7a919d0a95a6b89a636f487a2374e9425995e703a0a558d"), + felt::hex("0x8ed8523025b5b3b294ea58b4ede32d22ee3825a6c48e5a82eab1593d205af6"), + ]; + let witness = vec![ + felt::hex("0x2037a21c5ea8104af0432ab63ab3e9a9bf66cceaeae73976ccd66de4e568417"), + felt::hex("0x139fdcf6674bd96dc8f9430e5848b4ed6367ec95f5b8f47002a5217e3edc14e"), + felt::hex("0x74c47cd9ad93a721c54df826e9a0d98f1e483f86345eec3cdaefb6a896486f7"), + felt::hex("0x53e83449c0a5e804d054d42a908ab734d80c1d10e05717a791af48548cc2904"), + felt::hex("0x712dd86d28fda2554a340d54405a2cc618e5a55d1c2dac0b9750ac9f5f6c388"), + felt::hex("0x6e5869ccae857d03a21532a19ebe15c05ebdcae60aee1c513d3e7399e6814f2"), + felt::hex("0x4d5e1422eb3b70e8c4e50aafacb53621a59d0610762eea29c7d427d0e40d77f"), + felt::hex("0x387ee019c812c6103fea3938125fa83e6f5622b58e262f55f783da66c139517"), + felt::hex("0x5c79ace9fed0d99ba88b74c062159d16d5f11b60a6560655ca1e410d88be120"), + felt::hex("0x6224c41fbd171f66bb49710257ad11ff8423ca1c62b69a4fa725eaacb236987"), + felt::hex("0x6e0f65996f3d3cae13241717427305d59c7791d4c44ef4e723946a337e9faf3"), + felt::hex("0x5bca0645831877dd14da19aab5d30dce063b30d879a4338cf67cb3d03c0a40b"), + felt::hex("0x7939504393ce11aeea9084c11e4024d12f0368ba34fa89d7ba636b1130863fd"), + felt::hex("0xb9d779f0703ca35f595a1ff35f9511536a245dd81a7dd1409aab904e581940"), + felt::hex("0x60610022db37f29e4c00251fb523f4979c8ac148edc6e4c90c152b3d697b66d"), + felt::hex("0x61ee871c01255160305b5f1ef0981bc466b66e7f861c0dd7bbc1e984cf731ca"), + felt::hex("0x14abfba914595259d38c398dfc40850550d52f5b15b168bf5cb2d25435a1e98"), + felt::hex("0x77ece7b6a00d25c9817e4683b9289f6da0271d39229a88598b3f8da9276ed2b"), + felt::hex("0x46a6e9c0959385b9b9cdf25950af72dab5b9e2f25ef7425f1da0fdff5816f42"), + felt::hex("0xe5ef75df36a25f3091361ffd2a97d376c401585a1d48d2130cd289b444b15a"), + felt::hex("0x4b1cb1c37ab03a7278e0b5189fb19858a4dfcc91dc6415987950663ef27d87a"), + felt::hex("0x66b225825072935ccf7759d6865c2ef87212e21f55c2f496415fe449205c2cd"), + felt::hex("0xb000298dd8707eaebab146f7d29ac602ca52144d6e856b2eb0e524accf4a6b"), + felt::hex("0x3dd2400fbbf473d3069d50be232c6ae3b44797bdb9df84465412215318b753b"), + felt::hex("0x315f8418be42f3ea08d7dd73bfa00fd6e337a019166fb0ec2c2f883589e9779"), + felt::hex("0x58e219b3f490edf02c33d8dcd2b80f65a804cf6a774b62c7bf0bb28697e504b"), + felt::hex("0x4b346fe2bff5e0eb019bb24cab1d02bc77004bbf4abfa979b0206f0c26635b6"), + felt::hex("0x3b70da30aa9801158bbc0b455712a11b61a6cca4c2dd6e93798fa145a31b6a4"), + felt::hex("0x7a3a6e5476513f09b87a03b3c1e9b0cfba62e7576cf0941469130cd0297164e"), + felt::hex("0x7aeb5111daf9b7d45aac77eda98d7fccd44b8c136f4417862f4116f51be973b"), + felt::hex("0x28d8134ef781af9ed100fab94c8da840e3a5282f2afcf847ca571b479a13a0c"), + felt::hex("0x4fe6a2f0e9567c4eb4d1621f24e1727887fc44364650643ea566fed85bca195"), + ]; + let exp_proof = vec![ + 129, 84, 199, 117, 207, 162, 234, 141, 211, 33, 34, 12, 15, 105, 240, 212, 222, 123, + 209, 24, 30, 184, 113, 96, 122, 89, 199, 129, 213, 163, 4, 246, 103, 170, 250, 158, + 171, 208, 8, 186, 43, 105, 40, 79, 139, 247, 144, 22, 36, 195, 197, 230, 246, 135, 202, + 206, 71, 59, 9, 240, 27, 119, 126, 238, 0, 94, 248, 137, 237, 48, 112, 12, 36, 184, + 112, 87, 34, 19, 100, 20, 49, 109, 146, 227, 201, 57, 129, 131, 13, 65, 100, 205, 3, + 158, 178, 185, 3, 187, 149, 240, 94, 131, 219, 236, 250, 90, 18, 70, 100, 235, 146, + 151, 181, 194, 232, 148, 19, 161, 154, 27, 42, 86, 226, 20, 79, 117, 211, 65, 0, 0, 0, + 0, 0, 0, 74, 156, 7, 232, 221, 116, 75, 79, 52, 234, 180, 7, 248, 250, 51, 110, 88, 51, + 195, 44, 181, 145, 104, 216, 133, 85, 172, 193, 168, 230, 34, 104, 134, 9, 2, 226, 158, + 123, 49, 252, 13, 74, 165, 174, 164, 222, 242, 231, 218, 64, 228, 154, 18, 3, 13, 227, + 1, 122, 234, 77, 228, 41, 25, 47, 170, 7, 7, 133, 140, 250, 6, 49, 23, 28, 155, 39, + 157, 234, 63, 87, 246, 43, 18, 225, 74, 143, 220, 118, 250, 169, 154, 24, 185, 228, + 133, 235, 249, 85, 4, 22, 248, 202, 248, 63, 231, 219, 94, 116, 21, 177, 239, 70, 150, + 244, 235, 75, 20, 111, 32, 10, 35, 220, 139, 173, 189, 185, 137, 103, 75, 214, 7, 9, 6, + 156, 199, 244, 221, 70, 114, 17, 31, 223, 100, 40, 90, 67, 46, 87, 185, 144, 38, 240, + 119, 21, 114, 64, 59, 163, 117, 255, 202, 113, 5, 209, 227, 26, 141, 45, 32, 191, 4, + 64, 73, 228, 67, 123, 209, 39, 190, 77, 120, 94, 189, 85, 193, 249, 131, 53, 224, 50, + 214, 205, 0, 66, 3, 135, 60, 246, 225, 180, 35, 205, 72, 50, 20, 152, 45, 146, 143, + 117, 75, 212, 163, 123, 111, 198, 251, 141, 233, 131, 205, 52, 148, 46, 99, 67, 6, 41, + 229, 96, 86, 105, 79, 136, 232, 180, 224, 206, 131, 141, 234, 81, 38, 88, 6, 158, 196, + 157, 102, 40, 174, 213, 74, 8, 151, 157, 156, 48, 7, 86, 90, 57, 208, 230, 55, 32, 176, + 85, 161, 98, 136, 145, 60, 193, 225, 121, 223, 34, 87, 159, 219, 116, 52, 225, 148, 95, + 154, 223, 1, 192, 2, 132, 248, 30, 4, 214, 132, 163, 7, 96, 223, 143, 85, 116, 55, 208, + 221, 95, 32, 187, 143, 40, 60, 0, 195, 180, 87, 207, 119, 157, 180, 191, 3, 110, 206, + 4, 53, 39, 242, 78, 178, 191, 156, 7, 82, 45, 240, 202, 128, 61, 88, 74, 127, 216, 34, + 163, 31, 34, 51, 198, 28, 227, 126, 29, 3, 160, 85, 143, 232, 3, 128, 7, 244, 80, 26, + 41, 78, 13, 161, 151, 14, 126, 23, 219, 205, 14, 174, 113, 159, 95, 22, 93, 12, 166, + 13, 24, 130, 247, 254, 203, 188, 100, 172, 50, 228, 160, 116, 29, 223, 164, 165, 72, + 53, 148, 54, 224, 34, 212, 249, 138, 63, 36, 42, 4, 246, 38, 32, 221, 73, 35, 188, 47, + 42, 197, 44, 22, 207, 110, 144, 100, 5, 126, 21, 243, 105, 125, 248, 250, 171, 42, 144, + 218, 68, 21, 144, 57, 168, 200, 2, 237, 82, 252, 85, 69, 87, 36, 96, 75, 79, 171, 90, + 40, 207, 19, 140, 27, 14, 180, 147, 210, 126, 125, 227, 160, 51, 212, 43, 150, 254, + 156, 61, 235, 3, 2, 184, 204, 42, 33, 90, 14, 127, 37, 126, 89, 143, 118, 51, 123, 113, + 80, 37, 232, 204, 160, 200, 236, 87, 207, 114, 26, 128, 144, 134, 123, 7, 95, 111, 24, + 141, 1, 239, 126, 176, 214, 229, 200, 178, 55, 206, 176, 70, 196, 113, 129, 124, 228, + 46, 252, 235, 9, 157, 164, 222, 212, 201, 47, 7, 238, 94, 209, 172, 34, 76, 163, 8, 26, + 233, 142, 146, 12, 63, 207, 231, 169, 213, 77, 123, 156, 244, 31, 249, 93, 218, 235, + 18, 213, 26, 43, 5, 166, 213, 208, 30, 58, 45, 118, 139, 83, 211, 151, 100, 137, 13, + 205, 86, 177, 216, 239, 51, 137, 53, 232, 209, 42, 185, 156, 170, 53, 4, 226, + ]; + let seed: u64 = 0x17f7a49e20d141c8; + let proof = test_fri_correctness_with( + log2_eval_domain, + fri_step_list, + last_layer_degree_bound, + n_queries, + proof_of_work_bits, + seed, + Felt252::ONE, + coeffs, + witness, + ); + assert_eq!(exp_proof, proof); + + let log2_eval_domain = 4; + let fri_step_list = vec![0, 1, 2]; + let last_layer_degree_bound = 1; + let n_queries = 4; + let proof_of_work_bits = 15; + let witness = vec![ + felt::hex("0x64433913d23b0a0f2b5498872adef947abc543017a208337bbb65786a3b38de"), + felt::hex("0x4394addfefccd998a2dfc22bc2f5650c43a6971824a5b6b3b36e2f041e83d11"), + felt::hex("0x68c6fec68cb182cf62ba29fa531a96c961c7140e22a2cca615648bfb238d856"), + felt::hex("0x32c1e34b197f5b31787d326d74302537dbed6a3dceb02ce797476cfb2e0cbb4"), + felt::hex("0x5947036ad70c74c9c4c74f3127ecbbc4b25ebc2d988aa0f934710366f9e4b95"), + felt::hex("0x1182145365c2fcc3ef93558b5be9e2643fe2854fecbd182f3f146b7ac35b25e"), + felt::hex("0x32177b9cf753c5007d13d62c015519b2daf2b8865e272ffb36a55ad9846cb68"), + felt::hex("0x4f0ecf2e2a9afdaf6f18f2b4649fa3fdf96738f7d66bd255cf5fbd49442c54"), + felt::hex("0x3c8402d947eaa8cd9da9d9e8116c6c2d992cdee9f10adc893d4dd236bf5428e"), + felt::hex("0x7ee9ee6e1726db186bf1e2156bde6dee8ab0884fb62459284ce73320cc811af"), + felt::hex("0x755f6dac00997790320b4abddac61212126da4c6501d8e480c198da0d76ebfc"), + felt::hex("0x758f8c7e91f3396886a2032432dbf78501e96c4c9713a0f6a2a724ffb6abf67"), + felt::hex("0x1043858078ae89e34abecccd70fc3b8b60e97b4fcfe8b2f144de113d04e88f3"), + felt::hex("0x11e5f9d2048fe49514d7cd0e26df0441253dfb30202bdffe28ce4618c01741"), + felt::hex("0x5a90be5522cc6b0be211b35e96e800a1d0102e81493d5b8753a3d3f93e87037"), + felt::hex("0x52e2ba6ed1a3810a9164ba520b55bc4c5e68c4284765a8596eecc381005ff9e"), + ]; + let coeffs = vec![ + felt::hex("0x3ca6492a6fe0b5023a397825d012998e1b3d58bf1e1ddb38445e28a21d381f5"), + felt::hex("0xc94631e50dfef0dde10db68d464f75595fad1ed082b9f6c09b7289d34852c5"), + felt::hex("0x21541e075182cd345e2b6eaaa5106a012c097e55d076ed2ef95659e5f2034a2"), + felt::hex("0x5c7b8a672c899d7a9d409198d7a63c395152a7257cb98bacea6cbac9173acac"), + felt::hex("0x7431e916ea2d7c33f02175a0dd352d07300abd5a45e871a60295f73e27bc48a"), + felt::hex("0x3540d89e585d708c0fc1eb0c6340be4b12aa19b3d9b8fe568ca5f179eec7896"), + felt::hex("0x41bfa3313572f5015e93d0e82491fe938064589d9ae5e2e87747c97f2a23fd8"), + felt::hex("0x32067f761b701cbeb927131fa4a8d843ba17c32e4c1f3cd2835a3f6108105e1"), + ]; + let exp_proof = vec![ + 212, 217, 152, 50, 15, 134, 146, 73, 137, 109, 133, 120, 138, 125, 66, 58, 164, 121, + 125, 69, 112, 114, 76, 242, 135, 239, 73, 12, 160, 57, 93, 122, 90, 12, 66, 76, 107, + 19, 167, 207, 211, 236, 179, 52, 233, 1, 48, 78, 9, 56, 157, 81, 77, 211, 219, 83, 173, + 183, 129, 212, 111, 208, 70, 65, 2, 46, 216, 28, 4, 6, 12, 193, 194, 122, 210, 143, + 106, 106, 229, 89, 180, 108, 232, 150, 164, 74, 170, 179, 40, 29, 139, 138, 184, 66, 8, + 59, 0, 0, 0, 0, 0, 0, 58, 197, 6, 144, 194, 16, 199, 69, 3, 86, 199, 11, 154, 81, 116, + 225, 125, 105, 79, 125, 62, 108, 3, 117, 38, 103, 231, 76, 128, 130, 74, 244, 236, 194, + 7, 213, 247, 39, 231, 28, 29, 46, 245, 184, 103, 161, 130, 114, 110, 250, 165, 202, 10, + 246, 234, 190, 114, 77, 56, 13, 14, 223, 172, 164, 202, 57, 54, 3, 129, 200, 134, 18, + 168, 123, 150, 28, 140, 143, 54, 235, 219, 3, 164, 39, 113, 88, 153, 140, 173, 60, 178, + 109, 102, 93, 175, 127, 205, 140, 52, 129, 105, 47, 156, 4, 249, 80, 164, 101, 0, 24, + 87, 60, 186, 161, 196, 151, 166, 241, 245, 205, 172, 195, 21, 124, 193, 145, 182, 54, + 70, 133, 122, 160, 189, 69, 173, 245, 25, 79, 65, 219, 36, 147, 98, 143, 51, 155, 4, + 146, 220, 14, 61, 140, 42, 176, 118, 219, 182, 133, 185, 211, 128, 127, 47, 137, 226, + 139, 238, 160, 169, 252, 186, 241, 50, 111, 208, 255, 205, 19, 116, 114, 254, 111, 200, + 139, 197, 69, 23, 132, 174, 176, 62, 161, 27, 107, 7, 26, 205, 172, 71, 167, 11, 144, + 139, 58, 39, 192, 7, 255, 74, 83, 167, 172, 253, 185, 154, 103, 243, 104, 227, 6, 52, + 161, 234, 47, 247, 147, 3, 140, 246, 134, 27, 207, 240, 245, 32, 32, 1, 202, 228, 212, + 23, 90, 103, 66, 55, 17, 205, 45, 121, 38, 114, 200, 183, 32, 188, 208, 28, 225, 7, + 118, 180, 203, 229, 52, 76, 138, 18, 221, 120, 62, 83, 162, 239, 140, 152, 206, 42, + 233, 63, 116, 236, 234, 49, 168, 58, 53, 249, 134, 61, 124, 5, 34, 147, 49, 78, 166, + 250, 215, 46, 82, 9, 192, 16, 233, 227, 73, 77, 147, 180, 115, 7, 168, 97, 16, 14, 220, + 10, 17, 167, 80, 223, 222, 7, 172, 249, 200, 78, 10, 219, 39, 11, 40, 183, 18, 66, 130, + 125, 37, 87, 246, 114, 19, 130, 121, 114, 129, 166, 89, 170, 62, 131, 36, 106, 107, + ]; + let seed: u64 = 0x17f79d3b0c455630; + let proof = test_fri_correctness_with( + log2_eval_domain, + fri_step_list, + last_layer_degree_bound, + n_queries, + proof_of_work_bits, + seed, + Felt252::ONE, + coeffs, + witness, + ); + assert_eq!(exp_proof, proof); + + let log2_eval_domain = 4; + let fri_step_list = vec![0, 2, 1]; + let last_layer_degree_bound = 1; + let n_queries = 4; + let proof_of_work_bits = 15; + let witness = vec![ + felt::hex("0x664ab667f47556e85164804eb1dd4d059cec3151566a5d461a1b89ffa4742e7"), + felt::hex("0x7ad1ec137b3a592da7715ee8fa8c90b66eede4feca5b3cdbe59d8393003c992"), + felt::hex("0xaa069c3dbe22826fb1006a2196814ad6c5169ca0ae3db9d8f5eb8d11dd5454"), + felt::hex("0x3e3daaf4a87f822971674346fcf501f3c70346786ac8a253616143fedcc9df5"), + felt::hex("0x5aa1ab7d90041bb147fb51d88e9e2da8dc006ac7aef53c801a4026b54618365"), + felt::hex("0xd2027379aea66b9f81e77d2b375d1a8a2843f2a1b3af93d42f30e24e2eb277"), + felt::hex("0x7edf5d6b0904ec6c5b1f60ecfa4466fc96c6db9d2f57c98095be91755438853"), + felt::hex("0x21f88ff8f2be530e8ab7b91e8b30f022a0aaff94e3b7a93d30f11b2ac2f5f6f"), + felt::hex("0x666d0d91f6916e0137abc7245055af76df8081e285a3f920c3c66cd87220fff"), + felt::hex("0x10d49f89ee4b673aa12b9db8c9faba651dbfbfeb7599563522e9ae080497871"), + felt::hex("0x2023c87730a44498f4a245499374fd6582795bad4ef8a1e3696d62c7f9218b5"), + felt::hex("0x6d0c3fca9e6518de103f91195d18e509d3480c020a6f67346d11b841b658c1"), + felt::hex("0x77d2af555d45a1157aaa48c2fb98b3755b8e69e92e2ee393d6a87f1ccf3715e"), + felt::hex("0x1c113ad1e86bb533673bde18ded4a6812a4eab559d291bf5285a1c2c3e74111"), + felt::hex("0x7a6279b4aea2b5c7589d80f6c033583c512bb90ba355fda74a92b97d4d55eb9"), + felt::hex("0x617d9e16707a3c9a23cc1ccac18a309012e5f309a26dbb133d7fde9f941151"), + ]; + let coeffs = vec![ + felt::hex("0x46528ee9a35863899167c19af14a0959bea4a976ce763811c28b7d7b9bf038c"), + felt::hex("0x270aa48221a3d99fd50eaf9d8ad21076475c3a60f70a65c33006b55726ef342"), + felt::hex("0x270b0a282e18cb4dbe1c06a4fb169bfe2fddb9e79a400ebe4bdad82d93c376d"), + felt::hex("0x30705c9a1a2e53e69a83ce3c9312129816fb354b776afbeaa448d47328c88f4"), + felt::hex("0x442c1ee359abf39807eb88ad3f67b3bd9127082dd7264df2f992c51d0be3c25"), + felt::hex("0x1be97dee7353777dda2756d95b956ecc62039ab7b5f756e9ee8c964a5ee78df"), + felt::hex("0x7f0499488cbab733a4fb9eaeaa6c95c886439f9bd086384df7e36c0316c0f20"), + felt::hex("0x4257e61f8d77db710b3fbbff622ecc4cd6a41bc5219ad79d5762e321a37c797"), + ]; + let exp_proof = vec![ + 93, 179, 153, 108, 253, 65, 129, 59, 155, 222, 13, 33, 231, 64, 45, 41, 62, 59, 158, + 38, 111, 179, 71, 38, 61, 17, 31, 10, 49, 109, 17, 160, 180, 177, 128, 77, 181, 106, + 40, 38, 199, 129, 10, 14, 54, 183, 162, 7, 52, 25, 155, 5, 110, 135, 9, 236, 84, 53, + 52, 57, 234, 105, 141, 170, 5, 88, 0, 208, 22, 127, 211, 116, 28, 211, 104, 243, 186, + 240, 50, 135, 25, 235, 64, 35, 16, 50, 59, 165, 253, 240, 243, 209, 118, 242, 200, 150, + 0, 0, 0, 0, 0, 0, 164, 39, 3, 134, 169, 230, 65, 128, 157, 95, 173, 72, 148, 249, 194, + 221, 139, 98, 231, 231, 163, 68, 84, 129, 84, 27, 104, 138, 7, 166, 108, 180, 19, 161, + 6, 184, 227, 30, 76, 176, 145, 177, 159, 34, 49, 242, 244, 54, 35, 156, 31, 85, 6, 41, + 175, 9, 219, 61, 54, 210, 154, 1, 126, 221, 177, 99, 4, 27, 22, 74, 129, 244, 124, 90, + 216, 105, 188, 172, 253, 72, 124, 130, 218, 70, 146, 17, 143, 129, 119, 117, 164, 35, + 126, 101, 71, 11, 215, 39, 2, 247, 38, 85, 205, 143, 129, 13, 127, 14, 69, 12, 96, 95, + 132, 184, 212, 31, 142, 120, 214, 86, 100, 60, 17, 116, 28, 77, 223, 249, 246, 27, 97, + 233, 114, 36, 95, 250, 10, 203, 87, 62, 121, 141, 21, 239, 166, 1, 47, 112, 48, 93, + 224, 187, 26, 246, 127, 60, 126, 101, 240, 92, 36, 67, 19, 94, 70, 229, 189, 134, 198, + 14, 34, 94, 215, 96, 58, 82, 79, 112, 147, 59, 66, 197, 56, 8, 87, 103, 23, 89, 248, + 173, 142, 20, 176, 28, + ]; + let seed: u64 = 0x17f7965703127351; + let proof = test_fri_correctness_with( + log2_eval_domain, + fri_step_list, + last_layer_degree_bound, + n_queries, + proof_of_work_bits, + seed, + Felt252::ONE, + coeffs, + witness, + ); + assert_eq!(exp_proof, proof); + + let log2_eval_domain = 4; + let fri_step_list = vec![1, 1, 1]; + let last_layer_degree_bound = 1; + let n_queries = 4; + let proof_of_work_bits = 15; + let witness = vec![ + felt::hex("0x1cf9851157cb769852653697c843d11cd6ba0b0bbab690c508816d1492f49ca"), + felt::hex("0x464435f3e7fc324d2a74cd705307f0f77132ef75509031eef10fe55e42d3643"), + felt::hex("0x48e5dc2bcae2e2cf7a3195226a9adcb359589299f29b3e61717dc69b5d32f4"), + felt::hex("0xcd0d6f405850d6cc8ba005fdf4ea38638e0d609e2fde87847d838ff9edec25"), + felt::hex("0x4057dbc15290a9717c4a36d776d156db816fcee9f4b813d36f684008df22230"), + felt::hex("0x25fc6ca01bfdceb27866cb946426c94c1bc636acabc6f1a7944ff7b4f7bcc61"), + felt::hex("0x6842b1f4a74998de41e61229e24a6fe94d372e06874ef5415e93c1f6185a72e"), + felt::hex("0x4d884c2f0ff179ea4a63d363ac975e62edfd88b20af6e6466da545f7b8039a0"), + felt::hex("0x61bd351a59523778b50f0cb66eea0ea75b4bf347f11cd312de03cf26e9b9aef"), + felt::hex("0x472264c1fd1d2b9d9c0462f88af7bf1d2d701864fb018af90f0220bc15dd623"), + felt::hex("0x1bce23e5cc1c0858646957a00db7c4e347a314d15116fff03a3397b0bbf31e8"), + felt::hex("0x7356aac8ce189c47d6251b4086467f11275ff67746e5ecd7de1276b48d7c491"), + felt::hex("0x19d1adc825b37fab2f0fb1fb7a35b42ae072352fa30b392cb3d8a9bbcd79757"), + felt::hex("0x6262ddf4f66fd4c2ae7338f656368653b759bcf33d1f7cc830d95488df3f481"), + felt::hex("0x1fb9f3e9aea6bc46ff80439809a0e1fed50aad65b2bdb3e8dc5537635bc1a74"), + felt::hex("0x3cc94e0f6c565810558cf49a2330d3a32a385f85a92f8b63621f739780360af"), + ]; + let coeffs = vec![ + felt::hex("0x621786c824f88e5377c640b67163c03b31d9c2c078066802a50e54f0fa36dd1"), + felt::hex("0x7c50eecb0a7b9bd9a09f8bb5b9558e8588ff5ee3429b47f507459dced726d0b"), + felt::hex("0x46c142e5a4eb6deba5ae4a303203d7b83f5b215da78446db9e3154f1f08ea4a"), + felt::hex("0x26802e8e122147f007eadefb8f1b586911b50b367db1c8ce59ae4384e9ccd55"), + felt::hex("0x7b0fb526db862c64578786b816ed449e3bbf13acab552fc1f112050610679fa"), + felt::hex("0x594925314f874f3b8a9d13992829161c237589d22947723f3669f11d164e154"), + felt::hex("0x4db65eadfa79ae774970f0655351047877028575bac382b9c876fa506fb6df4"), + felt::hex("0x2f4065044bc371c860d0b6494a03f307f49999df4b7eac68745af16a50cee12"), + ]; + let exp_proof = vec![ + 231, 46, 8, 116, 44, 9, 9, 158, 17, 79, 167, 6, 239, 134, 171, 237, 147, 101, 26, 253, + 196, 138, 4, 135, 37, 84, 149, 123, 170, 224, 31, 22, 252, 243, 193, 98, 24, 32, 104, + 233, 29, 156, 42, 182, 188, 33, 48, 225, 101, 148, 161, 79, 2, 175, 157, 139, 246, 144, + 107, 143, 5, 78, 158, 98, 7, 14, 182, 56, 154, 10, 69, 230, 36, 34, 36, 182, 180, 207, + 21, 45, 253, 70, 139, 68, 38, 7, 81, 246, 194, 56, 189, 128, 103, 237, 162, 155, 0, 0, + 0, 0, 0, 0, 8, 177, 4, 43, 247, 232, 92, 11, 222, 181, 130, 103, 254, 39, 130, 235, + 196, 254, 50, 1, 88, 182, 211, 153, 52, 50, 107, 117, 189, 218, 141, 105, 133, 9, 6, + 90, 139, 51, 137, 97, 95, 27, 114, 211, 233, 53, 89, 166, 240, 33, 195, 153, 57, 199, + 224, 250, 112, 82, 106, 178, 156, 15, 105, 227, 147, 217, 4, 102, 180, 212, 210, 150, + 128, 48, 79, 34, 37, 201, 8, 106, 151, 253, 195, 143, 49, 235, 122, 119, 253, 23, 69, + 197, 70, 23, 254, 133, 181, 58, 153, 0, 72, 198, 218, 20, 252, 107, 190, 201, 141, 8, + 113, 230, 95, 76, 31, 209, 156, 15, 200, 56, 86, 54, 76, 3, 113, 80, 201, 251, 194, 6, + 1, 185, 136, 240, 47, 199, 90, 17, 139, 158, 202, 133, 134, 67, 181, 76, 216, 111, 89, + 119, 16, 212, 213, 43, 220, 20, 142, 32, 17, 78, 82, 123, + ]; + let seed: u64 = 0x17f795da1b1032fd; + let proof = test_fri_correctness_with( + log2_eval_domain, + fri_step_list, + last_layer_degree_bound, + n_queries, + proof_of_work_bits, + seed, + Felt252::ONE, + coeffs, + witness, + ); + assert_eq!(exp_proof, proof); + + let log2_eval_domain = 3; + let fri_step_list = vec![0, 2]; + let last_layer_degree_bound = 1; + let n_queries = 4; + let proof_of_work_bits = 15; + let witness = vec![ + felt::hex("0x674252648a8cfb6eb35f61fc736f196c97aabda520898fd556d77481275e802"), + felt::hex("0x33e82edac094f04768082c5a3bc3a5ea55b1c3b905c7ea950cf1da534f731a"), + felt::hex("0x140b8ddeac2bfff4614885a78dbff1a17c0bb5a819697a64158e14b1b9478ed"), + felt::hex("0x3fe54f995fa4a4b5fadd2a101fd6692665ea0d436ba92d0cb893d6b54e9808"), + felt::hex("0x3723528cbbdd735a13bde8256fe165b9ee415f2cac28deb9e5d3ddbd3f7e37a"), + felt::hex("0x7748cae882c5de585641080c91f40a002d736b279a4372db74b788579e90abe"), + felt::hex("0x58dce1b40fbe083bb0f2a5512eb983ffa5df16d4543f867ee9e86a8dce02931"), + felt::hex("0x7b41b9012a5b3ce4cfe4a7877659b8455ddc4f34665e439f444a13a0be754aa"), + ]; + let coeffs = vec![ + felt::hex("0xa2ae0a9e2f24e8bab58f42a9ba2affc7dc0c17404286ece22f7910daa1b04"), + felt::hex("0xef42a99a4e9f9222b64c7a967a2b5b2f0b110624c925461f401c989e5a339e"), + felt::hex("0x349dbc9e7d1c0050da3a631e61db7ee5d6a6e0d91830805271a3d002538928a"), + felt::hex("0x230dbd21ca57dd12f30aa7f20036b9d40876c0527b8434340f0261e413906d6"), + ]; + let exp_proof = vec![ + 145, 68, 242, 198, 199, 93, 113, 48, 74, 11, 21, 205, 232, 13, 231, 65, 147, 34, 230, + 191, 24, 37, 89, 13, 80, 143, 64, 186, 143, 155, 36, 88, 3, 60, 202, 166, 23, 135, 20, + 166, 21, 208, 170, 79, 17, 190, 196, 235, 81, 154, 111, 101, 143, 142, 223, 43, 11, + 126, 17, 71, 214, 199, 200, 191, 0, 0, 0, 0, 0, 1, 20, 249, 5, 179, 217, 181, 150, 235, + 4, 190, 110, 137, 231, 12, 159, 127, 54, 82, 34, 221, 153, 220, 222, 217, 156, 173, + 189, 252, 225, 66, 255, 3, 241, 50, 2, 233, 39, 218, 209, 81, 108, 112, 57, 141, 127, + 123, 99, 192, 207, 32, 230, 147, 216, 35, 152, 210, 180, 116, 110, 194, 57, 132, 150, + 109, 135, 150, 1, 246, 53, 190, 196, 160, 202, 245, 46, 163, 5, 211, 141, 101, 129, + 105, 9, 16, 224, 26, 47, 251, 67, 88, 240, 124, 12, 223, 139, 20, 115, 207, 3, 211, + 127, 144, 188, 170, 28, 182, 72, 220, 76, 18, 165, 4, 174, 36, 208, 247, 130, 18, 33, + 135, 12, 13, 8, 156, 136, 201, 131, 229, 12, 172, 1, 70, 185, 113, 185, 45, 32, 26, 55, + 136, 245, 229, 23, 11, 2, 191, 65, 60, 218, 198, 59, 221, 162, 86, 214, 26, 243, 127, + 76, 28, 114, 88, + ]; + let seed: u64 = 0x17f7332f022bccbe; + let proof = test_fri_correctness_with( + log2_eval_domain, + fri_step_list, + last_layer_degree_bound, + n_queries, + proof_of_work_bits, + seed, + Felt252::ONE, + coeffs, + witness, + ); + assert_eq!(exp_proof, proof); + } +} diff --git a/fri/src/test.rs b/fri/src/test.rs index e9e4e1a..cff0ef4 100644 --- a/fri/src/test.rs +++ b/fri/src/test.rs @@ -13,7 +13,6 @@ mod fri_tests { }; use commitment_scheme::{CommitmentHashes, SupportedHashes}; use felt::{hex, Felt252}; - use num_bigint::BigUint; use paste::paste; use randomness::{keccak256::PrngKeccak256, Prng}; use sha3::{Digest, Sha3_256}; @@ -152,7 +151,7 @@ mod fri_tests { prover_channel.draw_number(1024); } - let mut first_layer_evals = vec![ + let first_layer_evals = vec![ hex("0x3b169859b500d9f2b4fe19e662701da2e8ae2f69ccb4f9823ae31b9db698838"), hex("0x328c64b926d309a915f58d93b14f6f4a14b9349e52bbff4095c892dfbb49834"), hex("0x5cfd45df2ef0d8d5a2e1031131c84a49af6282ccbdc4d5d1f615f7c1d5221cd"), @@ -167,11 +166,6 @@ mod fri_tests { hex("0x617cc7be7cd5a3b14b76cdb12801fa7784f414112a5ffc74f826ca327a19a8e"), ]; - // convert coeffs_vec to montgomery form - first_layer_evals = first_layer_evals - .iter() - .map(|coeff| coeff * &self.mont_r) - .collect(); let _ = prover_channel.send_felts(&first_layer_evals); let first_layer_decommitments = vec![ @@ -249,18 +243,13 @@ mod fri_tests { let _ = prover_channel.send_decommit_node(node); } - let mut second_layer_evals = vec![ + let second_layer_evals = vec![ hex("0x1ed573c763647053fdb084c8ab9bd0773c78b006d9efca09f99063e0f2676da"), hex("0x450df06879222711f99947cc9519193eb5913ff0bdcb2b30aef4bed4a8faf74"), hex("0x7d2af22f1b20026d6a3802e3ec6db2cea2e95754231e252bcbaf7a09c8767d1"), hex("0x327be53f5e29e44c667d791b0d5ae932045aa39e0234e943cdde8113d3a2ea0"), ]; - // convert second_layer_evals to montgomery form - second_layer_evals = second_layer_evals - .iter() - .map(|coeff| coeff * &self.mont_r) - .collect(); let _ = prover_channel.send_felts(&second_layer_evals); let second_layer_decommitment_node = vec![ @@ -322,7 +311,7 @@ mod fri_tests { let _ = prover_channel.send_decommit_node(node); } - let mut third_layer_evals = vec![ + let third_layer_evals = vec![ hex("0x7337d35628e7bb159b48fa8ce05544f9d11bed81bd7b48969536138aaa576c1"), hex("0x16aa6c6d0d718bc2c6e67fdcd76433b67f5ad9a2f986f64d461d8443edead06"), hex("0x2428af41a81a61c18ab64cb1a9efee81d527fe0b1f774937aecb67e50ae6c39"), @@ -353,11 +342,6 @@ mod fri_tests { hex("0x1fc9374c591d4d9fec3e37b706392ebb77ee4efb05a868f7eb47ae7358e6595"), ]; - // convert third_layer_evals to montgomery form - third_layer_evals = third_layer_evals - .iter() - .map(|coeff| coeff * &self.mont_r) - .collect(); let _ = prover_channel.send_felts(&third_layer_evals); let third_layer_decommitment_node = vec![ diff --git a/poseidon/Cargo.toml b/poseidon/Cargo.toml index f90089c..7d807e5 100644 --- a/poseidon/Cargo.toml +++ b/poseidon/Cargo.toml @@ -2,6 +2,7 @@ name = "poseidon" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] ark-ff.workspace = true diff --git a/randomness/Cargo.toml b/randomness/Cargo.toml index 3289244..0f0ebf3 100644 --- a/randomness/Cargo.toml +++ b/randomness/Cargo.toml @@ -2,6 +2,7 @@ name = "randomness" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] ark-ff.workspace = true