@proto-kit/protocol 0.1.1-develop.456 → 0.1.1-develop.600

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.
Files changed (98) hide show
  1. package/dist/blockmodules/AccountStateModule.d.ts.map +1 -1
  2. package/dist/blockmodules/AccountStateModule.js +10 -3
  3. package/dist/blockmodules/BlockHeightHook.d.ts +3 -3
  4. package/dist/blockmodules/BlockHeightHook.d.ts.map +1 -1
  5. package/dist/blockmodules/BlockHeightHook.js +5 -6
  6. package/dist/blockmodules/LastStateRootBlockHook.d.ts +8 -0
  7. package/dist/blockmodules/LastStateRootBlockHook.d.ts.map +1 -0
  8. package/dist/blockmodules/LastStateRootBlockHook.js +15 -0
  9. package/dist/blockmodules/NoopBlockHook.d.ts +6 -4
  10. package/dist/blockmodules/NoopBlockHook.d.ts.map +1 -1
  11. package/dist/blockmodules/NoopBlockHook.js +4 -4
  12. package/dist/blockmodules/NoopSettlementHook.d.ts +6 -0
  13. package/dist/blockmodules/NoopSettlementHook.d.ts.map +1 -0
  14. package/dist/blockmodules/NoopSettlementHook.js +18 -0
  15. package/dist/hooks/AccountStateHook.d.ts.map +1 -1
  16. package/dist/hooks/AccountStateHook.js +7 -2
  17. package/dist/hooks/BlockHeightHook.d.ts.map +1 -1
  18. package/dist/index.d.ts +9 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +9 -3
  21. package/dist/model/MethodPublicOutput.d.ts +8 -0
  22. package/dist/model/MethodPublicOutput.d.ts.map +1 -1
  23. package/dist/model/MethodPublicOutput.js +1 -0
  24. package/dist/model/network/NetworkState.d.ts +40 -0
  25. package/dist/model/network/NetworkState.d.ts.map +1 -1
  26. package/dist/model/network/NetworkState.js +14 -2
  27. package/dist/model/transaction/RuntimeTransaction.d.ts +45 -20
  28. package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
  29. package/dist/model/transaction/RuntimeTransaction.js +68 -11
  30. package/dist/model/transaction/SignedTransaction.d.ts +71 -0
  31. package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
  32. package/dist/model/transaction/SignedTransaction.js +33 -0
  33. package/dist/model/transaction/ValueOption.d.ts +119 -0
  34. package/dist/model/transaction/ValueOption.d.ts.map +1 -0
  35. package/dist/model/transaction/ValueOption.js +24 -0
  36. package/dist/protocol/Protocol.d.ts +7 -3
  37. package/dist/protocol/Protocol.d.ts.map +1 -1
  38. package/dist/protocol/Protocol.js +26 -16
  39. package/dist/protocol/ProvableBlockHook.d.ts +2 -10
  40. package/dist/protocol/ProvableBlockHook.d.ts.map +1 -1
  41. package/dist/protocol/ProvableBlockHook.js +1 -1
  42. package/dist/protocol/ProvableTransactionHook.d.ts +1 -1
  43. package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
  44. package/dist/protocol/TransitioningProtocolModule.d.ts +3 -2
  45. package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
  46. package/dist/protocol/TransitioningProtocolModule.js +3 -2
  47. package/dist/prover/block/BlockProvable.d.ts +106 -28
  48. package/dist/prover/block/BlockProvable.d.ts.map +1 -1
  49. package/dist/prover/block/BlockProvable.js +23 -5
  50. package/dist/prover/block/BlockProver.d.ts +29 -8
  51. package/dist/prover/block/BlockProver.d.ts.map +1 -1
  52. package/dist/prover/block/BlockProver.js +241 -77
  53. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +45 -0
  54. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
  55. package/dist/prover/block/accummulators/BlockHashMerkleTree.js +16 -0
  56. package/dist/settlement/ProvableSettlementHook.d.ts +26 -0
  57. package/dist/settlement/ProvableSettlementHook.d.ts.map +1 -0
  58. package/dist/settlement/ProvableSettlementHook.js +3 -0
  59. package/dist/settlement/SettlementContract.d.ts +230 -0
  60. package/dist/settlement/SettlementContract.d.ts.map +1 -0
  61. package/dist/settlement/SettlementContract.js +346 -0
  62. package/dist/settlement/modules/NetworkStateSettlementModule.d.ts +11 -0
  63. package/dist/settlement/modules/NetworkStateSettlementModule.d.ts.map +1 -0
  64. package/dist/settlement/modules/NetworkStateSettlementModule.js +12 -0
  65. package/dist/state/context/RuntimeMethodExecutionContext.d.ts +75 -1
  66. package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
  67. package/dist/state/context/RuntimeMethodExecutionContext.js +19 -1
  68. package/dist/utils/MinaPrefixedProvableHashList.d.ts +24 -0
  69. package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
  70. package/dist/utils/MinaPrefixedProvableHashList.js +51 -0
  71. package/package.json +2 -2
  72. package/src/blockmodules/AccountStateModule.ts +17 -6
  73. package/src/blockmodules/BlockHeightHook.ts +5 -8
  74. package/src/blockmodules/LastStateRootBlockHook.ts +26 -0
  75. package/src/blockmodules/NoopBlockHook.ts +15 -11
  76. package/src/blockmodules/NoopSettlementHook.ts +21 -0
  77. package/src/blockmodules/SequenceStateTransactionModule.ts +25 -0
  78. package/src/index.ts +9 -3
  79. package/src/model/MethodPublicOutput.ts +3 -2
  80. package/src/model/network/NetworkState.ts +15 -3
  81. package/src/model/transaction/RuntimeTransaction.ts +90 -16
  82. package/src/model/transaction/SignedTransaction.ts +54 -0
  83. package/src/model/transaction/ValueOption.ts +28 -0
  84. package/src/protocol/Protocol.ts +49 -31
  85. package/src/protocol/ProvableBlockHook.ts +10 -13
  86. package/src/protocol/ProvableTransactionHook.ts +2 -1
  87. package/src/protocol/TransitioningProtocolModule.ts +3 -2
  88. package/src/prover/block/BlockProvable.ts +39 -6
  89. package/src/prover/block/BlockProver.ts +473 -143
  90. package/src/prover/block/accummulators/BlockHashMerkleTree.ts +16 -0
  91. package/src/settlement/ProvableSettlementHook.ts +37 -0
  92. package/src/settlement/SettlementContract.ts +444 -0
  93. package/src/settlement/modules/NetworkStateSettlementModule.ts +39 -0
  94. package/src/state/context/RuntimeMethodExecutionContext.ts +18 -1
  95. package/src/utils/MinaPrefixedProvableHashList.ts +72 -0
  96. package/test/BlockProver.test.ts +2 -3
  97. package/src/model/transaction/ProtocolTransaction.ts +0 -25
  98. package/src/prover/block/BlockTransactionPosition.ts +0 -34
