Skip to content

Commit

Permalink
Merge pull request #1580 from o1-labs/better-error
Browse files Browse the repository at this point in the history
Improve error handling for setting out of bounds on-chain state
  • Loading branch information
Trivo25 authored Apr 15, 2024
2 parents c427142 + beb1df2 commit b765707
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/mina/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ function createState<T>(): InternalStateType<T> {
let stateAsFields = this._contract.stateType.toFields(state);
let accountUpdate = this._contract.instance.self;
stateAsFields.forEach((x, i) => {
AccountUpdate.setValue(
accountUpdate.body.update.appState[layout.offset + i],
x
);
let appStateSlot =
accountUpdate.body.update.appState[layout.offset + i];
if (!appStateSlot)
throw Error(
`Attempted to set on-chain state variable \`${this._contract?.key}\`. Currently, only a total of 8 fields elements of on-chain state are supported.`
);
AccountUpdate.setValue(appStateSlot, x);
});
},

Expand Down

0 comments on commit b765707

Please sign in to comment.