A reducer to process actions in fixed-size batches.
let batchReducer = new BatchReducer({ actionType: Action, batchSize: 5 });
// in contract: concurrent dispatching of actions
batchReducer.dispatch(action);
// reducer logic
// outside contract: prepare a list of { batch, proof } objects which cover all pending actions
let batches = await batchReducer.prepareBatches();
// in contract: process a single batch
// create one transaction that does this for each batch!
batchReducer.processBatch({ batch, proof }, (action, isDummy) => {
// ...
});
BatchReducer
<ActionType
,BatchSize
,Action
>
• ActionType extends Actionable
<any
>
• BatchSize extends number
= number
• Action = InferProvable
<ActionType
>
new BatchReducer<ActionType, BatchSize, Action>(__namedParameters: {
"actionType": ActionType;
"batchSize": BatchSize;
"maxActionsPerUpdate": number;
"maxUpdatesFinalProof": 100;
"maxUpdatesPerProof": 300;
}): BatchReducer<ActionType, BatchSize, Action>
• __namedParameters
• __namedParameters.actionType: ActionType
The provable type of actions submitted by this reducer.
• __namedParameters.batchSize: BatchSize
The number of actions in a batch. The idea is to process one batch per transaction, by calling processBatch()
.
The motivation for processing actions in small batches is to work around the protocol limit on the number of account updates. If every action should result in an account update, then you have to set the batch size low enough to not exceed the limit.
If transaction limits are no concern, the batchSize
could be set based on amount of logic you do per action.
A smaller batch size will make proofs faster, but you might need more individual transactions as more batches are needed to process all pending actions.
• __namedParameters.maxActionsPerUpdate?: number
= undefined
The maximum number of actions dispatched in any of the zkApp methods on the contract.
Note: This number just has to be an upper bound of the actual maximum, but if it's the precise number, fewer constraints will be used. (The overhead of a higher number is fairly small though.)
A restriction is that the number has to be less or equal than the batchSize
.
The reason is that actions in one account update are always processed together, so if you'd have more actions in one than the batch size, we couldn't process them at all.
By default, this is set to Math.min(batchSize, 5)
which should be sensible for most applications.
• __namedParameters.maxUpdatesFinalProof?: number
= 100
The maximum number of action lists (= all actions on an account update) to process inside processBatch()
,
i.e. in your zkApp method.
Default: 100, which will take up about 3000 constraints.
The current default should be sensible for most applications, but here are some trade-offs to consider when changing it:
- Using a smaller number means a smaller circuit, so proofs of your method will be faster.
- Using a bigger number means it's more likely that you can prove all actions in the method call and won't need a recursive proof.
So, go lower if you expect very few actions, and higher if you expect a lot of actions.
• __namedParameters.maxUpdatesPerProof?: number
= 300
The maximum number of action lists (= all actions on an account update) to process in a single recursive proof, in prepareBatches()
.
Default: 300, which will take up about 9000 constraints.
The current default should be sensible for most applications, but here are some trade-offs to consider when changing it:
- Using a smaller number means a smaller circuit, so recursive proofs will be faster.
- Using a bigger number means you'll need fewer recursive proofs in the case a lot of actions are pending.
So, go lower if you expect very few actions, and higher if you expect a lot of actions. (Note: A larger circuit causes longer compilation and proof times for your zkApp even if you never need a recursive proof)
BatchReducer
<ActionType
, BatchSize
, Action
>
BatchReducer_.BatchReducer<ActionType, BatchSize, Action>.constructor
lib/mina/actions/batch-reducer.ts:75
Batch: (value: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
} & {
"_isStruct": true;
} & Provable<{
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}, {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": any;
"useOnchainStack": Bool;
"witnesses": ActionWitnesses;
}> & {
"empty": () => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
"fromJSON": (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
"useOnchainStack": Bool;
"witnesses": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
"fromValue": (value: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": any;
"useOnchainStack": Bool;
"witnesses": ActionWitnesses | Unconstrained<ActionWitnesses>;
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
"toInput": (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}) => {
"fields": Field[];
"packed": [Field, number][];
};
"toJSON": (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
"useOnchainStack": Bool;
"witnesses": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
};
};
_isStruct: true;
empty: () => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
{
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}
isRecursive: Bool = Bool;
onchainActionState: Field = Field;
onchainStack: Field = Field;
processedActionState: Field = Field;
stack: MerkleList<MerkleList<Hashed<any>>>;
useOnchainStack: Bool = Bool;
witnesses: Unconstrained<ActionWitnesses>;
fromJSON: (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
"useOnchainStack": Bool;
"witnesses": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
• x
• x.isRecursive: boolean
= Bool
• x.onchainActionState: string
= Field
• x.onchainStack: string
= Field
• x.processedActionState: string
= Field
• x.stack= undefined
• x.stack._emptyHash: null
| string
• x.stack._innerProvable: null
| {
"check"
: {};
"empty"
: {};
"fromFields"
: {};
"fromValue"
: {};
"toAuxiliary"
: {};
"toCanonical"
: null
| {};
"toFields"
: {};
"toInput"
: {};
"toValue"
: {};
"sizeInFields"
: ;
}
• x.stack._nextHash: null
| {}
• x.stack._provable: null
| {
"check"
: {};
"empty"
: {};
"fromFields"
: {};
"fromValue"
: {};
"toAuxiliary"
: {};
"toCanonical"
: null
| {};
"toFields"
: {};
"toInput"
: {};
"toValue"
: {};
"sizeInFields"
: ;
}
• x.stack.empty
• x.stack.emptyHash: string
• x.stack.from
• x.stack.fromReverse
• x.stack.prototype
• x.stack.prototype.Constructor
• x.stack.prototype.Constructor._emptyHash: null
| string
• x.stack.prototype.Constructor._innerProvable: null
| {
"check"
: {};
"empty"
: {};
"fromFields"
: {};
"fromValue"
: {};
"toAuxiliary"
: {};
"toCanonical"
: null
| {};
"toFields"
: {};
"toInput"
: {};
"toValue"
: {};
"sizeInFields"
: ;
}
• x.stack.prototype.Constructor._nextHash: null
| {}
• x.stack.prototype.Constructor._provable: null
| {
"check"
: {};
"empty"
: {};
"fromFields"
: {};
"fromValue"
: {};
"toAuxiliary"
: {};
"toCanonical"
: null
| {};
"toFields"
: {};
"toInput"
: {};
"toValue"
: {};
"sizeInFields"
: ;
}
• x.stack.prototype.Constructor.emptyHash: string
• x.stack.prototype.Constructor.prototype: { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; }
• x.stack.prototype.Constructor.create
Create a Merkle list type
Optionally, you can tell create()
how to do the hash that pushes a new list element, by passing a nextHash
function.
Example
class MyList extends MerkleList.create(Field, (hash, x) =>
Poseidon.hashWithPrefix('custom', [hash, x])
) {}
• x.stack.prototype.data
• x.stack.prototype.data.get
Read an unconstrained value.
Note: Can only be called outside provable code.
• x.stack.prototype.data.set
Modify the unconstrained value.
• x.stack.prototype.data.setTo
Set the unconstrained value to the same as another Unconstrained
.
• x.stack.prototype.data.updateAsProver
Update an Unconstrained
by a witness computation.
• x.stack.prototype.hash: string
• x.stack.prototype.innerProvable
• x.stack.prototype.innerProvable.check
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
Param
the element of type T
to put assertions on.
• x.stack.prototype.innerProvable.empty
• x.stack.prototype.innerProvable.fromFields
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
Param
an array of Field elements describing the provable data of the new T
element.
Param
an array of any type describing the "auxiliary" data of the new T
element, optional.
• x.stack.prototype.innerProvable.fromValue
Convert provable type from a normal JS type.
• x.stack.prototype.innerProvable.toAuxiliary
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
Param
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
• x.stack.prototype.innerProvable.toCanonical?: null
| {}
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
• x.stack.prototype.innerProvable.toFields
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
Param
the element of type T
to generate the Field array from.
• x.stack.prototype.innerProvable.toInput
• x.stack.prototype.innerProvable.toValue
Convert provable type to a normal JS type.
• x.stack.prototype.innerProvable.sizeInFields
• x.stack.prototype.clone
• x.stack.prototype.forEach
Iterate through the list in a fixed number of steps any apply a given callback on each element.
Proves that the iteration traverses the entire list. Once past the last element, dummy elements will be passed to the callback.
Note: There are no guarantees about the contents of dummy elements, so the callback is expected
to handle the isDummy
flag separately.
• x.stack.prototype.isEmpty
• x.stack.prototype.lengthUnconstrained
• x.stack.prototype.nextHash
• x.stack.prototype.pop
Remove the last element from the list and return it.
If the list is empty, returns a dummy element.
• x.stack.prototype.popExn
Remove the last element from the list and return it.
This proves that the list is non-empty, and fails otherwise.
• x.stack.prototype.popIf
Return the last element, but only remove it if condition
is true.
If the list is empty, returns a dummy element.
• x.stack.prototype.popIfUnsafe
Low-level, minimal version of pop()
which lets the caller decide whether there is an element to pop.
I.e. this proves:
- If the input condition is true, this returns the last element and removes it from the list.
- If the input condition is false, the list is unchanged and the return value is garbage.
Note that if the caller passes true
but the list is empty, this will fail.
If the caller passes false
but the list is non-empty, this succeeds and just doesn't pop off an element.
• x.stack.prototype.push
Push a new element to the list.
• x.stack.prototype.pushIf
Push a new element to the list, if the condition
is true.
• x.stack.prototype.startIterating
• x.stack.prototype.startIteratingFromLast
• x.stack.prototype.toArrayUnconstrained
• x.stack.provable
• x.stack.provable.check
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
Param
the element of type T
to put assertions on.
• x.stack.provable.empty
• x.stack.provable.fromFields
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
Param
an array of Field elements describing the provable data of the new T
element.
Param
an array of any type describing the "auxiliary" data of the new T
element, optional.
• x.stack.provable.fromValue
Convert provable type from a normal JS type.
• x.stack.provable.toAuxiliary
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
Param
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
• x.stack.provable.toCanonical?: null
| {}
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
• x.stack.provable.toFields
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
Param
the element of type T
to generate the Field array from.
• x.stack.provable.toInput
• x.stack.provable.toValue
Convert provable type to a normal JS type.
• x.stack.provable.sizeInFields
• x.stack.create
Create a Merkle list type
Optionally, you can tell create()
how to do the hash that pushes a new list element, by passing a nextHash
function.
Example
class MyList extends MerkleList.create(Field, (hash, x) =>
Poseidon.hashWithPrefix('custom', [hash, x])
) {}
• x.useOnchainStack: boolean
= Bool
• x.witnesses= undefined
• x.witnesses.check
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
Param
the element of type T
to put assertions on.
• x.witnesses.empty
• x.witnesses.fromFields
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
Param
an array of Field elements describing the provable data of the new T
element.
Param
an array of any type describing the "auxiliary" data of the new T
element, optional.
• x.witnesses.fromValue
Convert provable type from a normal JS type.
• x.witnesses.toAuxiliary
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
Param
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
• x.witnesses.toCanonical?: null
| {}
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
• x.witnesses.toFields
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
Param
the element of type T
to generate the Field array from.
• x.witnesses.toInput
• x.witnesses.toValue
Convert provable type to a normal JS type.
• x.witnesses.sizeInFields
{
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}
isRecursive: Bool = Bool;
onchainActionState: Field = Field;
onchainStack: Field = Field;
processedActionState: Field = Field;
stack: MerkleList<MerkleList<Hashed<any>>>;
useOnchainStack: Bool = Bool;
witnesses: Unconstrained<ActionWitnesses>;
fromValue: (value: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": any;
"useOnchainStack": Bool;
"witnesses": ActionWitnesses | Unconstrained<ActionWitnesses>;
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
};
• value
• value.isRecursive: boolean
| Bool
= Bool
• value.onchainActionState: string
| number
| bigint
| Field
= Field
• value.onchainStack: string
| number
| bigint
| Field
= Field
• value.processedActionState: string
| number
| bigint
| Field
= Field
• value.stack: any
= undefined
• value.useOnchainStack: boolean
| Bool
= Bool
• value.witnesses: ActionWitnesses
| Unconstrained
<ActionWitnesses
>= undefined
{
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}
isRecursive: Bool = Bool;
onchainActionState: Field = Field;
onchainStack: Field = Field;
processedActionState: Field = Field;
stack: MerkleList<MerkleList<Hashed<any>>>;
useOnchainStack: Bool = Bool;
witnesses: Unconstrained<ActionWitnesses>;
toInput: (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}) => {
"fields": Field[];
"packed": [Field, number][];
};
• x
• x.isRecursive: Bool
= Bool
• x.onchainActionState: Field
= Field
• x.onchainStack: Field
= Field
• x.processedActionState: Field
= Field
• x.stack: MerkleList
<MerkleList
<Hashed
<any
>>>= undefined
• x.useOnchainStack: Bool
= Bool
• x.witnesses: Unconstrained
<ActionWitnesses
>= undefined
{
"fields": Field[];
"packed": [Field, number][];
}
optional fields: Field[];
optional packed: [Field, number][];
toJSON: (x: {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": MerkleList<MerkleList<Hashed<any>>>;
"useOnchainStack": Bool;
"witnesses": Unconstrained<ActionWitnesses>;
}) => {
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
"useOnchainStack": Bool;
"witnesses": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
};
• x
• x.isRecursive: Bool
= Bool
• x.onchainActionState: Field
= Field
• x.onchainStack: Field
= Field
• x.processedActionState: Field
= Field
• x.stack: MerkleList
<MerkleList
<Hashed
<any
>>>= undefined
• x.useOnchainStack: Bool
= Bool
• x.witnesses: Unconstrained
<ActionWitnesses
>= undefined
{
"isRecursive": Bool;
"onchainActionState": Field;
"onchainStack": Field;
"processedActionState": Field;
"stack": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
"useOnchainStack": Bool;
"witnesses": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
}
isRecursive: boolean = Bool;
onchainActionState: string = Field;
onchainStack: string = Field;
processedActionState: string = Field;
stack: {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"empty": {};
"emptyHash": string;
"from": {};
"fromReverse": {};
"prototype": {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
"provable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"create": ;
};
_emptyHash: null | string;
_innerProvable: null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
_nextHash: null | {};
_provable: null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
empty: {};
emptyHash: string;
from: {};
fromReverse: {};
prototype: {
"Constructor": {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
"data": {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
"hash": string;
"innerProvable": {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"clone": ;
"forEach": ;
"isEmpty": ;
"lengthUnconstrained": ;
"nextHash": ;
"pop": ;
"popExn": ;
"popIf": ;
"popIfUnsafe": ;
"push": ;
"pushIf": ;
"startIterating": ;
"startIteratingFromLast": ;
"toArrayUnconstrained": ;
};
Constructor: {
"_emptyHash": null | string;
"_innerProvable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"_nextHash": null | {};
"_provable": null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
"emptyHash": string;
"prototype": { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
"create": ;
};
_emptyHash: null | string;
_innerProvable: null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
_nextHash: null | {};
_provable: null | {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
emptyHash: string;
prototype: { hash: string; data: { get: {}; set: {}; setTo: {}; updateAsProver: {}; }; isEmpty: {}; push: {}; pushIf: {}; popExn: {}; pop: {}; popIf: {}; popIfUnsafe: {}; clone: {}; forEach: {}; startIterating: {}; startIteratingFromLast: {}; ... 4 more ...; readonly innerProvable: { ...; }; };
create;
Create a Merkle list type
Optionally, you can tell create()
how to do the hash that pushes a new list element, by passing a nextHash
function.
class MyList extends MerkleList.create(Field, (hash, x) =>
Poseidon.hashWithPrefix('custom', [hash, x])
) {}
data: {
"get": ;
"set": ;
"setTo": ;
"updateAsProver": ;
};
get;
Read an unconstrained value.
Note: Can only be called outside provable code.
set;
Modify the unconstrained value.
setTo;
Set the unconstrained value to the same as another Unconstrained
.
updateAsProver;
Update an Unconstrained
by a witness computation.
hash: string;
innerProvable: {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
check: {};
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
the element of type T
to put assertions on.
empty: {};
fromFields: {};
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
an array of Field elements describing the provable data of the new T
element.
an array of any type describing the "auxiliary" data of the new T
element, optional.
fromValue: {};
Convert provable type from a normal JS type.
toAuxiliary: {};
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
optional toCanonical: null | {};
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
toFields: {};
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
the element of type T
to generate the Field array from.
toInput: {};
toValue: {};
Convert provable type to a normal JS type.
sizeInFields;
clone;
forEach;
Iterate through the list in a fixed number of steps any apply a given callback on each element.
Proves that the iteration traverses the entire list. Once past the last element, dummy elements will be passed to the callback.
Note: There are no guarantees about the contents of dummy elements, so the callback is expected
to handle the isDummy
flag separately.
isEmpty;
lengthUnconstrained;
nextHash;
pop;
Remove the last element from the list and return it.
If the list is empty, returns a dummy element.
popExn;
Remove the last element from the list and return it.
This proves that the list is non-empty, and fails otherwise.
popIf;
Return the last element, but only remove it if condition
is true.
If the list is empty, returns a dummy element.
popIfUnsafe;
Low-level, minimal version of pop()
which lets the caller decide whether there is an element to pop.
I.e. this proves:
- If the input condition is true, this returns the last element and removes it from the list.
- If the input condition is false, the list is unchanged and the return value is garbage.
Note that if the caller passes true
but the list is empty, this will fail.
If the caller passes false
but the list is non-empty, this succeeds and just doesn't pop off an element.
push;
Push a new element to the list.
pushIf;
Push a new element to the list, if the condition
is true.
startIterating;
startIteratingFromLast;
toArrayUnconstrained;
provable: {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
check: {};
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
the element of type T
to put assertions on.
empty: {};
fromFields: {};
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
an array of Field elements describing the provable data of the new T
element.
an array of any type describing the "auxiliary" data of the new T
element, optional.
fromValue: {};
Convert provable type from a normal JS type.
toAuxiliary: {};
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
optional toCanonical: null | {};
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
toFields: {};
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
the element of type T
to generate the Field array from.
toInput: {};
toValue: {};
Convert provable type to a normal JS type.
sizeInFields;
create;
Create a Merkle list type
Optionally, you can tell create()
how to do the hash that pushes a new list element, by passing a nextHash
function.
class MyList extends MerkleList.create(Field, (hash, x) =>
Poseidon.hashWithPrefix('custom', [hash, x])
) {}
useOnchainStack: boolean = Bool;
witnesses: {
"check": {};
"empty": {};
"fromFields": {};
"fromValue": {};
"toAuxiliary": {};
"toCanonical": null | {};
"toFields": {};
"toInput": {};
"toValue": {};
"sizeInFields": ;
};
check: {};
Add assertions to the proof to check if value
is a valid member of type T
.
This function does not return anything, instead it creates any number of assertions to prove that value
is a valid member of the type T
.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
the element of type T
to put assertions on.
empty: {};
fromFields: {};
A function that returns an element of type T
from the given provable and "auxiliary" data.
This function is the reverse operation of calling toFields and toAuxiliary methods on an element of type T
.
an array of Field elements describing the provable data of the new T
element.
an array of any type describing the "auxiliary" data of the new T
element, optional.
fromValue: {};
Convert provable type from a normal JS type.
toAuxiliary: {};
A function that takes value
(optional), an element of type T
, as argument and
returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
the element of type T
to generate the auxiliary data array from, optional.
If not provided, a default value for auxiliary data is returned.
optional toCanonical: null | {};
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField
class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical()
converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical()
is not present on a type.
toFields: {};
A function that takes value
, an element of type T
, as argument and returns
an array of Field elements that make up the provable data of value
.
the element of type T
to generate the Field array from.
toInput: {};
toValue: {};
Convert provable type to a normal JS type.
sizeInFields;
BatchReducer_.BatchReducer.Batch
lib/mina/actions/batch-reducer.ts:67
BatchProof: typeof Proof;
BatchReducer_.BatchReducer.BatchProof
lib/mina/actions/batch-reducer.ts:70
optional _contract: BatchReducerContract;
BatchReducer_.BatchReducer._contract
lib/mina/actions/batch-reducer.ts:164
optional _contractClass: BatchReducerContractClass;
BatchReducer_.BatchReducer._contractClass
lib/mina/actions/batch-reducer.ts:165
actionType: Provable<Action, any> & {
"empty": () => Action;
} & {
"toInput": (x: Action) => HashInput;
} & Omit<Provable<Action, any>, "fromFields"> & {
"fromFields": (fields: Field[]) => Action;
};
empty: () => Action;
Action
toInput: (x: Action) => HashInput;
• x: Action
HashInput
fromFields: (fields: Field[]) => Action;
• fields: Field
[]
Action
BatchReducer_.BatchReducer.actionType
lib/mina/actions/batch-reducer.ts:66
batchSize: BatchSize;
BatchReducer_.BatchReducer.batchSize
lib/mina/actions/batch-reducer.ts:65
maxActionsPerUpdate: number;
BatchReducer_.BatchReducer.maxActionsPerUpdate
lib/mina/actions/batch-reducer.ts:73
maxUpdatesFinalProof: number;
BatchReducer_.BatchReducer.maxUpdatesFinalProof
lib/mina/actions/batch-reducer.ts:72
program: ActionStackProgram;
BatchReducer_.BatchReducer.program
lib/mina/actions/batch-reducer.ts:69
get static initialActionStack(): Field
lib/mina/actions/batch-reducer.ts:160
get static initialActionState(): Field
lib/mina/actions/batch-reducer.ts:157
compile(): Promise<{
"verificationKey": {
"data": string;
"hash": Field;
};
}>
Compile the recursive action stack prover.
Promise
<{
"verificationKey"
: {
"data"
: string
;
"hash"
: Field
;
};
}>
verificationKey: { "data": string; "hash": Field; };data: string;hash: Field;
BatchReducer_.BatchReducer.compile
lib/mina/actions/batch-reducer.ts:421
contract(): BatchReducerContract
BatchReducerContract
BatchReducer_.BatchReducer.contract
lib/mina/actions/batch-reducer.ts:174
contractClass(): BatchReducerContractClass
BatchReducerContractClass
BatchReducer_.BatchReducer.contractClass
lib/mina/actions/batch-reducer.ts:167
dispatch(action: From<ActionType>): void
Submit an action.
• action: From
<ActionType
>
void
BatchReducer_.BatchReducer.dispatch
lib/mina/actions/batch-reducer.ts:202
dispatchIf(condition: Bool, action: From<ActionType>): void
Conditionally submit an action.
• condition: Bool
• action: From
<ActionType
>
void
BatchReducer_.BatchReducer.dispatchIf
lib/mina/actions/batch-reducer.ts:215
prepareBatches(): Promise<{
"batch": ActionBatch<Action>;
"proof": ActionStackProof;
}[]>
Create a proof which returns the next actions batch(es) to process and helps guarantee their correctness.
Promise
<{
"batch"
: ActionBatch
<Action
>;
"proof"
: ActionStackProof
;
}[]>
BatchReducer_.BatchReducer.prepareBatches
lib/mina/actions/batch-reducer.ts:428
processBatch(__namedParameters: {
"batch": ActionBatch<Action>;
"proof": Proof<Field, ActionStackState>;
}, callback: (action: Action, isDummy: Bool, i: number) => void): void
Process a batch of actions which was created by prepareBatches()
.
Important: The callback exposes the action's value along with an isDummy
flag.
This is necessary because we process a dynamically-sized list in a fixed number of steps.
Dummies will be passed to your callback once the actual actions are exhausted.
Make sure to write your code to account for dummies. For example, when sending MINA from your contract for every action,
you probably want to zero out the balance decrease in the isDummy
case:
processBatch({ batch, proof }, (action, isDummy) => {
// ... other logic ...
let amountToSend = Provable.if(isDummy, UInt64.zero, action.amount);
this.balance.subInPlace(amountToSend);
});
Warning: Don't call processBatch()
on two different batches within the same method. The second call
would override the preconditions set by the first call, which would leave the method insecure.
To process more actions per method call, increase the batchSize
.
• __namedParameters
• __namedParameters.batch: ActionBatch
<Action
>
• __namedParameters.proof: Proof
<Field
, ActionStackState
>
• callback
void
BatchReducer_.BatchReducer.processBatch
lib/mina/actions/batch-reducer.ts:253
setContractClass(contractClass: BatchReducerContractClass): void
Set the smart contract class this reducer is connected with.
Note: You can use either this method or setContractInstance()
before calling compile()
.
However, setContractInstance()
is required for proveNextBatch()
.
• contractClass: BatchReducerContractClass
void
BatchReducer_.BatchReducer.setContractClass
lib/mina/actions/batch-reducer.ts:195
setContractInstance(contract: BatchReducerContract): void
Set the smart contract instance this reducer is connected with.
Note: This is a required step before using dispatch()
, proveNextBatch()
or processNextBatch()
.
• contract: BatchReducerContract
void
BatchReducer_.BatchReducer.setContractInstance