From 919c98d63074f3f5c2da4eca96e37dc5b444719a Mon Sep 17 00:00:00 2001 From: davidsemakula Date: Thu, 28 Aug 2025 14:33:22 +0300 Subject: [PATCH 1/3] contract-build: Re-enable `overflow-checks` setting --- crates/build/src/workspace/manifest.rs | 10 +--------- crates/build/src/workspace/profile.rs | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/build/src/workspace/manifest.rs b/crates/build/src/workspace/manifest.rs index e21a88c3d..f5e37f0ff 100644 --- a/crates/build/src/workspace/manifest.rs +++ b/crates/build/src/workspace/manifest.rs @@ -134,19 +134,11 @@ impl Manifest { pub fn new(manifest_path: ManifestPath) -> Result { let toml = fs::read_to_string(&manifest_path).context("Loading Cargo.toml")?; let toml: value::Table = toml::from_str(&toml)?; - let mut manifest = Manifest { + let manifest = Manifest { path: manifest_path, toml, metadata_package: false, }; - let profile = manifest.profile_release_table_mut()?; - if profile - .get("overflow-checks") - .and_then(|val| val.as_bool()) - .unwrap_or(false) - { - anyhow::bail!("Overflow checks must be disabled. Cargo contract makes sure that no unchecked arithmetic is used.") - } Ok(manifest) } diff --git a/crates/build/src/workspace/profile.rs b/crates/build/src/workspace/profile.rs index a66e3aa1c..00761f19b 100644 --- a/crates/build/src/workspace/profile.rs +++ b/crates/build/src/workspace/profile.rs @@ -27,6 +27,7 @@ pub struct Profile { // `None` means use rustc default. pub codegen_units: Option, pub panic: Option, + pub overflow_checks: Option, } impl Profile { @@ -37,6 +38,7 @@ impl Profile { lto: Some(Lto::Fat), codegen_units: Some(1), panic: Some(PanicStrategy::Abort), + overflow_checks: Some(true), } } @@ -73,6 +75,7 @@ impl Profile { self.panic.map(PanicStrategy::to_toml_value), profile, ); + set_value_if_vacant("overflow-checks", self.overflow_checks, profile); } } @@ -159,6 +162,7 @@ mod tests { expected.insert("lto".into(), value::Value::String("fat".into())); expected.insert("codegen-units".into(), value::Value::Integer(1)); expected.insert("panic".into(), value::Value::String("abort".into())); + expected.insert("overflow-checks".into(), value::Value::Boolean(true)); let mut manifest_profile = toml::from_str(manifest_toml).unwrap(); @@ -176,12 +180,14 @@ mod tests { lto = false opt-level = 3 codegen-units = 256 + overflow-checks = false "#; let mut expected = value::Table::new(); expected.insert("opt-level".into(), value::Value::Integer(3)); expected.insert("lto".into(), value::Value::Boolean(false)); expected.insert("codegen-units".into(), value::Value::Integer(256)); expected.insert("panic".into(), value::Value::String("unwind".into())); + expected.insert("overflow-checks".into(), value::Value::Boolean(false)); let mut manifest_profile = toml::from_str(manifest_toml).unwrap(); From 617a55e42691d012da27c75bda96f584a167a440 Mon Sep 17 00:00:00 2001 From: davidsemakula Date: Thu, 28 Aug 2025 15:09:30 +0300 Subject: [PATCH 2/3] contract-build: Enable `compiler-builtins-mem` `build-std` feature --- crates/build/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index afb5d4ed5..297b15d44 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -357,7 +357,10 @@ fn exec_cargo_for_onchain_target( if build_mode == &BuildMode::Debug { features.push("ink/ink-debug".to_string()); } else { - args.push("-Zbuild-std-features=panic_immediate_abort".to_owned()); + args.push( + "-Zbuild-std-features=panic_immediate_abort,compiler-builtins-mem" + .to_owned(), + ); } features.append_to_args(&mut args); let mut env = Vec::new(); From e22e6b4266deb6b036a5b56d9111a09b782d19a2 Mon Sep 17 00:00:00 2001 From: davidsemakula Date: Tue, 2 Sep 2025 21:00:30 +0300 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 142478919..22fdf1685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Synchronized with `polkadot-sdk/c40b36c3a7c208f9a6837b80812473af3d9ba7f7` ‒ [2102](https://github.com/use-ink/cargo-contract/pull/2102) +- Re-enable `rustc` overflow checks - [#2116](https://github.com/use-ink/cargo-contract/pull/2116) ### Removed - Removed chain extension functionality ‒ [2120](https://github.com/use-ink/cargo-contract/pull/2120)