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

Enforce state preconditions #267

Merged
merged 5 commits into from
Jun 28, 2022
Merged

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Jun 28, 2022

code that looked like this:

let x = this.x.get();

will throw an error, and has to be changed to look like this:

let x = this.x.get();
this.x.assertEquals(x);

this makes it consistent with the behaviour for other preconditions (#179)

if (!context?.wasRead || context.wasConstrained) continue;
// we accessed a precondition field but not constrained it explicitly - throw an error
let errorMessage = `You used \`this.${key}.get()\` without adding a precondition that links it to the actual on-chain state.
Consider adding this line to your code:
Copy link
Contributor

Choose a reason for hiding this comment

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

Great error message :D

Copy link
Contributor

@MartinMinkov MartinMinkov left a comment

Choose a reason for hiding this comment

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

Very clean, LGTM!

this._contract.wasConstrained = true;
},

assertNothing() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick question, when is assertNothing intended to be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

No specific use case I had in mind, I just wanted to have an escape hatch to get rid of the error if you have some reason to use .get() without having a precondition

@mitschabaude mitschabaude merged commit 1068560 into main Jun 28, 2022
@mitschabaude mitschabaude deleted the feature/enforce-state-precondition branch June 28, 2022 19:24
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.

Actually set the account precondition for on-chain state
3 participants