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

Add constraints to examples in dapps/ needed to prevent overflow. #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zenhack
Copy link
Contributor

@zenhack zenhack commented May 27, 2022

@marcinjangrzybowski asked me to come up with some examples of what index type constraints would look like in glow. This PR is a first step; it adds annotations that would become necessary for our existing apps in dapps/ to type check (and adds comments explaining what's going on). I'm pleased to see that it's already catching real bugs (if ones that are unlikely to come up in practice).

I'm going to mark this as a draft; we should not merge this, but it seemed like an easy way to get the diff in front of your eyes.

I plan to also look up some representative overflow exploits to see how this would apply to those as well.

Not to be merged; this is for discussion purposes.
let coinFlip = (wagerAmount : UInt256, escrowAmount : UInt256)

// required to ensure that the withdraw! statements do not overflow.
| (wagerAmount / 2) < MaxUInt256 - escrowAmount
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'm not 100% sure this constraint is correct -- there might be an off by one or something here, and I'm too tired to think through this methodically. But if it's wrong, the solver should complain that it still can't be sure there's no overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant