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: Keep track of changing permissions during transaction validation #1412

Merged
merged 5 commits into from
Feb 6, 2024

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Feb 5, 2024

This fixes a bug where a transaction that updated permissions on an existing account, and then tried to perform an action affected by the updated permissions, was incorrectly rejected by the TS pre-validation logic, because that logic didn't keep track of the changed permissions.

As a fix, we introduced a lightweight internal "ledger" on which individual account updates are applied, updating permissions.
This can be extended in the future to keep track of more account state on the TS side.

Note: There are no tests currently fixed by this. However, a unit test that would fail without this change is coming soon as part of #1384 (token-contract.unit-test.ts)

isValidProof = await verify(proof, verificationKey);
if (!isValidProof) {
throw Error(
`Invalid proof for account update\n${JSON.stringify(update)}`
);
}
} catch (error) {
errorTrace += '\n\n' + (error as Error).message;
errorTrace += '\n\n' + (error as Error).stack;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

much better to also include the stack trace here - that way you can see where the code failed

Comment on lines +1257 to +1261
let verificationKey = account.zkapp?.verificationKey?.data;
assert(
verificationKey !== undefined,
'Account does not have a verification key'
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ran into this being undefined in a test and failed down the line - better to have an explicit error about it right away

Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

nice, looking forward to extending this!

@mitschabaude mitschabaude merged commit a6a985a into main Feb 6, 2024
12 of 13 checks passed
@mitschabaude mitschabaude deleted the fix/valid-permissions branch February 6, 2024 10:40
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.

2 participants