Disallow building with overflow-checks off#1702
Draft
leighmcculloch wants to merge 6 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a compile-time guard to prevent building Soroban contracts when integer overflow checks are disabled, using a build-time probe and an internal cfg flag.
Changes:
- Adds a build-script probe in
soroban-sdk/build.rsthat detects whetheroverflow-checksare enabled by attempting an overflowingu8addition and settingcfg(soroban_sdk_internal_overflow_checks_enabled)when a panic is observed. - Introduces a
compile_error!insoroban-sdk/src/lib.rsthat triggers when the internaloverflow-checkscfg flag is absent, with a pointer to the documentation on correctly configuring the release profile.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| soroban-sdk/build.rs | Adds a runtime probe and corresponding rustc-cfg/rustc-check-cfg output to encode overflow-checks status into a cfg flag at compile time. |
| soroban-sdk/src/lib.rs | Adds a compile_error! guarded by the new cfg flag to hard-fail builds when overflow checks are disabled, with a link to the recommended release profile configuration. |
dmkozh
approved these changes
Jan 27, 2026
jayz22
approved these changes
Jan 28, 2026
leighmcculloch
commented
Jan 29, 2026
mootz12
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
build.rsthat detects whetheroverflow-checksare enabled by attempting an overflowingu8addition and catching whether it panicscfgflag (soroban_sdk_internal_overflow_checks_enabled) when checks are oncompile_error!inlib.rsthat fires when the flag is absent, with a link to the docsWhy
Cargo's default
releaseprofile disablesoverflow-checks. Without this guard developers can silently build contracts with wrapping arithmetic, leading to unexpected behavior. The tooling for Soroban contracts that generates boilerplate for new contracts setsoverflow-checks = truefor the release profile, and docs encourage the same pattern, but this makes it a compile-time error so that anyone doesn't accidentally turn that off.This is a workaround until
cfg(overflow_checks)is stabilized (rust-lang/rust#111466).Known limitations
It may not detect overflow-checks being disabled in cross-compilation setups where the host and target profiles diverge or where the build-override profile is explicitly set to overflow-checks = true when the main profile is set to false. These are advanced configurations, and the check is primarily present to prevent developers using the default release profile that has checks off.