diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 500033f728..bacc95b914 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -52,7 +52,6 @@ jobs: env: RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native RUST_BACKTRACE: 1 - # FRI_QUERIES: 1 SP1_DEV: 1 test-arm: @@ -89,7 +88,6 @@ jobs: env: RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native RUST_BACKTRACE: 1 - # FRI_QUERIES: 1 SP1_DEV: 1 lint: diff --git a/Cargo.lock b/Cargo.lock index 61fc6701dc..0cdbe70840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4194,9 +4194,8 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3-air" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "066f571b2e645505ed5972dd0e1e252ba03352150830c9566769ca711c0f1e9b" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "p3-field", "p3-matrix", @@ -4204,9 +4203,8 @@ dependencies = [ [[package]] name = "p3-baby-bear" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff00f571044d299310d9659c6e51c98422de3bf94b8577f7f30cf59cf2043e40" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "num-bigint 0.4.6", "p3-field", @@ -4219,9 +4217,8 @@ dependencies = [ [[package]] name = "p3-blake3" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc4cb69ae54a279bbbd477566d1bdb71aa879b528fd658d0fcfc36f54b00217c" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "blake3", "p3-symmetric", @@ -4229,9 +4226,8 @@ dependencies = [ [[package]] name = "p3-bn254-fr" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf19917f986d45e9abb6d177e875824ced6eed096480d574fce16f2c45c721ea" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "ff 0.13.0", "num-bigint 0.4.6", @@ -4244,9 +4240,8 @@ dependencies = [ [[package]] name = "p3-challenger" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be7e4fbce4566a93091107eadfafa0b5374bd1ffd3e0f6b850da3ff72eb183f" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "p3-field", "p3-maybe-rayon", @@ -4258,13 +4253,11 @@ dependencies = [ [[package]] name = "p3-commit" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a03eb0f99d68a712c41e658e9a7782a0705d4ffcfb6232a43bd3f1ef9591002" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-challenger", - "p3-dft", "p3-field", "p3-matrix", "p3-util", @@ -4273,9 +4266,8 @@ dependencies = [ [[package]] name = "p3-dft" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1556de968523fbe5d804ab50600ea306fcceea3500cfd7601e40882480524664" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "p3-field", "p3-matrix", @@ -4286,9 +4278,8 @@ dependencies = [ [[package]] name = "p3-field" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cec2af6e1ac47a2035af5165e668d64612c4b9ccabd06df37fc1fd381fdf8a71" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "num-bigint 0.4.6", @@ -4300,9 +4291,8 @@ dependencies = [ [[package]] name = "p3-fri" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f351ee9f9d4256455164565cd91e3e6d2487cc2a5355515fa2b6d479269188dd" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-challenger", @@ -4319,9 +4309,8 @@ dependencies = [ [[package]] name = "p3-interpolation" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24d0f2907a374ebe4545fcff3120d6376d9630cf0bef30feedcfc5908ea2c37" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "p3-field", "p3-matrix", @@ -4330,9 +4319,8 @@ dependencies = [ [[package]] name = "p3-keccak-air" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66badd47cedf6570e91a0cabc389b80dfd53ba1a6e9a45a3923fd54b86122ff" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "p3-air", "p3-field", @@ -4344,9 +4332,8 @@ dependencies = [ [[package]] name = "p3-matrix" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa272f3ae77ed8d73478aa7c89e712efb15bda3ff4aff10fadfe11a012cd5389" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-field", @@ -4359,18 +4346,16 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eecad6292021858f282d643d9d1284ab112a200494d589863a9c4080e578ef0" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "rayon", ] [[package]] name = "p3-mds" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716c4dbe68a02f1541eb09149d07b8663a3a5951b1864a31cd67ff3bb0826e57" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-dft", @@ -4383,9 +4368,8 @@ dependencies = [ [[package]] name = "p3-merkle-tree" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad7ebab52a03c26025988663a135aed62f5084a2e2ea262176dc8748efb593e5" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-commit", @@ -4400,9 +4384,8 @@ dependencies = [ [[package]] name = "p3-poseidon2" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c042efa15beab7a8c4d0ca9b9e4cbda7582be0c08e121e830fec45f082935b" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "gcd", "p3-field", @@ -4414,9 +4397,8 @@ dependencies = [ [[package]] name = "p3-symmetric" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9896a831f5b688adc13f6fbe1dcf66ecfaa4622a500f81aa745610e777acb72" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-field", @@ -4425,9 +4407,8 @@ dependencies = [ [[package]] name = "p3-uni-stark" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8437ebcd060c8a5479898030b114a93da8a86eb4c2e5f313d9eeaaf40c6e6f61" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "itertools 0.12.1", "p3-air", @@ -4444,9 +4425,8 @@ dependencies = [ [[package]] name = "p3-util" -version = "0.1.4-succinct" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dedb9d27ba47ac314c6fac4ca54e55c3e486c864d51ec5ba55dbe47b75121157" +version = "0.1.0" +source = "git+https://github.com/Plonky3/Plonky3?branch=sp1-v4#db3d45d4ec899efaf8f7234a8573f285fbdda5db" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 593b072f55..f993cba193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,46 +68,49 @@ sp1-lib = { path = "crates/zkvm/lib", version = "3.0.0", default-features = fals sp1-zkvm = { path = "crates/zkvm/entrypoint", version = "3.0.1", default-features = false } # p3 -p3-air = "0.1.4-succinct" -p3-field = "0.1.4-succinct" -p3-commit = "0.1.4-succinct" -p3-matrix = "0.1.4-succinct" -p3-baby-bear = { version = "0.1.4-succinct", features = ["nightly-features"] } -p3-util = "0.1.4-succinct" -p3-challenger = "0.1.4-succinct" -p3-dft = "0.1.4-succinct" -p3-fri = "0.1.4-succinct" -p3-keccak-air = "0.1.4-succinct" -p3-blake3 = "0.1.4-succinct" -p3-merkle-tree = "0.1.4-succinct" -p3-poseidon2 = "0.1.4-succinct" -p3-symmetric = "0.1.4-succinct" -p3-uni-stark = "0.1.4-succinct" -p3-maybe-rayon = "0.1.4-succinct" -p3-bn254-fr = "0.1.4-succinct" +# p3-air = "0.1.4-succinct" +# p3-field = "0.1.4-succinct" +# p3-commit = "0.1.4-succinct" +# p3-matrix = "0.1.4-succinct" +# p3-baby-bear = { version = "0.1.4-succinct", features = ["nightly-features"] } +# p3-util = "0.1.4-succinct" +# p3-challenger = "0.1.4-succinct" +# p3-dft = "0.1.4-succinct" +# p3-fri = "0.1.4-succinct" +# p3-goldilocks = "0.1.4-succinct" +# p3-keccak = "0.1.4-succinct" +# p3-keccak-air = "0.1.4-succinct" +# p3-blake3 = "0.1.4-succinct" +# p3-mds = "0.1.4-succinct" +# p3-merkle-tree = "0.1.4-succinct" +# p3-poseidon2 = "0.1.4-succinct" +# p3-symmetric = "0.1.4-succinct" +# p3-uni-stark = "0.1.4-succinct" +# p3-maybe-rayon = "0.1.4-succinct" +# p3-bn254-fr = "0.1.4-succinct" # For local development. -# p3-air = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-field = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-commit = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-matrix = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-util = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-challenger = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-dft = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-fri = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-keccak = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-blake3 = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-mds = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-symmetric = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } -# p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v3" } +p3-air = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-field = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-commit = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-matrix = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-util = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-challenger = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-dft = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-fri = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-keccak = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-blake3 = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-mds = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-symmetric = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } +p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3", branch = "sp1-v4" } # p3-air = { path = "../Plonky3/air" } # p3-field = { path = "../Plonky3/field" } diff --git a/crates/core/machine/src/alu/divrem/mod.rs b/crates/core/machine/src/alu/divrem/mod.rs index 4491cacd0a..1d4d539fc4 100644 --- a/crates/core/machine/src/alu/divrem/mod.rs +++ b/crates/core/machine/src/alu/divrem/mod.rs @@ -572,16 +572,20 @@ where // Add remainder. if i < WORD_SIZE { - c_times_quotient_plus_remainder[i] += local.remainder[i].into(); + c_times_quotient_plus_remainder[i] = + c_times_quotient_plus_remainder[i].clone() + local.remainder[i].into(); } else { // If rem is negative, add 0xff to the upper 4 bytes. - c_times_quotient_plus_remainder[i] += sign_extension.clone(); + c_times_quotient_plus_remainder[i] = + c_times_quotient_plus_remainder[i].clone() + sign_extension.clone(); } // Propagate carry. - c_times_quotient_plus_remainder[i] -= local.carry[i] * base; + c_times_quotient_plus_remainder[i] = + c_times_quotient_plus_remainder[i].clone() - local.carry[i] * base; if i > 0 { - c_times_quotient_plus_remainder[i] += local.carry[i - 1].into(); + c_times_quotient_plus_remainder[i] = + c_times_quotient_plus_remainder[i].clone() + local.carry[i - 1].into(); } } @@ -628,8 +632,8 @@ where let mut rem_byte_sum = zero.clone(); let mut b_byte_sum = zero.clone(); for i in 0..WORD_SIZE { - rem_byte_sum += local.remainder[i].into(); - b_byte_sum += local.b[i].into(); + rem_byte_sum = rem_byte_sum.clone() + local.remainder[i].into(); + b_byte_sum = b_byte_sum + local.b[i].into(); } // 1. If remainder < 0, then b < 0. diff --git a/crates/core/machine/src/alu/lt/mod.rs b/crates/core/machine/src/alu/lt/mod.rs index b8c5900447..876fdaaf8f 100644 --- a/crates/core/machine/src/alu/lt/mod.rs +++ b/crates/core/machine/src/alu/lt/mod.rs @@ -390,10 +390,10 @@ where { // Once the byte flag was set to one, we turn off the quality check flag. // We can do this by calculating the sum of the flags since only `1` is set to `1`. - is_inequality_visited += flag.into(); + is_inequality_visited = is_inequality_visited.clone() + flag.into(); - b_comparison_byte += b_byte.clone() * flag; - c_comparison_byte += c_byte.clone() * flag; + b_comparison_byte = b_comparison_byte.clone() + b_byte.clone() * flag; + c_comparison_byte = c_comparison_byte.clone() + c_byte.clone() * flag; // If inequality is not visited, assert that the bytes are equal. builder diff --git a/crates/core/machine/src/alu/mul/mod.rs b/crates/core/machine/src/alu/mul/mod.rs index 299e0931aa..6a1ce272fe 100644 --- a/crates/core/machine/src/alu/mul/mod.rs +++ b/crates/core/machine/src/alu/mul/mod.rs @@ -361,7 +361,7 @@ where for i in 0..PRODUCT_SIZE { for j in 0..PRODUCT_SIZE { if i + j < PRODUCT_SIZE { - m[i + j] += b[i].clone() * c[j].clone(); + m[i + j] = m[i + j].clone() + b[i].clone() * c[j].clone(); } } } diff --git a/crates/core/machine/src/alu/sll/mod.rs b/crates/core/machine/src/alu/sll/mod.rs index 1b2f6cbd3d..af00dd47a5 100644 --- a/crates/core/machine/src/alu/sll/mod.rs +++ b/crates/core/machine/src/alu/sll/mod.rs @@ -290,7 +290,7 @@ where let mut c_byte_sum = zero.clone(); for i in 0..BYTE_SIZE { let val: AB::Expr = AB::F::from_canonical_u32(1 << i).into(); - c_byte_sum += val * local.c_least_sig_byte[i]; + c_byte_sum = c_byte_sum.clone() + val * local.c_least_sig_byte[i]; } builder.assert_eq(c_byte_sum, local.c[0]); @@ -300,7 +300,8 @@ where // 3 is the maximum number of bits necessary to represent num_bits_to_shift as // num_bits_to_shift is in [0, 7]. for i in 0..3 { - num_bits_to_shift += local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); + num_bits_to_shift = num_bits_to_shift.clone() + + local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); } for i in 0..BYTE_SIZE { builder @@ -321,7 +322,7 @@ where let mut v = local.b[i] * local.bit_shift_multiplier - local.bit_shift_result_carry[i] * base.clone(); if i > 0 { - v += local.bit_shift_result_carry[i - 1].into(); + v = v.clone() + local.bit_shift_result_carry[i - 1].into(); } builder.assert_eq(local.bit_shift_result[i], v); } diff --git a/crates/core/machine/src/alu/sr/mod.rs b/crates/core/machine/src/alu/sr/mod.rs index 86dd4d2d32..b26c949945 100644 --- a/crates/core/machine/src/alu/sr/mod.rs +++ b/crates/core/machine/src/alu/sr/mod.rs @@ -352,7 +352,7 @@ where let mut c_byte_sum = AB::Expr::zero(); for i in 0..BYTE_SIZE { let val: AB::Expr = AB::F::from_canonical_u32(1 << i).into(); - c_byte_sum += val * local.c_least_sig_byte[i]; + c_byte_sum = c_byte_sum.clone() + val * local.c_least_sig_byte[i]; } builder.assert_eq(c_byte_sum, local.c[0]); @@ -362,7 +362,8 @@ where // of bits to shift. let mut num_bits_to_shift = AB::Expr::zero(); for i in 0..3 { - num_bits_to_shift += local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); + num_bits_to_shift = num_bits_to_shift.clone() + + local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); } for i in 0..BYTE_SIZE { builder @@ -423,15 +424,16 @@ where // The carry multiplier is 2^(8 - num_bits_to_shift). let mut carry_multiplier = AB::Expr::from_canonical_u8(0); for i in 0..BYTE_SIZE { - carry_multiplier += - AB::Expr::from_canonical_u32(1u32 << (8 - i)) * local.shift_by_n_bits[i]; + carry_multiplier = carry_multiplier.clone() + + AB::Expr::from_canonical_u32(1u32 << (8 - i)) * local.shift_by_n_bits[i]; } // The 3-bit number represented by the 3 least significant bits of c equals the number // of bits to shift. let mut num_bits_to_shift = AB::Expr::zero(); for i in 0..3 { - num_bits_to_shift += local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); + num_bits_to_shift = num_bits_to_shift.clone() + + local.c_least_sig_byte[i] * AB::F::from_canonical_u32(1 << i); } // Calculate ShrCarry. @@ -450,7 +452,7 @@ where for i in (0..LONG_WORD_SIZE).rev() { let mut v: AB::Expr = local.shr_carry_output_shifted_byte[i].into(); if i + 1 < LONG_WORD_SIZE { - v += local.shr_carry_output_carry[i + 1] * carry_multiplier.clone(); + v = v.clone() + local.shr_carry_output_carry[i + 1] * carry_multiplier.clone(); } builder.assert_eq(v, local.bit_shift_result[i]); } diff --git a/crates/core/machine/src/cpu/air/ecall.rs b/crates/core/machine/src/cpu/air/ecall.rs index 9c05105bcc..59785123fb 100644 --- a/crates/core/machine/src/cpu/air/ecall.rs +++ b/crates/core/machine/src/cpu/air/ecall.rs @@ -118,8 +118,8 @@ impl CpuChip { &self, builder: &mut AB, local: &CpuCols, - commit_digest: [Word; PV_DIGEST_NUM_WORDS], - deferred_proofs_digest: [AB::Expr; POSEIDON_NUM_WORDS], + commit_digest: [Word; PV_DIGEST_NUM_WORDS], + deferred_proofs_digest: [AB::PublicVar; POSEIDON_NUM_WORDS], ) { let (is_commit, is_commit_deferred_proofs) = self.get_is_commit_related_syscall(builder, local); @@ -132,7 +132,7 @@ impl CpuChip { // They should all be bools. for bit in ecall_columns.index_bitmap.iter() { builder.when(local.selectors.is_ecall).assert_bool(*bit); - bitmap_sum += (*bit).into(); + bitmap_sum = bitmap_sum.clone() + (*bit).into(); } // When the syscall is COMMIT or COMMIT_DEFERRED_PROOFS, there should be one set bit. builder @@ -199,7 +199,7 @@ impl CpuChip { builder: &mut AB, local: &CpuCols, next: &CpuCols, - public_values: &PublicValues, AB::Expr>, + public_values: &PublicValues, AB::PublicVar>, ) { let is_halt = self.get_is_halt_syscall(builder, local); @@ -219,7 +219,7 @@ impl CpuChip { builder .when(is_halt.clone()) - .assert_eq(local.op_b_access.value().reduce::(), public_values.exit_code.clone()); + .assert_eq(local.op_b_access.value().reduce::(), public_values.exit_code); } /// Returns a boolean expression indicating whether the instruction is a HALT instruction. diff --git a/crates/core/machine/src/cpu/air/memory.rs b/crates/core/machine/src/cpu/air/memory.rs index 7269334a6d..79054d1abf 100644 --- a/crates/core/machine/src/cpu/air/memory.rs +++ b/crates/core/machine/src/cpu/air/memory.rs @@ -327,8 +327,8 @@ impl CpuChip { let mut recomposed_byte = AB::Expr::zero(); for i in 0..8 { builder.when(is_mem.clone()).assert_bool(memory_columns.most_sig_byte_decomp[i]); - recomposed_byte += - memory_columns.most_sig_byte_decomp[i] * AB::Expr::from_canonical_u8(1 << i); + recomposed_byte = recomposed_byte.clone() + + memory_columns.most_sig_byte_decomp[i] * AB::Expr::from_canonical_u8(1 << i); } builder.when(local.selectors.is_lb).assert_eq(recomposed_byte.clone(), unsigned_mem_val[0]); builder.when(local.selectors.is_lh).assert_eq(recomposed_byte, unsigned_mem_val[1]); diff --git a/crates/core/machine/src/cpu/air/mod.rs b/crates/core/machine/src/cpu/air/mod.rs index 5ab408ce95..35b6dc18af 100644 --- a/crates/core/machine/src/cpu/air/mod.rs +++ b/crates/core/machine/src/cpu/air/mod.rs @@ -36,10 +36,6 @@ where let (local, next) = (main.row_slice(0), main.row_slice(1)); let local: &CpuCols = (*local).borrow(); let next: &CpuCols = (*next).borrow(); - let public_values_slice: [AB::Expr; SP1_PROOF_NUM_PV_ELTS] = - core::array::from_fn(|i| builder.public_values()[i].into()); - let public_values: &PublicValues, AB::Expr> = - public_values_slice.as_slice().borrow(); // Program constraints. builder.send_program( @@ -87,11 +83,15 @@ where self.eval_ecall(builder, local); // COMMIT/COMMIT_DEFERRED_PROOFS ecall instruction. + let public_values_slice: [AB::PublicVar; SP1_PROOF_NUM_PV_ELTS] = + core::array::from_fn(|i| builder.public_values()[i]); + let public_values: &PublicValues, AB::PublicVar> = + public_values_slice.as_slice().borrow(); self.eval_commit( builder, local, - public_values.committed_value_digest.clone(), - public_values.deferred_proofs_digest.clone(), + public_values.committed_value_digest, + public_values.deferred_proofs_digest, ); // HALT ecall and UNIMPL instruction. @@ -335,13 +335,13 @@ impl CpuChip { builder: &mut AB, local: &CpuCols, next: &CpuCols, - public_values: &PublicValues, AB::Expr>, + public_values: &PublicValues, AB::PublicVar>, ) { // Verify the public value's shard. - builder.when(local.is_real).assert_eq(public_values.execution_shard.clone(), local.shard); + builder.when(local.is_real).assert_eq(public_values.execution_shard, local.shard); // Verify the public value's start pc. - builder.when_first_row().assert_eq(public_values.start_pc.clone(), local.pc); + builder.when_first_row().assert_eq(public_values.start_pc, local.pc); // Verify the public value's next pc. We need to handle two cases: // 1. The last real row is a transition row. @@ -351,13 +351,10 @@ impl CpuChip { builder .when_transition() .when(local.is_real - next.is_real) - .assert_eq(public_values.next_pc.clone(), local.next_pc); + .assert_eq(public_values.next_pc, local.next_pc); // If the last real row is the last row, verify the public value's next pc. - builder - .when_last_row() - .when(local.is_real) - .assert_eq(public_values.next_pc.clone(), local.next_pc); + builder.when_last_row().when(local.is_real).assert_eq(public_values.next_pc, local.next_pc); } /// Constraints related to the is_real column. diff --git a/crates/core/machine/src/lib.rs b/crates/core/machine/src/lib.rs index 16fd571c95..168be94eac 100644 --- a/crates/core/machine/src/lib.rs +++ b/crates/core/machine/src/lib.rs @@ -8,6 +8,7 @@ clippy::unnecessary_unwrap, clippy::default_constructed_unit_structs, clippy::box_default, + clippy::assign_op_pattern, deprecated, incomplete_features )] diff --git a/crates/core/machine/src/memory/global.rs b/crates/core/machine/src/memory/global.rs index 2630759b48..db58e9c351 100644 --- a/crates/core/machine/src/memory/global.rs +++ b/crates/core/machine/src/memory/global.rs @@ -208,10 +208,10 @@ where let mut byte3 = AB::Expr::zero(); let mut byte4 = AB::Expr::zero(); for i in 0..8 { - byte1 += local.value[i].into() * AB::F::from_canonical_u8(1 << i); - byte2 += local.value[i + 8].into() * AB::F::from_canonical_u8(1 << i); - byte3 += local.value[i + 16].into() * AB::F::from_canonical_u8(1 << i); - byte4 += local.value[i + 24].into() * AB::F::from_canonical_u8(1 << i); + byte1 = byte1.clone() + local.value[i].into() * AB::F::from_canonical_u8(1 << i); + byte2 = byte2.clone() + local.value[i + 8].into() * AB::F::from_canonical_u8(1 << i); + byte3 = byte3.clone() + local.value[i + 16].into() * AB::F::from_canonical_u8(1 << i); + byte4 = byte4.clone() + local.value[i + 24].into() * AB::F::from_canonical_u8(1 << i); } let value = [byte1, byte2, byte3, byte4]; diff --git a/crates/core/machine/src/operations/add4.rs b/crates/core/machine/src/operations/add4.rs index fc010e9ab1..121acbf767 100644 --- a/crates/core/machine/src/operations/add4.rs +++ b/crates/core/machine/src/operations/add4.rs @@ -141,7 +141,7 @@ impl Add4Operation { for i in 0..WORD_SIZE { let mut overflow = a[i] + b[i] + c[i] + d[i] - cols.value[i]; if i > 0 { - overflow += cols.carry[i - 1].into(); + overflow = overflow.clone() + cols.carry[i - 1].into(); } builder_is_real.assert_eq(cols.carry[i] * base, overflow.clone()); } diff --git a/crates/core/machine/src/operations/add5.rs b/crates/core/machine/src/operations/add5.rs index dcd011f7f8..14d8dae259 100644 --- a/crates/core/machine/src/operations/add5.rs +++ b/crates/core/machine/src/operations/add5.rs @@ -147,12 +147,12 @@ impl Add5Operation { for i in 0..WORD_SIZE { let mut overflow: AB::Expr = AB::F::zero().into(); for word in words { - overflow += word[i].into(); + overflow = overflow.clone() + word[i].into(); } - overflow -= cols.value[i].into(); + overflow = overflow.clone() - cols.value[i].into(); if i > 0 { - overflow += cols.carry[i - 1].into(); + overflow = overflow.clone() + cols.carry[i - 1].into(); } builder_is_real.assert_eq(cols.carry[i] * base, overflow.clone()); } diff --git a/crates/core/machine/src/operations/baby_bear_range.rs b/crates/core/machine/src/operations/baby_bear_range.rs index 17674b6491..e6c8bdde5a 100644 --- a/crates/core/machine/src/operations/baby_bear_range.rs +++ b/crates/core/machine/src/operations/baby_bear_range.rs @@ -41,7 +41,8 @@ impl BabyBearBitDecomposition { let mut reconstructed_value = AB::Expr::zero(); for (i, bit) in cols.bits.iter().enumerate() { builder.when(is_real.clone()).assert_bool(*bit); - reconstructed_value += AB::Expr::from_wrapped_u32(1 << i) * *bit; + reconstructed_value = + reconstructed_value.clone() + AB::Expr::from_wrapped_u32(1 << i) * *bit; } // Assert that bits2num(bits) == value. diff --git a/crates/core/machine/src/operations/field/range.rs b/crates/core/machine/src/operations/field/range.rs index b7490c584b..73a108e775 100644 --- a/crates/core/machine/src/operations/field/range.rs +++ b/crates/core/machine/src/operations/field/range.rs @@ -98,7 +98,7 @@ impl FieldLtCols { // Assert that the flag is boolean. builder.when(is_real.clone()).assert_bool(flag); // Add the flag to the sum. - sum_flags += flag.into(); + sum_flags = sum_flags.clone() + flag.into(); } // Assert that the sum is equal to one. builder.when(is_real.clone()).assert_one(sum_flags); @@ -121,10 +121,10 @@ impl FieldLtCols { ) { // Once the byte flag was set to one, we turn off the quality check flag. // We can do this by calculating the sum of the flags since only `1` is set to `1`. - is_inequality_visited += flag.into(); + is_inequality_visited = is_inequality_visited.clone() + flag.into(); - lhs_comparison_byte += lhs_byte.clone() * flag; - rhs_comparison_byte += flag.into() * rhs_byte.clone(); + lhs_comparison_byte = lhs_comparison_byte.clone() + lhs_byte.clone() * flag; + rhs_comparison_byte = rhs_comparison_byte.clone() + flag.into() * rhs_byte.clone(); builder .when(is_real.clone()) diff --git a/crates/core/machine/src/operations/lt.rs b/crates/core/machine/src/operations/lt.rs index 5d9f000983..ae6c4c2bf4 100644 --- a/crates/core/machine/src/operations/lt.rs +++ b/crates/core/machine/src/operations/lt.rs @@ -81,7 +81,7 @@ impl AssertLtColsBytes { // Assert that the flag is boolean. builder.assert_bool(flag); // Add the flag to the sum. - sum_flags += flag.into(); + sum_flags = sum_flags.clone() + flag.into(); } // Assert that the sum is equal to one. builder.when(is_real.clone()).assert_one(sum_flags); @@ -104,10 +104,10 @@ impl AssertLtColsBytes { { // Once the byte flag was set to one, we turn off the quality check flag. // We can do this by calculating the sum of the flags since only `1` is set to `1`. - is_inequality_visited += flag.into(); + is_inequality_visited = is_inequality_visited.clone() + flag.into(); - first_lt_byte += a_byte.clone() * flag; - b_comparison_byte += b_byte.clone() * flag; + first_lt_byte = first_lt_byte.clone() + a_byte.clone() * flag; + b_comparison_byte = b_comparison_byte.clone() + b_byte.clone() * flag; builder .when_not(is_inequality_visited.clone()) @@ -189,7 +189,7 @@ impl AssertLtColsBits { // Assert that the flag is boolean. builder.assert_bool(flag); // Add the flag to the sum. - sum_flags += flag.into(); + sum_flags = sum_flags.clone() + flag.into(); } // Assert that the sum is equal to one. builder.when(is_real.clone()).assert_one(sum_flags); @@ -212,10 +212,10 @@ impl AssertLtColsBits { { // Once the bit flag was set to one, we turn off the quality check flag. // We can do this by calculating the sum of the flags since only `1` is set to `1`. - is_inequality_visited += flag.into(); + is_inequality_visited = is_inequality_visited.clone() + flag.into(); - a_comparison_bit += a_bit.clone() * flag; - b_comparison_bit += b_bit.clone() * flag; + a_comparison_bit = a_comparison_bit.clone() + a_bit.clone() * flag; + b_comparison_bit = b_comparison_bit.clone() + b_bit.clone() * flag; builder .when(is_real.clone()) diff --git a/crates/core/machine/src/syscall/precompiles/sha256/compress/air.rs b/crates/core/machine/src/syscall/precompiles/sha256/compress/air.rs index 648f9cdd34..2ecb8deb37 100644 --- a/crates/core/machine/src/syscall/precompiles/sha256/compress/air.rs +++ b/crates/core/machine/src/syscall/precompiles/sha256/compress/air.rs @@ -80,7 +80,7 @@ impl ShaCompressChip { // Verify that exactly one of the octet columns is true. let mut octet_sum = AB::Expr::zero(); for i in 0..8 { - octet_sum += local.octet[i].into(); + octet_sum = octet_sum.clone() + local.octet[i].into(); } builder.assert_one(octet_sum); @@ -100,7 +100,7 @@ impl ShaCompressChip { // Verify that exactly one of the octet_num columns is true. let mut octet_num_sum = AB::Expr::zero(); for i in 0..10 { - octet_num_sum += local.octet_num[i].into(); + octet_num_sum = octet_num_sum.clone() + local.octet_num[i].into(); } builder.assert_one(octet_num_sum); @@ -217,13 +217,13 @@ impl ShaCompressChip { // Calculate the current cycle_num. let mut cycle_num = AB::Expr::zero(); for i in 0..10 { - cycle_num += local.octet_num[i] * AB::Expr::from_canonical_usize(i); + cycle_num = cycle_num.clone() + local.octet_num[i] * AB::Expr::from_canonical_usize(i); } // Calculate the current step of the cycle 8. let mut cycle_step = AB::Expr::zero(); for i in 0..8 { - cycle_step += local.octet[i] * AB::Expr::from_canonical_usize(i); + cycle_step = cycle_step.clone() + local.octet[i] * AB::Expr::from_canonical_usize(i); } // Verify correct mem address for initialize phase @@ -490,7 +490,7 @@ impl ShaCompressChip { let mut filtered_operand = Word([zero.clone(), zero.clone(), zero.clone(), zero]); for (i, operand) in local.octet.iter().zip(add_operands.iter()) { for j in 0..4 { - filtered_operand.0[j] += *i * operand.0[j]; + filtered_operand.0[j] = filtered_operand.0[j].clone() + *i * operand.0[j]; } } diff --git a/crates/recursion/core/src/chips/poseidon2_skinny/mod.rs b/crates/recursion/core/src/chips/poseidon2_skinny/mod.rs index 637c00f3f9..ff3c7b32ce 100644 --- a/crates/recursion/core/src/chips/poseidon2_skinny/mod.rs +++ b/crates/recursion/core/src/chips/poseidon2_skinny/mod.rs @@ -52,7 +52,7 @@ pub(crate) fn external_linear_layer(state: &mut [AF; WIDTH]) core::array::from_fn(|k| (0..WIDTH).step_by(4).map(|j| state[j + k].clone()).sum::()); for j in 0..WIDTH { - state[j] += sums[j % 4].clone(); + state[j] = state[j].clone() + sums[j % 4].clone(); } } @@ -66,7 +66,7 @@ pub(crate) fn internal_linear_layer(state: &mut [F; WIDTH]) { .unwrap(); matmul_internal(state, matmul_constants); let monty_inverse = F::from_wrapped_u32(MONTY_INVERSE.as_canonical_u32()); - state.iter_mut().for_each(|i| *i *= monty_inverse.clone()); + state.iter_mut().for_each(|i| *i = i.clone() * monty_inverse.clone()); } #[cfg(test)] diff --git a/crates/recursion/core/src/chips/poseidon2_wide/mod.rs b/crates/recursion/core/src/chips/poseidon2_wide/mod.rs index 637c5afca9..266231b230 100644 --- a/crates/recursion/core/src/chips/poseidon2_wide/mod.rs +++ b/crates/recursion/core/src/chips/poseidon2_wide/mod.rs @@ -67,7 +67,7 @@ pub(crate) fn external_linear_layer(state: &mut [AF; WIDTH]) core::array::from_fn(|k| (0..WIDTH).step_by(4).map(|j| state[j + k].clone()).sum::()); for j in 0..WIDTH { - state[j] += sums[j % 4].clone(); + state[j] = state[j].clone() + sums[j % 4].clone(); } } @@ -89,7 +89,7 @@ pub(crate) fn internal_linear_layer(state: &mut [F; WIDTH]) { .unwrap(); matmul_internal(state, matmul_constants); let monty_inverse = F::from_wrapped_u32(MONTY_INVERSE.as_canonical_u32()); - state.iter_mut().for_each(|i| *i *= monty_inverse.clone()); + state.iter_mut().for_each(|i| *i = i.clone() * monty_inverse.clone()); } #[cfg(test)] diff --git a/crates/stark/src/air/builder.rs b/crates/stark/src/air/builder.rs index c64f1677cd..dc89f80d2e 100644 --- a/crates/stark/src/air/builder.rs +++ b/crates/stark/src/air/builder.rs @@ -97,7 +97,7 @@ pub trait BaseAirBuilder: AirBuilder + MessageBuilder let mut result = Self::Expr::zero(); for (value, i) in array.iter().zip_eq(index_bitmap) { - result += value.clone().into() * i.clone().into(); + result = result.clone() + value.clone().into() * i.clone().into(); } result diff --git a/crates/stark/src/air/extension.rs b/crates/stark/src/air/extension.rs index 0f810a026d..a986f0f06b 100644 --- a/crates/stark/src/air/extension.rs +++ b/crates/stark/src/air/extension.rs @@ -62,9 +62,10 @@ impl + Mul + AbstractField> Mul for BinomialExten for i in 0..D { for j in 0..D { if i + j >= D { - result[i + j - D] += w.clone() * self.0[i].clone() * rhs.0[j].clone(); + result[i + j - D] = result[i + j - D].clone() + + w.clone() * self.0[i].clone() * rhs.0[j].clone(); } else { - result[i + j] += self.0[i].clone() * rhs.0[j].clone(); + result[i + j] = result[i + j].clone() + self.0[i].clone() * rhs.0[j].clone(); } } } diff --git a/crates/stark/src/air/polynomial.rs b/crates/stark/src/air/polynomial.rs index 40f5fdbe84..e89ec78e03 100644 --- a/crates/stark/src/air/polynomial.rs +++ b/crates/stark/src/air/polynomial.rs @@ -126,7 +126,7 @@ impl + Add + AddAssign + Clone> Add for Polyno fn add(self, other: T) -> Polynomial { let mut coefficients = self.coefficients; - coefficients[0] += other; + coefficients[0] = coefficients[0].clone() + other; Self::new(coefficients) } } diff --git a/crates/stark/src/permutation.rs b/crates/stark/src/permutation.rs index 98c1555b93..1d0fa11574 100644 --- a/crates/stark/src/permutation.rs +++ b/crates/stark/src/permutation.rs @@ -335,11 +335,12 @@ pub fn eval_permutation_constraints<'a, F, AB>( let mut rlc = alpha.clone(); let mut betas = beta.powers(); - rlc += betas.next().unwrap() - * AB::ExprEF::from_canonical_usize(interaction.argument_index()); + rlc = rlc.clone() + + betas.next().unwrap() + * AB::ExprEF::from_canonical_usize(interaction.argument_index()); for (field, beta) in interaction.values.iter().zip(betas.clone()) { let elem = field.apply::(&preprocessed_local, main_local); - rlc += beta * elem; + rlc = rlc.clone() + beta * elem; } rlcs.push(rlc); @@ -357,16 +358,16 @@ pub fn eval_permutation_constraints<'a, F, AB>( let mut numerator = AB::ExprEF::zero(); for (i, (m, rlc)) in multiplicities.into_iter().zip(rlcs.iter()).enumerate() { // Calculate the running product of all rlcs. - product *= rlc.clone(); + product = product.clone() * rlc.clone(); // Calculate the product of all but the current rlc. let mut all_but_current = AB::ExprEF::one(); for other_rlc in rlcs.iter().enumerate().filter(|(j, _)| i != *j).map(|(_, rlc)| rlc) { - all_but_current *= other_rlc.clone(); + all_but_current = all_but_current.clone() * other_rlc.clone(); } - numerator += AB::ExprEF::from_base(m) * all_but_current; + numerator = numerator.clone() + AB::ExprEF::from_base(m) * all_but_current; } // Finally, assert that the entry is equal to the numerator divided by the product.