@@ -1,4 +1,4 @@
1
- import { Bool } from "o1js";
1
+ import { Bool, Provable } from "o1js";
2
2
  import { ProvableMethodExecutionContext, ProvableMethodExecutionResult } from "@proto-kit/common";
3
3
  import { StateTransition } from "../../model/StateTransition";
4
4
  import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
@@ -12,6 +12,78 @@ export interface RuntimeMethodExecutionData {
12
12
  transaction: RuntimeTransaction;
13
13
  networkState: NetworkState;
14
14
  }
15
+ declare const RuntimeMethodExecutionDataStruct_base: (new (value: {
16
+ transaction: RuntimeTransaction;
17
+ networkState: NetworkState;
18
+ }) => {
19
+ transaction: RuntimeTransaction;
20
+ networkState: NetworkState;
21
+ }) & {
22
+ _isStruct: true;
23
+ } & Provable<{
24
+ transaction: RuntimeTransaction;
25
+ networkState: NetworkState;
26
+ }> & {
27
+ toInput: (x: {
28
+ transaction: RuntimeTransaction;
29
+ networkState: NetworkState;
30
+ }) => {
31
+ fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
32
+ packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
33
+ };
34
+ toJSON: (x: {
35
+ transaction: RuntimeTransaction;
36
+ networkState: NetworkState;
37
+ }) => {
38
+ transaction: {
39
+ methodId: string;
40
+ argsHash: string;
41
+ nonce: {
42
+ isSome: boolean;
43
+ value: any;
44
+ };
45
+ sender: {
46
+ isSome: boolean;
47
+ value: any;
48
+ };
49
+ };
50
+ networkState: {
51
+ block: {
52
+ height: string;
53
+ };
54
+ previous: {
55
+ rootHash: string;
56
+ };
57
+ };
58
+ };
59
+ fromJSON: (x: {
60
+ transaction: {
61
+ methodId: string;
62
+ argsHash: string;
63
+ nonce: {
64
+ isSome: boolean;
65
+ value: any;
66
+ };
67
+ sender: {
68
+ isSome: boolean;
69
+ value: any;
70
+ };
71
+ };
72
+ networkState: {
73
+ block: {
74
+ height: string;
75
+ };
76
+ previous: {
77
+ rootHash: string;
78
+ };
79
+ };
80
+ }) => {
81
+ transaction: RuntimeTransaction;
82
+ networkState: NetworkState;
83
+ };
84
+ };
85
+ export declare class RuntimeMethodExecutionDataStruct extends RuntimeMethodExecutionDataStruct_base {
86
+ }
15
87
  /**
16
88
  * Execution context used to wrap runtime module methods,
17
89
  * allowing them to post relevant information (such as execution status)
@@ -41,6 +113,7 @@ export declare class RuntimeMethodExecutionContext extends ProvableMethodExecuti
41
113
  * @param input Input witness data required for a runtime execution
42
114
  */
