Skip to content

Commit

Permalink
Merge pull request #689 from o1-labs/fix/reducer-struct
Browse files Browse the repository at this point in the history
Fix: this === undefined in Struct static methods
  • Loading branch information
mitschabaude committed Jan 12, 2023
2 parents f2b316a + beb45c4 commit f4b6aa7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Type inference for Structs with instance methods https://github.com/o1-labs/snarkyjs/pull/567
- also fixes `Struct.fromJSON`
- `SmartContract.fetchEvents` fixed when multiple event types existed https://github.com/o1-labs/snarkyjs/issues/627
- Error when using reduce with a `Struct` as state type https://github.com/o1-labs/snarkyjs/pull/689

## [0.7.3](https://github.com/o1-labs/snarkyjs/compare/5f20f496...d880bd6e)

Expand Down
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;
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

0 comments on commit f4b6aa7

Please sign in to comment.