@proto-kit/protocol 0.1.1-develop.336 → 0.1.1-develop.455
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockmodules/AccountStateModule.d.ts +1 -1
- package/dist/blockmodules/AccountStateModule.d.ts.map +1 -1
- package/dist/blockmodules/BlockHeightHook.d.ts +7 -0
- package/dist/blockmodules/BlockHeightHook.d.ts.map +1 -0
- package/dist/blockmodules/BlockHeightHook.js +16 -0
- package/dist/blockmodules/NoopBlockHook.d.ts +7 -0
- package/dist/blockmodules/NoopBlockHook.d.ts.map +1 -0
- package/dist/blockmodules/NoopBlockHook.js +9 -0
- package/dist/blockmodules/NoopTransactionHook.d.ts +1 -1
- package/dist/blockmodules/NoopTransactionHook.d.ts.map +1 -1
- package/dist/blockmodules/NoopTransactionHook.js +1 -2
- package/dist/hooks/AccountStateHook.d.ts +38 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -0
- package/dist/hooks/AccountStateHook.js +36 -0
- package/dist/hooks/BlockHeightHook.d.ts +7 -0
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -0
- package/dist/hooks/BlockHeightHook.js +14 -0
- package/dist/hooks/NoopBlockHook.d.ts +7 -0
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -0
- package/dist/hooks/NoopBlockHook.js +9 -0
- package/dist/hooks/NoopTransactionHook.d.ts +6 -0
- package/dist/hooks/NoopTransactionHook.d.ts.map +1 -0
- package/dist/hooks/NoopTransactionHook.js +4 -0
- package/dist/hooks/TransactionFeeHook.d.ts +16 -0
- package/dist/hooks/TransactionFeeHook.d.ts.map +1 -0
- package/dist/hooks/TransactionFeeHook.js +39 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/model/Option.d.ts +29 -22
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +51 -45
- package/dist/model/StateTransition.d.ts +4 -2
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +2 -2
- package/dist/model/network/NetworkState.d.ts +1 -0
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +7 -0
- package/dist/protocol/Protocol.d.ts +4 -18
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +20 -9
- package/dist/protocol/ProtocolModule.d.ts +2 -2
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +1 -1
- package/dist/protocol/ProvableBlockHook.d.ts +16 -0
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
- package/dist/protocol/ProvableBlockHook.js +4 -0
- package/dist/protocol/ProvableTransactionHook.d.ts +2 -1
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.d.ts +4 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.js +4 -0
- package/dist/prover/block/BlockProvable.d.ts +21 -0
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +3 -1
- package/dist/prover/block/BlockProver.d.ts +9 -4
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +66 -16
- package/dist/prover/block/BlockTransactionPosition.d.ts +36 -0
- package/dist/prover/block/BlockTransactionPosition.d.ts.map +1 -0
- package/dist/prover/block/BlockTransactionPosition.js +25 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +1 -1
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +4 -5
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +3 -3
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionWitnessProvider.js +2 -2
- package/dist/state/State.d.ts +8 -1
- package/dist/state/State.d.ts.map +1 -1
- package/dist/state/State.js +11 -4
- package/dist/state/StateServiceProvider.d.ts +0 -2
- package/dist/state/StateServiceProvider.d.ts.map +1 -1
- package/dist/state/StateServiceProvider.js +5 -17
- package/package.json +3 -2
- package/src/blockmodules/AccountStateModule.ts +2 -2
- package/src/blockmodules/BlockHeightHook.ts +22 -0
- package/src/blockmodules/NoopBlockHook.ts +16 -0
- package/src/blockmodules/NoopTransactionHook.ts +3 -4
- package/src/index.ts +4 -4
- package/src/model/Option.ts +71 -56
- package/src/model/StateTransition.ts +2 -2
- package/src/model/network/NetworkState.ts +8 -0
- package/src/protocol/Protocol.ts +33 -32
- package/src/protocol/ProtocolModule.ts +3 -3
- package/src/protocol/ProvableBlockHook.ts +22 -0
- package/src/protocol/ProvableTransactionHook.ts +4 -1
- package/src/protocol/TransitioningProtocolModule.ts +4 -0
- package/src/prover/block/BlockProvable.ts +4 -2
- package/src/prover/block/BlockProver.ts +134 -21
- package/src/prover/block/BlockTransactionPosition.ts +34 -0
- package/src/prover/statetransition/StateTransitionProver.ts +6 -13
- package/src/prover/statetransition/StateTransitionWitnessProvider.ts +4 -5
- package/src/state/State.ts +11 -4
- package/src/state/StateServiceProvider.ts +2 -10
- package/test/Option.test.ts +64 -0
- package/test/StateTransition.test.ts +1 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +0 -11
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -12
- package/dist/utils/merkletree/MerkleTreeStore.d.ts +0 -11
- package/dist/utils/merkletree/MerkleTreeStore.d.ts.map +0 -1
- package/dist/utils/merkletree/MerkleTreeStore.js +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -132
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -251
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +0 -17
- package/src/utils/merkletree/MerkleTreeStore.ts +0 -15
- package/src/utils/merkletree/RollupMerkleTree.ts +0 -275
- package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
- package/test/utils/MerkleTree.test.ts +0 -82
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Field, Struct } from "o1js";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
export class BlockTransactionPosition extends Struct({
|
|
4
|
+
type: Field,
|
|
5
|
+
}) {
|
|
6
|
+
static fromPositionType(type) {
|
|
7
|
+
return new BlockTransactionPosition({
|
|
8
|
+
type: Field(BlockTransactionPosition.fieldMapping[type]).toConstant(),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
static positionTypeFromIndex(index, bundleLength) {
|
|
12
|
+
return match(index)
|
|
13
|
+
.with(0, () => "FIRST")
|
|
14
|
+
.with(bundleLength - 1, () => "LAST")
|
|
15
|
+
.otherwise(() => "MIDDLE");
|
|
16
|
+
}
|
|
17
|
+
equals(type) {
|
|
18
|
+
return this.type.equals(type.type);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
BlockTransactionPosition.fieldMapping = {
|
|
22
|
+
FIRST: 0,
|
|
23
|
+
MIDDLE: 1,
|
|
24
|
+
LAST: 2,
|
|
25
|
+
};
|
|
@@ -39,7 +39,7 @@ export declare class StateTransitionProverProgrammable extends ZkProgrammable<St
|
|
|
39
39
|
runBatch(publicInput: StateTransitionProverPublicInput, batch: StateTransitionProvableBatch): StateTransitionProverPublicOutput;
|
|
40
40
|
merge(publicInput: StateTransitionProverPublicInput, proof1: StateTransitionProof, proof2: StateTransitionProof): StateTransitionProverPublicOutput;
|
|
41
41
|
}
|
|
42
|
-
export declare class StateTransitionProver extends ProtocolModule
|
|
42
|
+
export declare class StateTransitionProver extends ProtocolModule implements StateTransitionProvable {
|
|
43
43
|
readonly witnessProviderReference: StateTransitionWitnessProviderReference;
|
|
44
44
|
readonly zkProgrammable: StateTransitionProverProgrammable;
|
|
45
45
|
constructor(witnessProviderReference: StateTransitionWitnessProviderReference);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,
|
|
1
|
+
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAGd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,oBAAoB,EACpB,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AAepG,UAAU,mCAAmC;IAC3C,SAAS,EAAE,KAAK,CAAC;IACjB,iBAAiB,EAAE,KAAK,CAAC;IACzB,mBAAmB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IAC/D,sBAAsB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;CACnE;AAOD;;;GAGG;AACH,qBAAa,iCAAkC,SAAQ,cAAc,CACnE,gCAAgC,EAChC,iCAAiC,CAClC;IAGG,OAAO,CAAC,QAAQ,CAAC,qBAAqB;aACtB,wBAAwB,EAAE,uCAAuC;gBADhE,qBAAqB,EAAE,qBAAqB,EAC7C,wBAAwB,EAAE,uCAAuC;IAKnF,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAEM,gBAAgB,IAAI,cAAc,CACvC,gCAAgC,EAChC,iCAAiC,CAClC;IAqDD,OAAO,KAAK,eAAe,GAM1B;IAED;;;OAGG;IACI,gBAAgB,CACrB,SAAS,EAAE,KAAK,EAChB,iBAAiB,EAAE,KAAK,EACxB,6BAA6B,EAAE,KAAK,EACpC,gCAAgC,EAAE,KAAK,EACvC,eAAe,EAAE,4BAA4B,GAC5C,mCAAmC;IA6BtC;;;OAGG;IACI,eAAe,CACpB,KAAK,EAAE,mCAAmC,EAC1C,UAAU,EAAE,uBAAuB,EACnC,IAAI,EAAE,2BAA2B,EACjC,KAAK,SAAI;IAiDX;;OAEG;IAEI,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAkB7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAqErC;AAED,qBACa,qBACX,SAAQ,cACR,YAAW,uBAAuB;aAMhB,wBAAwB,EAAE,uCAAuC;IAJnF,SAAgB,cAAc,EAAE,iCAAiC,CAAC;gBAIhD,wBAAwB,EAAE,uCAAuC;IAS5E,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAI7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAGrC"}
|
|
@@ -10,8 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
/* eslint-disable max-lines */
|
|
11
11
|
import { Experimental, Field, Provable, SelfProof } from "o1js";
|
|
12
12
|
import { injectable } from "tsyringe";
|
|
13
|
-
import { provableMethod, ZkProgrammable, } from "@proto-kit/common";
|
|
14
|
-
import { MerkleTreeUtils, RollupMerkleWitness, } from "../../utils/merkletree/RollupMerkleTree.js";
|
|
13
|
+
import { provableMethod, RollupMerkleTreeWitness, ZkProgrammable, } from "@proto-kit/common";
|
|
15
14
|
import { DefaultProvableHashList, } from "../../utils/ProvableHashList";
|
|
16
15
|
import { ProvableStateTransition } from "../../model/StateTransition";
|
|
17
16
|
import { StateTransitionProvableBatch, } from "../../model/StateTransitionProvableBatch";
|
|
@@ -107,12 +106,12 @@ export class StateTransitionProverProgrammable extends ZkProgrammable {
|
|
|
107
106
|
* and mutates it in place
|
|
108
107
|
*/
|
|
109
108
|
applyTransition(state, transition, type, index = 0) {
|
|
110
|
-
const
|
|
111
|
-
const membershipValid =
|
|
109
|
+
const witness = Provable.witness(RollupMerkleTreeWitness, () => this.witnessProvider.getWitness(transition.path));
|
|
110
|
+
const membershipValid = witness.checkMembership(state.stateRoot, transition.path, transition.from.value);
|
|
112
111
|
membershipValid
|
|
113
112
|
.or(transition.from.isSome.not())
|
|
114
113
|
.assertTrue(errors.merkleWitnessNotCorrect(index, type.isNormal().toBoolean() ? "normal" : "protocol"));
|
|
115
|
-
const newRoot =
|
|
114
|
+
const newRoot = witness.calculateRoot(transition.to.value);
|
|
116
115
|
state.stateRoot = Provable.if(transition.to.isSome, newRoot, state.stateRoot);
|
|
117
116
|
// Only update protocol state root if ST is also of type protocol
|
|
118
117
|
// Since protocol STs are all at the start of the batch, this works
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field } from "o1js";
|
|
2
|
-
import {
|
|
2
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
3
3
|
/**
|
|
4
4
|
* Interface for providing merkle witnesses to the state-transition prover
|
|
5
5
|
*/
|
|
@@ -8,9 +8,9 @@ export interface StateTransitionWitnessProvider {
|
|
|
8
8
|
* Provides the merkle witness corresponding to the given key
|
|
9
9
|
* @param key Merkle-tree key
|
|
10
10
|
*/
|
|
11
|
-
getWitness: (key: Field) =>
|
|
11
|
+
getWitness: (key: Field) => RollupMerkleTreeWitness;
|
|
12
12
|
}
|
|
13
13
|
export declare class NoOpStateTransitionWitnessProvider implements StateTransitionWitnessProvider {
|
|
14
|
-
getWitness():
|
|
14
|
+
getWitness(): RollupMerkleTreeWitness;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=StateTransitionWitnessProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionWitnessProvider.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionWitnessProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"StateTransitionWitnessProvider.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionWitnessProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,uBAAuB,CAAC;CACrD;AAED,qBACa,kCACX,YAAW,8BAA8B;IAElC,UAAU,IAAI,uBAAuB;CAG7C"}
|
|
@@ -5,10 +5,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { injectable } from "tsyringe";
|
|
8
|
-
import {
|
|
8
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
9
9
|
let NoOpStateTransitionWitnessProvider = class NoOpStateTransitionWitnessProvider {
|
|
10
10
|
getWitness() {
|
|
11
|
-
return new
|
|
11
|
+
return new RollupMerkleTreeWitness({ path: [], isLeft: [] });
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
NoOpStateTransitionWitnessProvider = __decorate([
|
package/dist/state/State.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export declare class State<Value> extends State_base {
|
|
|
28
28
|
*/
|
|
29
29
|
static from<Value>(valueType: FlexibleProvablePure<Value>): State<Value>;
|
|
30
30
|
constructor(valueType: FlexibleProvablePure<Value>);
|
|
31
|
+
/**
|
|
32
|
+
* Returns the state that is currently the current state tree
|
|
33
|
+
* value: The value-fields, or if not state was found, dummy values
|
|
34
|
+
* isSome: Whether the values where found in the state or not
|
|
35
|
+
* (Basically, whether the value-fields are dummy values or actual values
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
31
38
|
private getState;
|
|
32
39
|
/**
|
|
33
40
|
* Provides an in-circuit witness for the current state representation,
|
|
@@ -35,7 +42,7 @@ export declare class State<Value> extends State_base {
|
|
|
35
42
|
*
|
|
36
43
|
* @returns Optional value of the current state
|
|
37
44
|
*/
|
|
38
|
-
private
|
|
45
|
+
private witnessFromState;
|
|
39
46
|
/**
|
|
40
47
|
* Retrieves the current state and creates a state transition
|
|
41
48
|
* anchoring the use of the current state value in the circuit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE,OAAO,CAAC,QAAQ;IAuChB;;;;;OAKG;IACH,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAuChB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;;;OAKG;IACI,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAc3B;;;;;;;;;;OAUG;IACI,GAAG,CAAC,KAAK,EAAE,KAAK;CAiBxB"}
|
package/dist/state/State.js
CHANGED
|
@@ -36,6 +36,13 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
36
36
|
super();
|
|
37
37
|
this.valueType = valueType;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the state that is currently the current state tree
|
|
41
|
+
* value: The value-fields, or if not state was found, dummy values
|
|
42
|
+
* isSome: Whether the values where found in the state or not
|
|
43
|
+
* (Basically, whether the value-fields are dummy values or actual values
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
39
46
|
getState() {
|
|
40
47
|
this.hasStateServiceOrFail();
|
|
41
48
|
this.hasPathOrFail();
|
|
@@ -70,7 +77,7 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
70
77
|
*
|
|
71
78
|
* @returns Optional value of the current state
|
|
72
79
|
*/
|
|
73
|
-
|
|
80
|
+
witnessFromState() {
|
|
74
81
|
// get the value from storage, or return a dummy value instead
|
|
75
82
|
const value = Provable.witness(this.valueType, () => this.getState().value);
|
|
76
83
|
// check if the value exists in the storage or not
|
|
@@ -84,7 +91,7 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
84
91
|
* @returns Option representation of the current state.
|
|
85
92
|
*/
|
|
86
93
|
get() {
|
|
87
|
-
const option = this.
|
|
94
|
+
const option = this.witnessFromState();
|
|
88
95
|
this.hasPathOrFail();
|
|
89
96
|
const stateTransition = StateTransition.from(this.path, option);
|
|
90
97
|
container
|
|
@@ -105,8 +112,8 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
105
112
|
*/
|
|
106
113
|
set(value) {
|
|
107
114
|
// link the transition to the current state
|
|
108
|
-
const fromOption = this.
|
|
109
|
-
const toOption = Option.
|
|
115
|
+
const fromOption = this.witnessFromState();
|
|
116
|
+
const toOption = Option.fromValue(value, this.valueType);
|
|
110
117
|
this.hasPathOrFail();
|
|
111
118
|
const stateTransition = StateTransition.fromTo(this.path, fromOption, toOption);
|
|
112
119
|
container
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { StateService } from "./StateService";
|
|
2
2
|
export declare class StateServiceProvider {
|
|
3
|
-
private readonly baseStateService?;
|
|
4
3
|
private readonly stateServiceStack;
|
|
5
|
-
constructor(baseStateService?: StateService | undefined);
|
|
6
4
|
get stateService(): StateService;
|
|
7
5
|
setCurrentStateService(service: StateService): void;
|
|
8
6
|
popCurrentStateService(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateServiceProvider.d.ts","sourceRoot":"","sources":["../../src/state/StateServiceProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C,qBACa,oBAAoB;
|
|
1
|
+
{"version":3,"file":"StateServiceProvider.d.ts","sourceRoot":"","sources":["../../src/state/StateServiceProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C,qBACa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAsB;IAExD,IAAW,YAAY,IAAI,YAAY,CAQtC;IAEM,sBAAsB,CAAC,OAAO,EAAE,YAAY;IAI5C,sBAAsB;CAO9B"}
|
|
@@ -4,24 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { inject, injectable } from "tsyringe";
|
|
7
|
+
import { injectable } from "tsyringe";
|
|
14
8
|
import { log } from "@proto-kit/common";
|
|
15
9
|
const errors = {
|
|
16
10
|
stateServiceNotSet: () => new Error("StateService has not been set yet. Be sure to either call your runtime or protocol function by creating them with an AppChain or by setting the stateService manually."),
|
|
17
11
|
};
|
|
18
12
|
let StateServiceProvider = class StateServiceProvider {
|
|
19
|
-
constructor(
|
|
20
|
-
this.baseStateService = baseStateService;
|
|
13
|
+
constructor() {
|
|
21
14
|
this.stateServiceStack = [];
|
|
22
|
-
if (baseStateService !== undefined) {
|
|
23
|
-
this.stateServiceStack.push(baseStateService);
|
|
24
|
-
}
|
|
25
15
|
}
|
|
26
16
|
get stateService() {
|
|
27
17
|
if (this.stateServiceStack.length === 0) {
|
|
@@ -35,16 +25,14 @@ let StateServiceProvider = class StateServiceProvider {
|
|
|
35
25
|
this.stateServiceStack.push(service);
|
|
36
26
|
}
|
|
37
27
|
popCurrentStateService() {
|
|
38
|
-
if (this.stateServiceStack.length ===
|
|
39
|
-
log.trace("Trying to pop
|
|
28
|
+
if (this.stateServiceStack.length === 0) {
|
|
29
|
+
log.trace("Trying to pop from empty state-service stack");
|
|
40
30
|
return;
|
|
41
31
|
}
|
|
42
32
|
this.stateServiceStack.pop();
|
|
43
33
|
}
|
|
44
34
|
};
|
|
45
35
|
StateServiceProvider = __decorate([
|
|
46
|
-
injectable()
|
|
47
|
-
__param(0, inject("StateService")),
|
|
48
|
-
__metadata("design:paramtypes", [Object])
|
|
36
|
+
injectable()
|
|
49
37
|
], StateServiceProvider);
|
|
50
38
|
export { StateServiceProvider };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.455+b020c57",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@proto-kit/common": "*",
|
|
27
27
|
"o1js": "0.13.1",
|
|
28
|
+
"ts-pattern": "^4.3.0",
|
|
28
29
|
"tsyringe": "^4.7.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@jest/globals": "^29.5.0",
|
|
32
33
|
"@types/lodash": "^4.14.194"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b020c5717e414d3a02a842cfbe1ac19a62584dbd"
|
|
35
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKey, Struct, UInt64 } from "o1js";
|
|
2
2
|
|
|
3
3
|
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
4
4
|
import { StateMap } from "../state/StateMap";
|
|
@@ -10,7 +10,7 @@ export class AccountState extends Struct({
|
|
|
10
10
|
nonce: UInt64,
|
|
11
11
|
}) {}
|
|
12
12
|
|
|
13
|
-
export class AccountStateModule extends ProvableTransactionHook
|
|
13
|
+
export class AccountStateModule extends ProvableTransactionHook {
|
|
14
14
|
@protocolState() public accountState = StateMap.from<PublicKey, AccountState>(
|
|
15
15
|
PublicKey,
|
|
16
16
|
AccountState
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Provable } from "o1js";
|
|
2
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
3
|
+
import {
|
|
4
|
+
AfterBlockParameters,
|
|
5
|
+
BeforeBlockParameters,
|
|
6
|
+
ProvableBlockHook,
|
|
7
|
+
} from "../protocol/ProvableBlockHook";
|
|
8
|
+
|
|
9
|
+
export class BlockHeightHook extends ProvableBlockHook<Record<string, never>> {
|
|
10
|
+
public afterBlock({ networkState }: AfterBlockParameters): NetworkState {
|
|
11
|
+
Provable.log("afterBlock", networkState);
|
|
12
|
+
return new NetworkState({
|
|
13
|
+
block: {
|
|
14
|
+
height: networkState.block.height.add(1),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
|
|
20
|
+
return blockData.networkState;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterBlockParameters,
|
|
3
|
+
BeforeBlockParameters,
|
|
4
|
+
ProvableBlockHook
|
|
5
|
+
} from "../protocol/ProvableBlockHook";
|
|
6
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
7
|
+
|
|
8
|
+
export class NoopBlockHook extends ProvableBlockHook<Record<string, never>>{
|
|
9
|
+
public afterBlock(blockData: AfterBlockParameters): NetworkState {
|
|
10
|
+
return blockData.networkState;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
|
|
14
|
+
return blockData.networkState;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
2
2
|
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
3
3
|
|
|
4
|
-
export class NoopTransactionHook extends ProvableTransactionHook
|
|
5
|
-
public onTransaction(executionData: BlockProverExecutionData): void {
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
export class NoopTransactionHook extends ProvableTransactionHook {
|
|
5
|
+
public onTransaction(executionData: BlockProverExecutionData): void {}
|
|
6
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./blockmodules/AccountStateModule";
|
|
2
|
+
export * from "./blockmodules/BlockHeightHook";
|
|
2
3
|
export * from "./utils/ProvableHashList";
|
|
3
4
|
export * from "./model/StateTransition";
|
|
4
5
|
export * from "./model/StateTransitionProvableBatch";
|
|
@@ -11,18 +12,17 @@ export * from "./utils/PrefixedProvableHashList.js";
|
|
|
11
12
|
export * from "./utils/utils";
|
|
12
13
|
export * from "./prover/block/BlockProver";
|
|
13
14
|
export * from "./prover/block/BlockProvable";
|
|
15
|
+
export * from "./prover/block/BlockTransactionPosition";
|
|
14
16
|
export * from "./prover/statetransition/StateTransitionProver";
|
|
15
17
|
export * from "./prover/statetransition/StateTransitionProvable";
|
|
16
18
|
export * from "./prover/statetransition/StateTransitionWitnessProvider";
|
|
17
|
-
export * from "./utils/merkletree/MerkleTreeStore";
|
|
18
|
-
export * from "./utils/merkletree/InMemoryMerkleTreeStorage";
|
|
19
|
-
export * from "./utils/merkletree/RollupMerkleTree";
|
|
20
19
|
export * from "./model/MethodPublicOutput";
|
|
21
20
|
export * from "./prover/statetransition/StateTransitionWitnessProviderReference";
|
|
22
21
|
export * from "./protocol/Protocol";
|
|
23
22
|
export * from "./protocol/ProtocolModule";
|
|
24
|
-
export * from "./protocol/
|
|
23
|
+
export * from "./protocol/ProtocolEnvironment";
|
|
25
24
|
export * from "./protocol/ProvableTransactionHook";
|
|
25
|
+
export * from "./protocol/ProvableBlockHook";
|
|
26
26
|
export * from "./state/context/ProtocolMethodExecutionContext";
|
|
27
27
|
export * from "./state/context/TransitionMethodExecutionContext";
|
|
28
28
|
export * from "./state/context/RuntimeMethodExecutionContext";
|
package/src/model/Option.ts
CHANGED
|
@@ -17,10 +17,67 @@ export class ProvableOption extends Struct({
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export abstract class OptionBase {
|
|
21
|
+
protected constructor(public isSome: Bool, public isForcedSome: Bool) {}
|
|
22
|
+
|
|
23
|
+
protected abstract encodeValueToFields(): Field[];
|
|
24
|
+
|
|
25
|
+
protected abstract clone(): OptionBase;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns Tree representation of the current value
|
|
29
|
+
*/
|
|
30
|
+
public get treeValue() {
|
|
31
|
+
const treeValue = Poseidon.hash(this.encodeValueToFields());
|
|
32
|
+
|
|
33
|
+
return Provable.if(
|
|
34
|
+
this.isSome.and(this.isForcedSome.not()),
|
|
35
|
+
treeValue,
|
|
36
|
+
Field(0)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public forceSome() {
|
|
41
|
+
this.isForcedSome = Provable.if(this.isSome, Bool(false), Bool(true));
|
|
42
|
+
this.isSome = Bool(true);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the `to`-value as decoded as a list of fields
|
|
47
|
+
* Not in circuit
|
|
48
|
+
*/
|
|
49
|
+
public toFields(): Field[] {
|
|
50
|
+
if (this.isSome.toBoolean()) {
|
|
51
|
+
return this.encodeValueToFields();
|
|
52
|
+
}
|
|
53
|
+
return [Field(0)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @returns Provable representation of the current option.
|
|
58
|
+
*/
|
|
59
|
+
public toProvable() {
|
|
60
|
+
return new ProvableOption({
|
|
61
|
+
isSome: this.isSome,
|
|
62
|
+
value: this.treeValue,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public toJSON() {
|
|
67
|
+
const value = this.encodeValueToFields().map((field) => field.toString());
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
isSome: this.isSome.toBoolean(),
|
|
71
|
+
isForcedSome: this.isForcedSome.toBoolean(),
|
|
72
|
+
value,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
20
77
|
/**
|
|
21
78
|
* Option facilitating in-circuit values that may or may not exist.
|
|
22
79
|
*/
|
|
23
|
-
export class Option<Value> {
|
|
80
|
+
export class Option<Value> extends OptionBase {
|
|
24
81
|
/**
|
|
25
82
|
* Creates a new Option from the provided parameters
|
|
26
83
|
*
|
|
@@ -58,57 +115,28 @@ export class Option<Value> {
|
|
|
58
115
|
return new Option(Bool(false), Field(0), Field);
|
|
59
116
|
}
|
|
60
117
|
|
|
61
|
-
public isForcedSome = Bool(false);
|
|
62
|
-
|
|
63
118
|
public constructor(
|
|
64
|
-
|
|
119
|
+
isSome: Bool,
|
|
65
120
|
public value: Value,
|
|
66
|
-
public valueType: FlexibleProvablePure<Value
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return new Option(this.isSome, this.value, this.valueType);
|
|
121
|
+
public valueType: FlexibleProvablePure<Value>,
|
|
122
|
+
isForcedSome = Bool(false)
|
|
123
|
+
) {
|
|
124
|
+
super(isSome, isForcedSome);
|
|
71
125
|
}
|
|
72
126
|
|
|
73
|
-
public
|
|
74
|
-
this.
|
|
75
|
-
this.isSome = Bool(true);
|
|
127
|
+
public encodeValueToFields(): Field[] {
|
|
128
|
+
return this.valueType.toFields(this.value);
|
|
76
129
|
}
|
|
77
130
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return Provable.if(
|
|
85
|
-
this.isSome.and(this.isForcedSome.not()),
|
|
86
|
-
treeValue,
|
|
87
|
-
Field(0)
|
|
131
|
+
public clone(): Option<Value> {
|
|
132
|
+
return new Option(
|
|
133
|
+
this.isSome,
|
|
134
|
+
this.value,
|
|
135
|
+
this.valueType,
|
|
136
|
+
this.isForcedSome
|
|
88
137
|
);
|
|
89
138
|
}
|
|
90
139
|
|
|
91
|
-
/**
|
|
92
|
-
* Returns the `to`-value as decoded as a list of fields
|
|
93
|
-
* Not in circuit
|
|
94
|
-
*/
|
|
95
|
-
public toFields(): Field[] {
|
|
96
|
-
if (this.isSome.toBoolean()) {
|
|
97
|
-
return this.valueType.toFields(this.value);
|
|
98
|
-
}
|
|
99
|
-
return [Field(0)];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @returns Provable representation of the current option.
|
|
104
|
-
*/
|
|
105
|
-
public toProvable() {
|
|
106
|
-
return new ProvableOption({
|
|
107
|
-
isSome: this.isSome,
|
|
108
|
-
value: this.treeValue,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
140
|
/**
|
|
113
141
|
* @returns Returns the value of this option if it isSome,
|
|
114
142
|
* otherwise returns the given defaultValue
|
|
@@ -121,17 +149,4 @@ export class Option<Value> {
|
|
|
121
149
|
defaultValue
|
|
122
150
|
);
|
|
123
151
|
}
|
|
124
|
-
|
|
125
|
-
public toJSON() {
|
|
126
|
-
const valueContent = this.valueType
|
|
127
|
-
.toFields(this.value)
|
|
128
|
-
.map((field) => field.toString())
|
|
129
|
-
.reduce((a, b) => `${a}, ${b}`);
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
isSome: this.isSome.toBoolean(),
|
|
133
|
-
|
|
134
|
-
value: `[${valueContent}]`,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
152
|
}
|