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: this === undefined in Struct static methods #689

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/lib/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,16 +1268,8 @@ Use the optional \`maxTransactionsWithActions\` argument to increase this number
// also, for each action length, compute the new state and then pick the actual one
let newStates = actionss.map((actions) => {
// we generate a new witness for the state so that this doesn't break if `apply` modifies the state
let newState = Circuit.witness(stateType, () => {
// TODO: why doesn't this work without the toConstant mapping?
let { toFields, fromFields, toAuxiliary } = stateType;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the problem here was that pulling those static members out of the class is not compatible with using this in those static methods. js rookie mistake

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and it turns out wee don't need that toConstant logic anymore, at all, because Circuit.witness does that under the hood anyway

return fromFields(
toFields(state).map((x) => x.toConstant()),
toAuxiliary(state)
);
// return state;
});
Circuit.assertEqual(newState, state);
let newState = Circuit.witness(stateType, () => state);
Circuit.assertEqual(stateType, newState, state);
actions.forEach((action) => {
newState = reduce(newState, action);
});
Expand Down