Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Require explicit overflow-checks flag #2716

Conversation

acheroncrypto
Copy link
Collaborator

Problem

overflow-checks flag is implicitly disabled by default.

Anchor workspaces that are crated with anchor init have this flag enabled by default but Anchor doesn't do any checks for it after workspace creation.

Summary of changes

  • Require explicit overflow-checks flag in workspace Cargo.toml
  • Add tests for add, sub, mul overflow cases
  • Add overflow-checks = true in all CI tests
  • Add a test to check whether anchor build fails when overflow-checks is not specified

Pros & Cons

Enabling overflow-checks not only allows to use regular math operations in a safe manner(and avoid checked_*().unwrap()) but it also works with dependencies i.e. a program will panic if a math operation in one of its dependencies overflows.

The only downside I can think of is that unchecked math operations cost a bit more compute units but this should be negligible.


Closes #1759

Copy link

vercel bot commented Nov 29, 2023

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit a423f78 into coral-xyz:master Nov 29, 2023
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error if overflow-checks isn't enabled in Cargo.toml
1 participant