diff --git a/Cargo.lock b/Cargo.lock index a1163a91c..6ba9c3f41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -90,7 +90,7 @@ checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", "once_cell", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -149,7 +149,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -456,7 +456,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -622,7 +622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -829,12 +829,12 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gmp-mpfr-sys" -version = "1.4.13" +version = "1.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "781d258743e6e07d38c5bcd7468cfaa068d56789d10e8de0d3836d5bb338b5d7" +checksum = "60f8970a75c006bb2f8ae79c6768a116dd215fa8346a87aed99bf9d82ca43394" dependencies = [ "libc", - "winapi", + "windows-sys 0.60.2", ] [[package]] @@ -984,6 +984,12 @@ version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "linux-raw-sys" version = "0.9.3" @@ -1447,13 +1453,14 @@ dependencies = [ [[package]] name = "rug" -version = "1.18.0" +version = "1.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55313a5bab6820d1439c0266db37f8084e50618d35d16d81f692eee14d8b01b9" +checksum = "de190ec858987c79cad4da30e19e546139b3339331282832af004d0ea7829639" dependencies = [ "az", "gmp-mpfr-sys", "libc", + "libm", "serde", ] @@ -1468,9 +1475,9 @@ dependencies = [ [[package]] name = "rug-polynomial" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78837d2c84bd38a3c9e666f802e21837df9f46d8413f4787a823c9b448d392d" +checksum = "749dd4670a8f2d1e8bcebdc1ccf07511184b61fdcfacab985e147c9027b466ad" dependencies = [ "flint-sys", "gmp-mpfr-sys", @@ -1495,7 +1502,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1684,7 +1691,7 @@ dependencies = [ "getrandom 0.3.2", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1813,7 +1820,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1822,13 +1829,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", ] [[package]] @@ -1837,14 +1859,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] [[package]] @@ -1853,48 +1892,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + [[package]] name = "wit-bindgen-rt" version = "0.39.0" diff --git a/Cargo.toml b/Cargo.toml index 7ae638899..f2ff14f88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ circ_opt = { path = "circ_opt" } circ_hc = { path = "circ_hc", default-features = false, features = ["rc", "lru"]} circ_waksman = { path = "circ_waksman" } rug = { version = "1.11", features = ["serde"] } -gmp-mpfr-sys = { version = "1.4", optional = true } +gmp-mpfr-sys = { version = "1.6", optional = true } lazy_static = { version = "1.4", optional = true } rand = "0.8" rand_chacha = "0.3" @@ -26,7 +26,7 @@ typed-arena = { version = "2.0", optional = true } log = "0.4" thiserror = "1.0" bellman = { git = "https://github.com/alex-ozdemir/bellman.git", branch = "mirage", optional = true } -rug-polynomial = { version = "0.2.5", optional = true } +rug-polynomial = { version = "0.2.6", optional = true } rayon = { version = "1", optional = true } ff = { version = "0.12", optional = true } fxhash = "0.2" diff --git a/src/front/zsharp/parser.rs b/src/front/zsharp/parser.rs index dfd887b2f..96f65c1e7 100644 --- a/src/front/zsharp/parser.rs +++ b/src/front/zsharp/parser.rs @@ -126,10 +126,7 @@ impl<'a> Loader for &'a ZLoad { debug!("Parsing: {}", p.as_ref().display()); let s = self.sources.alloc(s); let ast = ast::generate_ast(s); - if ast.is_err() { - panic!("{}", ast.unwrap_err()); - } - Ok(ast.unwrap()) + Ok(ast.unwrap_or_else(|e| panic!("{}", e))) } fn includes>(&self, ast: &Self::AST, p: &P) -> Vec { let mut c = p.as_ref().to_path_buf(); diff --git a/src/front/zsharp/zvisit/zconstlitrw.rs b/src/front/zsharp/zvisit/zconstlitrw.rs index 6e0558cfe..f10799724 100644 --- a/src/front/zsharp/zvisit/zconstlitrw.rs +++ b/src/front/zsharp/zvisit/zconstlitrw.rs @@ -97,6 +97,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter { &mut self, dle: &mut ast::DecimalLiteralExpression<'ast>, ) -> ZVisitorResult { + #![allow(clippy::unnecessary_unwrap)] if dle.suffix.is_none() && self.to_ty.is_some() { self.found = true; dle.suffix.replace(match self.to_ty.as_ref().unwrap() { diff --git a/src/front/zsharpcurly/parser.rs b/src/front/zsharpcurly/parser.rs index 2251a0b1d..116157c5c 100644 --- a/src/front/zsharpcurly/parser.rs +++ b/src/front/zsharpcurly/parser.rs @@ -126,10 +126,7 @@ impl<'a> Loader for &'a ZLoad { debug!("Parsing: {}", p.as_ref().display()); let s = self.sources.alloc(s); let ast = ast::generate_ast(s); - if ast.is_err() { - panic!("{}", ast.unwrap_err()); - } - Ok(ast.unwrap()) + Ok(ast.unwrap_or_else(|e| panic!("{}", e))) } fn includes>(&self, ast: &Self::AST, p: &P) -> Vec { let mut c = p.as_ref().to_path_buf(); diff --git a/src/front/zsharpcurly/zvisit/zconstlitrw.rs b/src/front/zsharpcurly/zvisit/zconstlitrw.rs index 01e4012cf..332b62a70 100644 --- a/src/front/zsharpcurly/zvisit/zconstlitrw.rs +++ b/src/front/zsharpcurly/zvisit/zconstlitrw.rs @@ -113,6 +113,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter { &mut self, dle: &mut ast::DecimalLiteralExpression<'ast>, ) -> ZVisitorResult { + #![allow(clippy::unnecessary_unwrap)] if dle.suffix.is_none() && self.to_ty.is_some() { self.found = true; dle.suffix.replace(match self.to_ty.as_ref().unwrap() { diff --git a/src/ir/term/mod.rs b/src/ir/term/mod.rs index 383c2a9b2..3497ace3e 100644 --- a/src/ir/term/mod.rs +++ b/src/ir/term/mod.rs @@ -20,6 +20,7 @@ //! * [Computation]: a collection of variables and assertions about them //! * [Value]: a variable-free (and evaluated) term //! +#![allow(clippy::derive_ord_xor_partial_ord)] use circ_fields::{FieldT, FieldV}; pub use circ_hc::{Node, Table, Weak}; @@ -795,7 +796,6 @@ impl Array { impl std::cmp::Eq for Value {} // We walk in danger here, intentionally. One day we may fix it. // FP is the heart of the problem. -#[allow(clippy::derive_ord_xor_partial_ord)] impl std::cmp::Ord for Value { fn cmp(&self, o: &Self) -> std::cmp::Ordering { self.partial_cmp(o).expect("broken Value cmp") diff --git a/src/target/r1cs/trans.rs b/src/target/r1cs/trans.rs index 9d6cd81b7..e5b6defda 100644 --- a/src/target/r1cs/trans.rs +++ b/src/target/r1cs/trans.rs @@ -644,9 +644,11 @@ impl<'cfg> ToR1cs<'cfg> { acc } - /// Shift `x` left by `2^y`, if bit-valued `c` is true. + /// Shift `x` left by `2^(2^y)`, if bit-valued `c` is true. fn const_pow_shift_bv_lit(&mut self, x: &TermLc, y: usize, c: TermLc) -> TermLc { - self.ite(c, x.clone() * (1 << (1 << y)), x) + let two_to_the_y = 1usize.checked_shl(y as u32).unwrap(); + let multiple = self.r1cs.modulus.new_v(Integer::from(1) << two_to_the_y); + self.ite(c, x.clone() * &multiple, x) } /// Shift `x` left by `y`, filling the blank spots with bit-valued `ext_bit`. @@ -677,12 +679,17 @@ impl<'cfg> ToR1cs<'cfg> { ) -> Vec { let y_w = y.len(); let mask: TermLc = match ext_bit.as_ref() { - Some(e) => e.clone() * &self.r1cs.modulus.new_v((1 << x_w) - 1), + Some(e) => e.clone() * &self.r1cs.modulus.new_v((Integer::from(1) << x_w) - 1), None => self.zero.clone(), }; let s = self.shift_bv_lit(x, y, ext_bit); let masked_s = self.ite(c, mask, &s); - let mut bits = self.bitify("shift", &masked_s, (1 << y_w) + x_w - 1, false); + let mut bits = self.bitify( + "shift", + &masked_s, + 1usize.checked_shl(y_w as u32).unwrap() + x_w - 1, + false, + ); bits.truncate(x_w); bits } @@ -1391,6 +1398,56 @@ pub mod test { ]); } + #[test] + fn sh32_test() { + init(); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Shl); bv_lit(0b1,32), bv_lit(3,32)], + bv_lit(0b1000, 32) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(0b1,32), bv_lit(3,32)], + bv_lit(0, 32) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(u32::MAX,32), bv_lit(3,32)], + bv_lit(u32::MAX, 32) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(0b1,32), bv_lit(3,32)], + bv_lit(0, 32) + ]); + } + + #[test] + fn sh64_test() { + init(); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Shl); bv_lit(0b1,64), bv_lit(3,64)], + bv_lit(0b1000, 64) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(0b1,64), bv_lit(3,64)], + bv_lit(0, 64) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(u64::MAX,64), bv_lit(3,64)], + bv_lit(u64::MAX, 64) + ]); + const_test(term![ + Op::Eq; + term![Op::BvBinOp(BvBinOp::Ashr); bv_lit(0b1,64), bv_lit(3,64)], + bv_lit(0, 64) + ]); + } + #[test] fn pf2bv_lit() { init();