43
115
  setup(input: RuntimeMethodExecutionData): void;
116
+ witnessInput(): RuntimeMethodExecutionDataStruct;
44
117
  setSimulated(simulated: boolean): void;
45
118
  /**
46
119
  * Manually clears/resets the execution context
@@ -58,4 +131,5 @@ export declare class RuntimeMethodExecutionContext extends ProvableMethodExecuti
58
131
  isSimulated: boolean;
59
132
  };
60
133
  }
134
+ export {};
61
135
  //# sourceMappingURL=RuntimeMethodExecutionContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimeMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/state/context/RuntimeMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,qBAAa,oCAAqC,SAAQ,6BAA6B;IAE9E,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBACa,6BAA8B,SAAQ,8BAA8B;IACxE,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,KAAK,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGrD,OAAO,CAAC,SAAS,CAAyC;IAE1C,MAAM,uCAA8C;IAEpE,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAKxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAQxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAQ7B;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,0BAA0B;IAIvC,YAAY,CAAC,SAAS,EAAE,OAAO;IAItC;;OAEG;IACI,KAAK;IAIL,WAAW;IASlB;;;OAGG;IACI,OAAO;;;;;;CAQf"}
1
+ {"version":3,"file":"RuntimeMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/state/context/RuntimeMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAU,MAAM,MAAM,CAAC;AAE9C,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,qBAAa,oCAAqC,SAAQ,6BAA6B;IAE9E,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,qBAAa,gCAAiC,SAAQ,qCAGpD;CAAG;AAEL;;;;GAIG;AACH,qBACa,6BAA8B,SAAQ,8BAA8B;IACxE,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,KAAK,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGrD,OAAO,CAAC,SAAS,CAAyC;IAE1C,MAAM,uCAA8C;IAEpE,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAKxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAQxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAQ7B;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,0BAA0B;IAIvC,YAAY,IAAI,gCAAgC;IAYhD,YAAY,CAAC,SAAS,EAAE,OAAO;IAItC;;OAEG;IACI,KAAK;IAIL,WAAW;IASlB;;;OAGG;IACI,OAAO;;;;;;CAQf"}
@@ -4,9 +4,11 @@ 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
- import { Bool } from "o1js";
7
+ import { Bool, Provable, Struct } from "o1js";
8
8
  import { singleton } from "tsyringe";
9
9
  import { ProvableMethodExecutionContext, ProvableMethodExecutionResult, } from "@proto-kit/common";
10
+ import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
11
+ import { NetworkState } from "../../model/network/NetworkState";
10
12
  const errors = {
11
13
  setupNotCalled: () => new Error("Setup has not been called prior to executing a runtime method. Be sure to do that so that the Runtime is setup property for execution"),
12
14
  };
@@ -18,6 +20,11 @@ export class RuntimeProvableMethodExecutionResult extends ProvableMethodExecutio
18
20
  this.status = Bool(true);
19
21
  }
20
22
  }
23
+ export class RuntimeMethodExecutionDataStruct extends Struct({
24
+ transaction: RuntimeTransaction,
25
+ networkState: NetworkState,
26
+ }) {
27
+ }
21
28
  /**
22
29
  * Execution context used to wrap runtime module methods,
23
30
  * allowing them to post relevant information (such as execution status)
@@ -70,6 +77,17 @@ let RuntimeMethodExecutionContext = class RuntimeMethodExecutionContext extends
70
77
  setup(input) {
71
78
  this.input = input;
72
79
  }
80
+ witnessInput() {
81
+ this.assertSetupCalled();
82
+ return Provable.witness(RuntimeMethodExecutionDataStruct, () => {
83
+ // TODO Is that right? Or this.current().input
84
+ const { transaction, networkState } = this.input;
85
+ return new RuntimeMethodExecutionDataStruct({
86
+ networkState,
87
+ transaction,
88
+ });
89
+ });
90
+ }
73
91
  setSimulated(simulated) {
74
92
  this.isSimulated = simulated;
75
93
  }
@@ -0,0 +1,24 @@
1
+ import { Field, FlexibleProvablePure } from "o1js";
2
+ import { ProvableHashList } from "./ProvableHashList";
3
+ export declare const MINA_EVENT_PREFIXES: {
4
+ readonly event: "MinaZkappEvent******";
5
+ readonly events: "MinaZkappEvents*****";
6
+ readonly sequenceEvents: "MinaZkappSeqEvents**";
7
+ };
8
+ export declare function emptyActions(): Field;
9
+ export declare function emptyEvents(): Field;
10
+ export declare class MinaActions {
11
+ static actionHash(action: Field[], previousHash?: Field): Field;
12
+ }
13
+ export declare class MinaEvents {
14
+ static eventHash(event: Field[], previousHash?: Field): Field;
15
+ }
16
+ export declare class MinaPrefixedProvableHashList<Value> extends ProvableHashList<Value> {
17
+ readonly prefix: string;
18
+ constructor(valueType: FlexibleProvablePure<Value>, prefix: string, internalCommitment?: Field);
19
+ protected hash(elements: Field[]): Field;
20
+ }
21
+ export declare class MinaActionsHashList extends MinaPrefixedProvableHashList<Field> {
22
+ constructor(internalCommitment?: Field);
23
+ }
24
+ //# sourceMappingURL=MinaPrefixedProvableHashList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MinaPrefixedProvableHashList.d.ts","sourceRoot":"","sources":["../../src/utils/MinaPrefixedProvableHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAY,MAAM,MAAM,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,eAAO,MAAM,mBAAmB;;;;CAItB,CAAC;AAEX,wBAAgB,YAAY,IAAI,KAAK,CAEpC;AAED,wBAAgB,WAAW,IAAI,KAAK,CAEnC;AAED,qBAAa,WAAW;IACtB,MAAM,CAAC,UAAU,CACf,MAAM,EAAE,KAAK,EAAE,EACf,YAAY,GAAE,KAAsB,GACnC,KAAK;CAOT;AAED,qBAAa,UAAU;IACrB,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,YAAY,GAAE,KAAqB,GAAG,KAAK;CAO7E;AAED,qBAAa,4BAA4B,CACvC,KAAK,CACL,SAAQ,gBAAgB,CAAC,KAAK,CAAC;aAGb,MAAM,EAAE,MAAM;gBAD9B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACtB,MAAM,EAAE,MAAM,EAC9B,kBAAkB,GAAE,KAAgB;IAKtC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;CAKzC;AAED,qBAAa,mBAAoB,SAAQ,4BAA4B,CAAC,KAAK,CAAC;gBACvD,kBAAkB,GAAE,KAAgB;CAGxD"}
@@ -0,0 +1,51 @@
1
+ import { Field, Poseidon } from "o1js";
2
+ import { hashWithPrefix, prefixToField } from "@proto-kit/common";
3
+ import { ProvableHashList } from "./ProvableHashList";
4
+ function salt(prefix) {
5
+ return Poseidon.update([Field(0), Field(0), Field(0)], [prefixToField(prefix)]);
6
+ }
7
+ export const MINA_EVENT_PREFIXES = {
8
+ event: "MinaZkappEvent******",
9
+ events: "MinaZkappEvents*****",
10
+ sequenceEvents: "MinaZkappSeqEvents**",
11
+ };
12
+ export function emptyActions() {
13
+ return salt("MinaZkappActionsEmpty")[0];
14
+ }
15
+ export function emptyEvents() {
16
+ return salt("MinaZkappEventsEmpty")[0];
17
+ }
18
+ export class MinaActions {
19
+ static actionHash(action, previousHash = emptyActions()) {
20
+ const actionDataHash = hashWithPrefix(MINA_EVENT_PREFIXES.event, action);
21
+ return hashWithPrefix(MINA_EVENT_PREFIXES.sequenceEvents, [
22
+ previousHash,
23
+ actionDataHash,
24
+ ]);
25
+ }
26
+ }
27
+ export class MinaEvents {
28
+ static eventHash(event, previousHash = emptyEvents()) {
29
+ const actionDataHash = hashWithPrefix(MINA_EVENT_PREFIXES.event, event);
30
+ return hashWithPrefix(MINA_EVENT_PREFIXES.events, [
31
+ previousHash,
32
+ actionDataHash,
33
+ ]);
34
+ }
35
+ }
36
+ export class MinaPrefixedProvableHashList extends ProvableHashList {
37
+ constructor(valueType, prefix, internalCommitment = Field(0)) {
38
+ super(valueType, internalCommitment);
39
+ this.prefix = prefix;
40
+ }
41
+ hash(elements) {
42
+ const init = salt(this.prefix);
43
+ const digest = Poseidon.update(init, elements);
44
+ return digest[0];
45
+ }
46
+ }
47
+ export class MinaActionsHashList extends MinaPrefixedProvableHashList {
48
+ constructor(internalCommitment = Field(0)) {
49
+ super(Field, MINA_EVENT_PREFIXES.sequenceEvents, internalCommitment);
50
+ }
51
+ }
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.456+bdb345d",
6
+ "version": "0.1.1-develop.600+699a7df",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
9
9
  "dev": "tsc -p tsconfig.json --watch",
@@ -32,5 +32,5 @@
32
32
  "@jest/globals": "^29.5.0",
33
33
  "@types/lodash": "^4.14.194"
34
34
  },
35
- "gitHead": "bdb345d9e6132387a870c8a4236d8fe295502ce4"
35
+ "gitHead": "699a7dfa3b5d3415ab4500f0cd495d6781365c6a"
36
36
  }
@@ -1,4 +1,4 @@
1
- import { PublicKey, Struct, UInt64 } from "o1js";
1
+ import { Provable, PublicKey, Struct, UInt64 } from "o1js";
2
2
 
3
3
  import { BlockProverExecutionData } from "../prover/block/BlockProvable";
4
4
  import { StateMap } from "../state/StateMap";
@@ -17,17 +17,28 @@ export class AccountStateModule extends ProvableTransactionHook {
17
17
  );
18
18
 
19
19
  public onTransaction({ transaction }: BlockProverExecutionData): void {
20
+ const sender = transaction.sender.value;
21
+
20
22
  const accountState = this.accountState
21
- .get(transaction.sender)
23
+ .get(sender)
22
24
  .orElse(new AccountState({ nonce: UInt64.zero }));
23
25
 
24
26
  const currentNonce = accountState.nonce;
25
27
 
26
- assert(currentNonce.equals(transaction.nonce), "Nonce not matching");
28
+ // Either the nonce matches or the tx is a message, in which case we don't care
29
+ assert(
30
+ currentNonce
31
+ .equals(transaction.nonce.value)
32
+ .or(transaction.sender.isSome.not()),
33
+ "Nonce not matching"
34
+ );
27
35
 
28
- this.accountState.set(
29
- transaction.sender,
30
- new AccountState({ nonce: currentNonce.add(1) })
36
+ // Optimized version of transaction.sender.isSome ? currentNonce.add(1) : Field(0)
37
+ // Bcs Bool(true).toField() == 1
38
+ const newNonce = UInt64.from(
39
+ currentNonce.value.add(1).mul(transaction.sender.isSome.toField())
31
40
  );
41
+
42
+ this.accountState.set(sender, new AccountState({ nonce: newNonce }));
32
43
  }
33
44
  }
@@ -1,21 +1,18 @@
1
1
  import { Provable } from "o1js";
2
2
  import { NetworkState } from "../model/network/NetworkState";
3
- import {
4
- AfterBlockParameters,
5
- BeforeBlockParameters,
6
- ProvableBlockHook,
7
- } from "../protocol/ProvableBlockHook";
3
+ import { ProvableBlockHook } from "../protocol/ProvableBlockHook";
8
4
 
9
5
  export class BlockHeightHook extends ProvableBlockHook<Record<string, never>> {
10
- public afterBlock({ networkState }: AfterBlockParameters): NetworkState {
6
+ public afterBlock(networkState: NetworkState): NetworkState {
11
7
  return new NetworkState({
12
8
  block: {
13
9
  height: networkState.block.height.add(1),
14
10
  },
11
+ previous: networkState.previous
15
12
  });
16
13
  }
17
14
 
18
- public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
19
- return blockData.networkState;
15
+ public beforeBlock(networkState: NetworkState): NetworkState {
16
+ return networkState;
20
17
  }
21
18
  }
@@ -0,0 +1,26 @@
1
+ import { ProvableBlockHook } from "../protocol/ProvableBlockHook";
2
+ import { NetworkState } from "../model/network/NetworkState";
3
+ import { BlockProverState } from "../prover/block/BlockProver";
4
+
5
+ export class LastStateRootBlockHook extends ProvableBlockHook<
6
+ Record<string, never>
7
+ > {
8
+ public afterBlock(
9
+ networkState: NetworkState,
10
+ state: BlockProverState
11
+ ): NetworkState {
12
+ return new NetworkState({
13
+ block: networkState.block,
14
+ previous: {
15
+ rootHash: state.stateRoot,
16
+ },
17
+ });
18
+ }
19
+
20
+ public beforeBlock(
21
+ networkState: NetworkState,
22
+ state: BlockProverState
23
+ ): NetworkState {
24
+ return networkState;
25
+ }
26
+ }
@@ -1,16 +1,20 @@
1
- import {
2
- AfterBlockParameters,
3
- BeforeBlockParameters,
4
- ProvableBlockHook
5
- } from "../protocol/ProvableBlockHook";
1
+ import { ProvableBlockHook } from "../protocol/ProvableBlockHook";
6
2
  import { NetworkState } from "../model/network/NetworkState";
3
+ import { BlockProverState } from "../prover/block/BlockProver";
4
+ import { NoConfig } from "@proto-kit/common";
7
5
 
8
- export class NoopBlockHook extends ProvableBlockHook<Record<string, never>>{
9
- public afterBlock(blockData: AfterBlockParameters): NetworkState {
10
- return blockData.networkState;
6
+ export class NoopBlockHook extends ProvableBlockHook<NoConfig> {
7
+ public afterBlock(
8
+ networkState: NetworkState,
9
+ state: BlockProverState
10
+ ): NetworkState {
11
+ return networkState;
11
12
  }
12
13
 
13
- public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
14
- return blockData.networkState;
14
+ public beforeBlock(
15
+ networkState: NetworkState,
16
+ state: BlockProverState
17
+ ): NetworkState {
18
+ return networkState;
15
19
  }
16
- }
20
+ }
@@ -0,0 +1,21 @@
1
+ import { injectable } from "tsyringe";
2
+ import { noop } from "@proto-kit/common";
3
+ import { SmartContract } from "o1js";
4
+
5
+ import { BlockProof } from "../prover/block/BlockProver";
6
+ import {
7
+ ProvableSettlementHook,
8
+ SettlementHookInputs,
9
+ } from "../settlement/ProvableSettlementHook";
10
+
11
+ @injectable()
12
+ export class NoopSettlementHook extends ProvableSettlementHook<
13
+ Record<string, never>
14
+ > {
15
+ public beforeSettlement(
16
+ contract: SmartContract,
17
+ state: SettlementHookInputs
18
+ ): void {
19
+ noop();
20
+ }
21
+ }
@@ -0,0 +1,25 @@
1
+ import { Field } from "o1js";
2
+
3
+ import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
4
+ import { BlockProverExecutionData } from "../prover/block/BlockProvable";
5
+ import { protocolState } from "../state/protocol/ProtocolState";
6
+ import { State } from "../state/State";
7
+ import { DefaultProvableHashList } from "../utils/ProvableHashList";
8
+ import { SignedTransaction } from "../model/transaction/SignedTransaction";
9
+
10
+ // Future idea to add this functionality as a module
11
+ // This is currently hardcoded in tracing however
12
+ class SequenceStateTransactionModule extends ProvableTransactionHook {
13
+ @protocolState() sequenceStateTransactionsList = State.from(Field);
14
+
15
+ public onTransaction(executionData: BlockProverExecutionData): void {
16
+ const hashList = new DefaultProvableHashList(
17
+ SignedTransaction,
18
+ this.sequenceStateTransactionsList.get().orElse(Field(0))
19
+ );
20
+
21
+ hashList.push(executionData.transaction);
22
+
23
+ this.sequenceStateTransactionsList.set(hashList.commitment);
24
+ }
25
+ }
package/src/index.ts CHANGED
@@ -1,18 +1,21 @@
1
1
  export * from "./blockmodules/AccountStateModule";
2
2
  export * from "./blockmodules/BlockHeightHook";
3
+ export * from "./blockmodules/LastStateRootBlockHook";
3
4
  export * from "./utils/ProvableHashList";
4
5
  export * from "./model/StateTransition";
5
6
  export * from "./model/StateTransitionProvableBatch";
6
7
  export * from "./model/Option";
7
8
  export * from "./model/Path";
8
9
  export * from "./model/network/NetworkState";
9
- export * from "./model/transaction/ProtocolTransaction";
10
+ export * from "./model/transaction/SignedTransaction";
10
11
  export * from "./model/transaction/RuntimeTransaction";
11
- export * from "./utils/PrefixedProvableHashList.js";
12
+ export * from "./model/transaction/ValueOption";
13
+ export * from "./utils/PrefixedProvableHashList";
14
+ export * from "./utils/MinaPrefixedProvableHashList";
12
15
  export * from "./utils/utils";
13
16
  export * from "./prover/block/BlockProver";
14
17
  export * from "./prover/block/BlockProvable";
15
- export * from "./prover/block/BlockTransactionPosition";
18
+ export * from "./prover/block/accummulators/BlockHashMerkleTree";
16
19
  export * from "./prover/statetransition/StateTransitionProver";
17
20
  export * from "./prover/statetransition/StateTransitionProvable";
18
21
  export * from "./prover/statetransition/StateTransitionWitnessProvider";
@@ -32,4 +35,7 @@ export * from "./state/StateMap";
32
35
  export * from "./state/StateService";
33
36
  export * from "./state/StateServiceProvider";
34
37
  export * from "./state/assert/assert";
38
+ export * from "./settlement/SettlementContract";
39
+ export * from "./settlement/ProvableSettlementHook";
40
+ export * from "./settlement/modules/NetworkStateSettlementModule";
35
41
  export { constants as ProtocolConstants } from "./Constants";
@@ -1,4 +1,4 @@
1
- import { Bool, Field, Struct } from "o1js";
1
+ import { Bool, Field, Signature, Struct } from "o1js";
2
2
 
3
3
  /**
4
4
  * Public input used to link in-circuit execution with
@@ -9,4 +9,5 @@ export class MethodPublicOutput extends Struct({
9
9
  status: Bool,
10
10
  transactionHash: Field,
11
11
  networkStateHash: Field,
12
- }) {}
12
+ isMessage: Bool,
13
+ }) {}
@@ -1,21 +1,33 @@
1
1
  import { Field, Poseidon, Struct, UInt64 } from "o1js";
2
+ import { RollupMerkleTree } from "@proto-kit/common";
2
3
 
3
4
  export class CurrentBlock extends Struct({
4
5
  height: UInt64,
5
6
  }) {}
6
7
 
8
+ export class PreviousBlock extends Struct({
9
+ rootHash: Field,
10
+ }) {}
11
+
7
12
  export class NetworkState extends Struct({
8
13
  block: CurrentBlock,
14
+ previous: PreviousBlock,
9
15
  }) {
10
16
  public hash(): Field {
11
- return Poseidon.hash(CurrentBlock.toFields(this.block));
17
+ return Poseidon.hash([
18
+ ...CurrentBlock.toFields(this.block),
19
+ ...PreviousBlock.toFields(this.previous),
20
+ ]);
12
21
  }
13
22
 
14
- public static empty(){
23
+ public static empty() {
15
24
  return new NetworkState({
16
25
  block: {
17
26
  height: UInt64.zero,
18
27
  },
19
- })
28
+ previous: {
29
+ rootHash: Field(RollupMerkleTree.EMPTY_ROOT)
30
+ }
31
+ });
20
32
  }
21
33
  }
@@ -1,6 +1,14 @@
1
- import { Field, Poseidon, PublicKey, Struct, UInt64 } from "o1js";
2
-
3
- import { ProtocolTransaction } from "./ProtocolTransaction";
1
+ import {
2
+ Bool,
3
+ Field,
4
+ Poseidon,
5
+ Provable,
6
+ PublicKey,
7
+ Struct,
8
+ UInt64,
9
+ } from "o1js";
10
+ import { PublicKeyOption, UInt64Option } from "./ValueOption";
11
+ import { EMPTY_PUBLICKEY, EMPTY_PUBLICKEY_X } from "@proto-kit/common";
4
12
 
5
13
  /**
6
14
  * This struct is used to expose transaction information to the runtime method
@@ -9,30 +17,96 @@ import { ProtocolTransaction } from "./ProtocolTransaction";
9
17
  */
