Skip to content

Commit

Permalink
Merge pull request #1736 from o1-labs/fix/option-pure
Browse files Browse the repository at this point in the history
Fix: Allow Option to be used in events and state
  • Loading branch information
mitschabaude authored Jul 10, 2024
2 parents 9f0274f + 893d966 commit 7c8377d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Fix reversed order of account updates when using `TokenContract.approveAccountUpdates()` https://github.com/o1-labs/o1js/pull/1722
- Fixed the static `check()` method in Struct classes to properly handle inheritance, preventing issues with under-constrained circuits. Added error handling to avoid using Struct directly as a field type. https://github.com/o1-labs/o1js/pull/1707
- Fixed that `Option` could not be used as `@state` or event https://github.com/o1-labs/o1js/pull/1736

## [1.4.0](https://github.com/o1-labs/o1js/compare/40c597775...ed198f305) - 2024-06-25

Expand Down
5 changes: 3 additions & 2 deletions src/lib/provable/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InferValue } from '../../bindings/lib/provable-generic.js';
import { emptyValue } from '../proof-system/zkprogram.js';
import { Provable } from './provable.js';
import { InferProvable, Struct } from './types/struct.js';
import { provable } from './types/provable-derivers.js';
import { provable, ProvableInferPureFrom } from './types/provable-derivers.js';
import { Bool } from './wrapped.js';

export { Option, OptionOrValue };
Expand Down Expand Up @@ -36,7 +36,8 @@ type OptionOrValue<T, V> =
*/
function Option<A extends Provable<any, any>>(
type: A
): Provable<
): ProvableInferPureFrom<
A,
Option<InferProvable<A>, InferValue<A>>,
InferValue<A> | undefined
> &
Expand Down
4 changes: 4 additions & 0 deletions src/lib/provable/types/provable-derivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { GenericHashInput } from '../../../bindings/lib/generic.js';
// external API
export {
ProvableExtended,
ProvableInferPureFrom,
provable,
provablePure,
provableTuple,
Expand Down Expand Up @@ -50,6 +51,9 @@ type ProvablePureExtended<T, TValue = any, TJson = any> = ProvablePure<
type InferProvable<T> = GenericInferProvable<T, Field>;
type InferredProvable<T> = GenericInferredProvable<T, Field>;
type IsPure<T> = GenericIsPure<T, Field>;
type ProvableInferPureFrom<A, T, V> = IsPure<A> extends true
? ProvablePure<T, V>
: Provable<T, V>;

type HashInput = GenericHashInput<Field>;
const HashInput = createHashInput<Field>();
Expand Down

0 comments on commit 7c8377d

Please sign in to comment.