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

Fix in-circuit hashing of complex account update layouts #1364

Merged
merged 7 commits into from
Jan 11, 2024

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Jan 11, 2024

Fixes #706

This is the minimal PR that fixes the bug.

Finding the bug was possible thanks to new infrastructure for catching compile/prove discrepancies, which now lives in a follow-up PR: #1363 (still needs clean-up work, and relies on changes to snarky that need broader alignment)

Note: This doesn't add unit tests. Should it?
It doesn't seem obvious that complex account update layouts can be tested in isolation, since it was the global mutable structure of transactions, and unwanted cross-interactions between proofs at multiple layers of the callstack, that broke them. It seems that integration tests are needed to exhibit non-trivial failure cases, and this PR already fixes such an integration test as its main result

@@ -1321,6 +1347,7 @@ class AccountUpdate implements Types.AccountUpdate {
accountUpdate.body.mayUseToken.inheritFromParent.assertFalse();
return;
}
accountUpdate.children.callsType = { type: 'None' };
Copy link
Member Author

Choose a reason for hiding this comment

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

this fixed the bug. literally one line 😓

@@ -1096,11 +1096,37 @@ class AccountUpdate implements Types.AccountUpdate {
return { accountUpdate, calls };
}

toPrettyLayout() {
Copy link
Member Author

Choose a reason for hiding this comment

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

this was useful for debugging, leaving it in here

@nicc
Copy link
Collaborator

nicc commented Jan 11, 2024

@mitschabaude, since the DEX app is run on CI now, we would pick it up if this regressed / the bug was reintroduced right?

Intuitively, account updates seem like the kind of thing that shoud have good unit test coverage (and be easy to test) so I'm inclined to say it should have a unit test. If that's a lot of work then we could dig into why it's hard and see if that should be fixed?

@mitschabaude
Copy link
Member Author

@mitschabaude, since the DEX app is run on CI now, we would pick it up if this regressed / the bug was reintroduced right?

Yes, we would pick up if this regressed. DEX was already running in CI but in an insecure version that worked around the bug, which is fixed here

We do have unit tests for account updates, but what broke here still seems hard to unit-test. I could devise a test that would catch a regression, but it would be quite artificial, setting up an interaction between multiple calls to approve() in different proofs which mirrors what happens in the DEX example. Not what feels like a good unit test.

Ultimately, I think the culprit for this bug is the overall structure of the code which relies heavily on mutating a shared transaction object, including mutating the individual account updates, from random places in the code. The global structure of the code is bad, and I think it needs some design and refactoring work to become better. The broad idea for me would be to make the global list of account updates largely immutable except in a few well-defined places -- such that the effects of the code fixed here become more local, after which unit tests become meaningful.

@mitschabaude mitschabaude merged commit e5bac80 into main Jan 11, 2024
13 checks passed
@mitschabaude mitschabaude deleted the fix/prover-bug-reloaded branch January 11, 2024 20:25
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.

Support advanced account updates (prover bug reloaded)
3 participants