10
18
  export class RuntimeTransaction extends Struct({
11
19
  methodId: Field,
12
- nonce: UInt64,
13
- sender: PublicKey,
14
20
  argsHash: Field,
21
+ nonce: UInt64Option,
22
+ sender: PublicKeyOption,
15
23
  }) {
16
- public static fromProtocolTransaction({
24
+ public static fromTransaction(input: {
25
+ methodId: Field;
26
+ argsHash: Field;
27
+ nonce: UInt64;
28
+ sender: PublicKey;
29
+ }) {
30
+ return new RuntimeTransaction({
31
+ methodId: input.methodId,
32
+ argsHash: input.argsHash,
33
+ nonce: UInt64Option.fromValue(input.nonce),
34
+ sender: PublicKeyOption.fromValue(input.sender),
35
+ });
36
+ }
37
+
38
+ public static fromMessage({
17
39
  methodId,
18
- nonce,
19
- sender,
20
40
  argsHash,
21
- }: ProtocolTransaction): RuntimeTransaction {
41
+ }: {
42
+ methodId: Field;
43
+ argsHash: Field;
44
+ }) {
22
45
  return new RuntimeTransaction({
23
46
  methodId,
24
- nonce,
25
- sender,
26
47
  argsHash,
48
+ nonce: UInt64Option.none(UInt64.zero),
49
+ sender: PublicKeyOption.none(EMPTY_PUBLICKEY),
27
50
  });
28
51
  }
29
52
 
30
- public hash(): Field {
31
- return Poseidon.hash([
53
+ public static dummyTransaction(): RuntimeTransaction {
54
+ return new RuntimeTransaction({
55
+ methodId: Field(0),
56
+ nonce: new UInt64Option({
57
+ isSome: Bool(true),
58
+ value: UInt64.zero,
59
+ }),
60
+ sender: new PublicKeyOption({
61
+ isSome: Bool(true),
62
+ value: EMPTY_PUBLICKEY,
63
+ }),
64
+ argsHash: Field(0),
65
+ });
66
+ }
67
+
68
+ public assertTransactionType(isMessage: Bool) {
69
+ const isTransaction = isMessage.not();
70
+ // isSome has to be true when it is a transaction, otherwise false
71
+ this.nonce.isSome
72
+ .equals(isTransaction)
73
+ .assertTrue("Nonce is not right option isSome for type");
74
+ this.sender.isSome
75
+ .equals(isTransaction)
76
+ .assertTrue("Sender is not right option isSome for type");
77
+ this.sender.value.x
78
+ .equals(EMPTY_PUBLICKEY_X)
79
+ .equals(isMessage)
80
+ .assertTrue("Transaction sender is not set to dummy");
81
+ }
82
+
83
+ public hashData(): Field[] {
84
+ return [
32
85
  this.methodId,
33
- ...this.sender.toFields(),
34
- ...this.nonce.toFields(),
86
+ ...this.sender.value.toFields(),
87
+ ...this.nonce.value.toFields(),
35
88
  this.argsHash,
36
- ]);
89
+ ];
90
+ }
91
+
92
+ public static fromHashData(fields: Field[]) {
93
+ // sender is 2nd and the first element is x (2nd isOdd)
94
+ const isMessage = fields[1].equals(EMPTY_PUBLICKEY_X);
95
+ return new RuntimeTransaction({
96
+ methodId: fields[0],
97
+ sender: new PublicKeyOption({
98
+ isSome: isMessage.not(),
99
+ value: PublicKey.fromFields([fields[1], fields[2]]),
100
+ }),
101
+ nonce: new UInt64Option({
102
+ isSome: isMessage.not(),
103
+ value: UInt64.fromFields([fields[3]]),
104
+ }),
105
+ argsHash: fields[4],
106
+ });
107
+ }
108
+
109
+ public hash(): Field {
110
+ return Poseidon.hash(this.hashData());
37
111
  }
38
112
  }