diff --git a/CHANGELOG.md b/CHANGELOG.md index a8a99dfe3c..8d5bcb382c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/lib/zkapp.ts b/src/lib/zkapp.ts index b29b17cfba..3588b2395c 100644 --- a/src/lib/zkapp.ts +++ b/src/lib/zkapp.ts @@ -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); });