@proto-kit/protocol 0.1.1-develop.165 → 0.1.1-develop.1665
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/Constants.js +1 -0
- package/dist/Constants.js.map +1 -0
- package/dist/hashing/mina-prefixes.d.ts +10 -0
- package/dist/hashing/mina-prefixes.d.ts.map +1 -0
- package/dist/hashing/mina-prefixes.js +10 -0
- package/dist/hashing/mina-prefixes.js.map +1 -0
- package/dist/hashing/protokit-prefixes.d.ts +10 -0
- package/dist/hashing/protokit-prefixes.d.ts.map +1 -0
- package/dist/hashing/protokit-prefixes.js +24 -0
- package/dist/hashing/protokit-prefixes.js.map +1 -0
- package/dist/hooks/AccountStateHook.d.ts +52 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -0
- package/dist/hooks/AccountStateHook.js +52 -0
- package/dist/hooks/AccountStateHook.js.map +1 -0
- package/dist/hooks/BlockHeightHook.d.ts +7 -0
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -0
- package/dist/hooks/BlockHeightHook.js +16 -0
- package/dist/hooks/BlockHeightHook.js.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts +7 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.js +16 -0
- package/dist/hooks/LastStateRootBlockHook.js.map +1 -0
- package/dist/hooks/NoopBlockHook.d.ts +8 -0
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -0
- package/dist/hooks/NoopBlockHook.js +10 -0
- package/dist/hooks/NoopBlockHook.js.map +1 -0
- package/dist/hooks/NoopSettlementHook.d.ts +6 -0
- package/dist/hooks/NoopSettlementHook.d.ts.map +1 -0
- package/dist/{prover/statetransition/StateTransitionWitnessProvider.js → hooks/NoopSettlementHook.js} +8 -7
- package/dist/hooks/NoopSettlementHook.js.map +1 -0
- package/dist/hooks/NoopTransactionHook.d.ts +6 -0
- package/dist/hooks/NoopTransactionHook.d.ts.map +1 -0
- package/dist/hooks/NoopTransactionHook.js +11 -0
- package/dist/hooks/NoopTransactionHook.js.map +1 -0
- package/dist/index.d.ts +51 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -9
- package/dist/index.js.map +1 -0
- package/dist/model/AppliedStateTransitionBatch.d.ts +114 -0
- package/dist/model/AppliedStateTransitionBatch.d.ts.map +1 -0
- package/dist/model/AppliedStateTransitionBatch.js +16 -0
- package/dist/model/AppliedStateTransitionBatch.js.map +1 -0
- package/dist/model/MethodPublicOutput.d.ts +83 -29
- package/dist/model/MethodPublicOutput.d.ts.map +1 -1
- package/dist/model/MethodPublicOutput.js +4 -1
- package/dist/model/MethodPublicOutput.js.map +1 -0
- package/dist/model/Option.d.ts +70 -42
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +62 -47
- package/dist/model/Option.js.map +1 -0
- package/dist/model/Path.d.ts +4 -3
- package/dist/model/Path.d.ts.map +1 -1
- package/dist/model/Path.js +6 -5
- package/dist/model/Path.js.map +1 -0
- package/dist/model/RuntimeLike.d.ts +11 -0
- package/dist/model/RuntimeLike.d.ts.map +1 -0
- package/dist/model/RuntimeLike.js +2 -0
- package/dist/model/RuntimeLike.js.map +1 -0
- package/dist/model/StateTransition.d.ts +67 -16
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +18 -2
- package/dist/model/StateTransition.js.map +1 -0
- package/dist/model/StateTransitionProvableBatch.d.ts +389 -16
- package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
- package/dist/model/StateTransitionProvableBatch.js +88 -11
- package/dist/model/StateTransitionProvableBatch.js.map +1 -0
- package/dist/model/network/NetworkState.d.ts +105 -9
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +20 -2
- package/dist/model/network/NetworkState.js.map +1 -0
- package/dist/model/transaction/RuntimeTransaction.d.ts +96 -28
- package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
- package/dist/model/transaction/RuntimeTransaction.js +75 -11
- package/dist/model/transaction/RuntimeTransaction.js.map +1 -0
- package/dist/model/transaction/SignedTransaction.d.ts +107 -0
- package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
- package/dist/model/transaction/SignedTransaction.js +34 -0
- package/dist/model/transaction/SignedTransaction.js.map +1 -0
- package/dist/model/transaction/ValueOption.d.ts +173 -0
- package/dist/model/transaction/ValueOption.d.ts.map +1 -0
- package/dist/model/transaction/ValueOption.js +25 -0
- package/dist/model/transaction/ValueOption.js.map +1 -0
- package/dist/protocol/Protocol.d.ts +27 -25
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +98 -28
- package/dist/protocol/Protocol.js.map +1 -0
- package/dist/protocol/ProtocolEnvironment.d.ts +9 -0
- package/dist/protocol/ProtocolEnvironment.d.ts.map +1 -0
- package/dist/protocol/ProtocolEnvironment.js +2 -0
- package/dist/protocol/ProtocolEnvironment.js.map +1 -0
- package/dist/protocol/ProtocolModule.d.ts +7 -7
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +10 -7
- package/dist/protocol/ProtocolModule.js.map +1 -0
- package/dist/protocol/ProvableBlockHook.d.ts +19 -0
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
- package/dist/protocol/ProvableBlockHook.js +21 -0
- package/dist/protocol/ProvableBlockHook.js.map +1 -0
- package/dist/protocol/ProvableTransactionHook.d.ts +34 -0
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -0
- package/dist/protocol/ProvableTransactionHook.js +13 -0
- package/dist/protocol/ProvableTransactionHook.js.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts +10 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.js +9 -0
- package/dist/protocol/TransitioningProtocolModule.js.map +1 -0
- package/dist/prover/accumulators/AppliedBatchHashList.d.ts +18 -0
- package/dist/prover/accumulators/AppliedBatchHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/AppliedBatchHashList.js +25 -0
- package/dist/prover/accumulators/AppliedBatchHashList.js.map +1 -0
- package/dist/prover/accumulators/StateTransitionReductionList.d.ts +12 -0
- package/dist/prover/accumulators/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/prover/accumulators/StateTransitionReductionList.js +64 -0
- package/dist/prover/accumulators/StateTransitionReductionList.js.map +1 -0
- package/dist/prover/accumulators/TransactionHashList.d.ts +6 -0
- package/dist/prover/accumulators/TransactionHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/TransactionHashList.js +8 -0
- package/dist/prover/accumulators/TransactionHashList.js.map +1 -0
- package/dist/prover/accumulators/WitnessedRootHashList.d.ts +137 -0
- package/dist/prover/accumulators/WitnessedRootHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js +50 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js.map +1 -0
- package/dist/prover/block/BlockProvable.d.ts +869 -65
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +86 -6
- package/dist/prover/block/BlockProvable.js.map +1 -0
- package/dist/prover/block/BlockProver.d.ts +82 -34
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +505 -86
- package/dist/prover/block/BlockProver.js.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +106 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js +25 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js.map +1 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts +139 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js +21 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js.map +1 -0
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts +7 -0
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts.map +1 -0
- package/dist/prover/{statetransition/StateTransitionWitnessProviderReference.js → block/services/RuntimeVerificationKeyRootService.js} +11 -8
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.js.map +1 -0
- package/dist/prover/statetransition/StateTransitionProvable.d.ts +137 -48
- package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProvable.js +10 -5
- package/dist/prover/statetransition/StateTransitionProvable.js.map +1 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +30 -17
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +169 -74
- package/dist/prover/statetransition/StateTransitionProver.js.map +1 -0
- package/dist/settlement/ContractModule.d.ts +16 -0
- package/dist/settlement/ContractModule.d.ts.map +1 -0
- package/dist/settlement/ContractModule.js +12 -0
- package/dist/settlement/ContractModule.js.map +1 -0
- package/dist/settlement/SettlementContractModule.d.ts +51 -0
- package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/SettlementContractModule.js +80 -0
- package/dist/settlement/SettlementContractModule.js.map +1 -0
- package/dist/settlement/contracts/BridgeContract.d.ts +116 -0
- package/dist/settlement/contracts/BridgeContract.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContract.js +259 -0
- package/dist/settlement/contracts/BridgeContract.js.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts +16 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js +41 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +21 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js +57 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts +44 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.js +229 -0
- package/dist/settlement/contracts/DispatchSmartContract.js.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts +21 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js +84 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts +123 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.js +310 -0
- package/dist/settlement/contracts/SettlementSmartContract.js.map +1 -0
- package/dist/settlement/contracts/TokenBridgeTree.d.ts +228 -0
- package/dist/settlement/contracts/TokenBridgeTree.d.ts.map +1 -0
- package/dist/settlement/contracts/TokenBridgeTree.js +60 -0
- package/dist/settlement/contracts/TokenBridgeTree.js.map +1 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts +10 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.js +2 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.js.map +1 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts +85 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js +11 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js.map +1 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts +79 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js +11 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js.map +1 -0
- package/dist/settlement/messages/Deposit.d.ts +77 -0
- package/dist/settlement/messages/Deposit.d.ts.map +1 -0
- package/dist/settlement/messages/Deposit.js +8 -0
- package/dist/settlement/messages/Deposit.js.map +1 -0
- package/dist/settlement/messages/OutgoingMessage.d.ts +67 -0
- package/dist/settlement/messages/OutgoingMessage.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessage.js +7 -0
- package/dist/settlement/messages/OutgoingMessage.js.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts +462 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js +40 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js.map +1 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts +25 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts.map +1 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.js +30 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.js.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts +26 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js +4 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js.map +1 -0
- package/dist/settlement/modularity/types.d.ts +8 -0
- package/dist/settlement/modularity/types.d.ts.map +1 -0
- package/dist/settlement/modularity/types.js +2 -0
- package/dist/settlement/modularity/types.js.map +1 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts +11 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts.map +1 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.js +15 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.js.map +1 -0
- package/dist/state/State.d.ts +68 -0
- package/dist/state/State.d.ts.map +1 -0
- package/dist/state/State.js +131 -0
- package/dist/state/State.js.map +1 -0
- package/dist/state/StateMap.d.ts +37 -0
- package/dist/state/StateMap.d.ts.map +1 -0
- package/dist/state/StateMap.js +56 -0
- package/dist/state/StateMap.js.map +1 -0
- package/dist/state/StateService.d.ts +6 -0
- package/dist/state/StateService.d.ts.map +1 -0
- package/dist/state/StateService.js +2 -0
- package/dist/state/StateService.js.map +1 -0
- package/dist/state/StateServiceProvider.d.ts +8 -0
- package/dist/state/StateServiceProvider.d.ts.map +1 -0
- package/dist/state/StateServiceProvider.js +37 -0
- package/dist/state/StateServiceProvider.js.map +1 -0
- package/dist/state/assert/assert.d.ts +12 -0
- package/dist/state/assert/assert.d.ts.map +1 -0
- package/dist/state/assert/assert.js +33 -0
- package/dist/state/assert/assert.js.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +193 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.js +138 -0
- package/dist/state/context/RuntimeMethodExecutionContext.js.map +1 -0
- package/dist/state/context/TransitionMethodExecutionContext.d.ts +23 -0
- package/dist/state/context/TransitionMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/TransitionMethodExecutionContext.js +6 -0
- package/dist/state/context/TransitionMethodExecutionContext.js.map +1 -0
- package/dist/state/protocol/ProtocolState.d.ts +13 -0
- package/dist/state/protocol/ProtocolState.d.ts.map +1 -0
- package/dist/state/protocol/ProtocolState.js +58 -0
- package/dist/state/protocol/ProtocolState.js.map +1 -0
- package/dist/utils/FieldOptions.d.ts +62 -0
- package/dist/utils/FieldOptions.d.ts.map +1 -0
- package/dist/utils/FieldOptions.js +13 -0
- package/dist/utils/FieldOptions.js.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts +19 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.js +46 -0
- package/dist/utils/MinaPrefixedProvableHashList.js.map +1 -0
- package/dist/utils/PrefixedProvableHashList.d.ts +2 -2
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/PrefixedProvableHashList.js +2 -1
- package/dist/utils/PrefixedProvableHashList.js.map +1 -0
- package/dist/utils/ProvableHashList.d.ts +23 -4
- package/dist/utils/ProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableHashList.js +38 -2
- package/dist/utils/ProvableHashList.js.map +1 -0
- package/dist/utils/ProvableReductionHashList.d.ts +18 -0
- package/dist/utils/ProvableReductionHashList.d.ts.map +1 -0
- package/dist/utils/ProvableReductionHashList.js +54 -0
- package/dist/utils/ProvableReductionHashList.js.map +1 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +51 -0
- package/dist/utils/utils.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +11 -9
- package/src/hashing/mina-prefixes.ts +10 -0
- package/src/hashing/protokit-prefixes.ts +37 -0
- package/src/hooks/AccountStateHook.ts +57 -0
- package/src/hooks/BlockHeightHook.ts +17 -0
- package/src/hooks/LastStateRootBlockHook.ts +25 -0
- package/src/hooks/NoopBlockHook.ts +24 -0
- package/src/hooks/NoopSettlementHook.ts +20 -0
- package/src/hooks/NoopTransactionHook.ts +13 -0
- package/src/index.ts +51 -9
- package/src/model/AppliedStateTransitionBatch.ts +16 -0
- package/src/model/MethodPublicOutput.ts +3 -1
- package/src/model/Option.ts +99 -60
- package/src/model/Path.ts +9 -5
- package/src/model/RuntimeLike.ts +12 -0
- package/src/model/StateTransition.ts +25 -3
- package/src/model/StateTransitionProvableBatch.ts +117 -14
- package/src/model/Transaction.ts +3 -1
- package/src/model/network/NetworkState.ts +21 -3
- package/src/model/transaction/RuntimeTransaction.ts +90 -15
- package/src/model/transaction/SignedTransaction.ts +47 -0
- package/src/model/transaction/ValueOption.ts +28 -0
- package/src/protocol/Protocol.ts +166 -74
- package/src/protocol/ProtocolEnvironment.ts +10 -0
- package/src/protocol/ProtocolModule.ts +16 -16
- package/src/protocol/ProvableBlockHook.ts +68 -0
- package/src/protocol/ProvableTransactionHook.ts +77 -0
- package/src/protocol/TransitioningProtocolModule.ts +12 -0
- package/src/prover/accumulators/AppliedBatchHashList.ts +32 -0
- package/src/prover/accumulators/StateTransitionReductionList.ts +92 -0
- package/src/prover/accumulators/TransactionHashList.ts +9 -0
- package/src/prover/accumulators/WitnessedRootHashList.ts +61 -0
- package/src/prover/block/BlockProvable.ts +188 -15
- package/src/prover/block/BlockProver.ts +979 -143
- package/src/prover/block/accummulators/BlockHashMerkleTree.ts +24 -0
- package/src/prover/block/accummulators/RuntimeVerificationKeyTree.ts +24 -0
- package/src/prover/block/services/RuntimeVerificationKeyRootService.ts +20 -0
- package/src/prover/statetransition/StateTransitionProvable.ts +26 -19
- package/src/prover/statetransition/StateTransitionProver.ts +338 -130
- package/src/settlement/ContractModule.ts +31 -0
- package/src/settlement/SettlementContractModule.ts +145 -0
- package/src/settlement/contracts/BridgeContract.ts +366 -0
- package/src/settlement/contracts/BridgeContractProtocolModule.ts +48 -0
- package/src/settlement/contracts/DispatchContractProtocolModule.ts +75 -0
- package/src/settlement/contracts/DispatchSmartContract.ts +325 -0
- package/src/settlement/contracts/SettlementContractProtocolModule.ts +113 -0
- package/src/settlement/contracts/SettlementSmartContract.ts +502 -0
- package/src/settlement/contracts/TokenBridgeTree.ts +73 -0
- package/src/settlement/contracts/authorizations/ContractAuthorization.ts +11 -0
- package/src/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.ts +16 -0
- package/src/settlement/contracts/authorizations/UpdateMessagesHashAuth.ts +16 -0
- package/src/settlement/messages/Deposit.ts +7 -0
- package/src/settlement/messages/OutgoingMessage.ts +17 -0
- package/src/settlement/messages/OutgoingMessageArgument.ts +53 -0
- package/src/settlement/modularity/OutgoingMessageProcessor.ts +65 -0
- package/src/settlement/modularity/ProvableSettlementHook.ts +36 -0
- package/src/settlement/modularity/types.ts +22 -0
- package/src/settlement/modules/NetworkStateSettlementModule.ts +42 -0
- package/src/state/State.ts +177 -0
- package/src/state/StateMap.ts +73 -0
- package/src/state/StateService.ts +6 -0
- package/src/state/StateServiceProvider.ts +37 -0
- package/src/state/assert/assert.ts +38 -0
- package/src/state/context/RuntimeMethodExecutionContext.ts +181 -0
- package/src/state/context/TransitionMethodExecutionContext.ts +26 -0
- package/src/state/protocol/ProtocolState.ts +98 -0
- package/src/utils/FieldOptions.ts +13 -0
- package/src/utils/MinaPrefixedProvableHashList.ts +66 -0
- package/src/utils/PrefixedProvableHashList.ts +2 -2
- package/src/utils/ProvableHashList.ts +78 -3
- package/src/utils/ProvableReductionHashList.ts +77 -0
- package/src/utils/utils.ts +44 -55
- package/test/BlockProver.test.ts +161 -74
- package/test/Protocol.test.ts +20 -10
- package/test/State.test.ts +45 -0
- package/test/StateTransition.test.ts +57 -65
- package/test/TestingProtocol.ts +56 -0
- package/test/compiling/types.ts +28 -0
- package/test/model/Option.test.ts +72 -0
- package/test/model/StateTransitionProvableBatch.test.ts +137 -0
- package/test/modularity/types.ts +35 -0
- package/test/prover/block/BlockProver.test.ts +18 -0
- package/test/prover/statetransition/StateTransitionProver.test.ts +261 -0
- package/test/state/assert/assert.test.ts +56 -0
- package/test/tsconfig.json +7 -0
- package/test/utils/ProvableHashList.test.ts +44 -0
- package/test/utils/ProvableReductionHashList.test.ts +117 -0
- package/test/utils.test.ts +27 -0
- package/dist/config/ConfigurableModule.d.ts +0 -18
- package/dist/config/ConfigurableModule.d.ts.map +0 -1
- package/dist/config/ConfigurableModule.js +0 -20
- package/dist/config/ConfigurationAggregator.d.ts +0 -10
- package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
- package/dist/config/ConfigurationAggregator.js +0 -35
- package/dist/config/ConfigurationReceiver.d.ts +0 -25
- package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
- package/dist/config/ConfigurationReceiver.js +0 -36
- package/dist/config/ModuleContainer.d.ts +0 -44
- package/dist/config/ModuleContainer.d.ts.map +0 -1
- package/dist/config/ModuleContainer.js +0 -89
- package/dist/config/types.d.ts +0 -2
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/model/MethodPublicInput.d.ts +0 -51
- package/dist/model/MethodPublicInput.d.ts.map +0 -1
- package/dist/model/MethodPublicInput.js +0 -11
- package/dist/model/transaction/ProtocolTransaction.d.ts +0 -70
- package/dist/model/transaction/ProtocolTransaction.d.ts.map +0 -1
- package/dist/model/transaction/ProtocolTransaction.js +0 -18
- package/dist/prover/block/BlockScopedModule.d.ts +0 -3
- package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
- package/dist/prover/block/BlockScopedModule.js +0 -6
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts +0 -7
- package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts.map +0 -1
- package/dist/src/model/Option.d.ts +0 -158
- package/dist/src/model/Option.d.ts.map +0 -1
- package/dist/src/model/Option.js +0 -53
- package/dist/src/model/Path.d.ts +0 -35
- package/dist/src/model/Path.d.ts.map +0 -1
- package/dist/src/model/Path.js +0 -51
- package/dist/src/model/StateTransition.d.ts +0 -201
- package/dist/src/model/StateTransition.d.ts.map +0 -1
- package/dist/src/model/StateTransition.js +0 -43
- package/dist/src/utils/PrefixedHashList.d.ts +0 -15
- package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/src/utils/PrefixedHashList.js +0 -28
- package/dist/src/utils/ProvableHashList.d.ts +0 -30
- package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/src/utils/ProvableHashList.js +0 -43
- package/dist/utils/PrefixedHashList.d.ts +0 -14
- package/dist/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedHashList.js +0 -12
- package/dist/utils/Utils.d.ts +0 -17
- package/dist/utils/Utils.d.ts.map +0 -1
- package/dist/utils/Utils.js +0 -64
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +0 -25
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -77
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
- 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 -130
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -244
- package/src/model/Option.test.ts +0 -21
- package/src/model/transaction/ProtocolTransaction.ts +0 -25
- package/src/prover/statetransition/StateTransitionWitnessProvider.ts +0 -24
- package/src/prover/statetransition/StateTransitionWitnessProviderReference.ts +0 -17
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +0 -106
- package/src/utils/merkletree/MerkleTreeStore.ts +0 -15
- package/src/utils/merkletree/RollupMerkleTree.ts +0 -250
- package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
- package/tsconfig.test.json +0 -9
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
import { Experimental, Field, Provable, SelfProof } from "snarkyjs";
|
|
2
|
-
import { inject, injectable } from "tsyringe";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
MerkleTreeUtils,
|
|
6
|
-
RollupMerkleWitness,
|
|
7
|
-
} from "../../utils/merkletree/RollupMerkleTree.js";
|
|
8
|
-
import {
|
|
9
|
-
DefaultProvableHashList,
|
|
10
|
-
ProvableHashList,
|
|
11
|
-
} from "../../utils/ProvableHashList";
|
|
12
|
-
import { ProvableStateTransition } from "../../model/StateTransition";
|
|
13
|
-
import { StateTransitionProvableBatch } from "../../model/StateTransitionProvableBatch";
|
|
14
|
-
import { constants } from "../../Constants";
|
|
15
|
-
|
|
16
|
-
import { StateTransitionWitnessProvider } from "./StateTransitionWitnessProvider.js";
|
|
17
1
|
import {
|
|
18
2
|
AreProofsEnabled,
|
|
19
3
|
PlainZkProgram,
|
|
20
4
|
provableMethod,
|
|
5
|
+
ZkProgrammable,
|
|
6
|
+
CompilableModule,
|
|
7
|
+
type ArtifactRecord,
|
|
8
|
+
type CompileRegistry,
|
|
9
|
+
TreeWrite,
|
|
10
|
+
LinkedMerkleTreeCircuitOps,
|
|
11
|
+
LinkedMerkleTreeWitness,
|
|
21
12
|
} from "@proto-kit/common";
|
|
13
|
+
import { Field, Provable, SelfProof, ZkProgram } from "o1js";
|
|
14
|
+
import { injectable } from "tsyringe";
|
|
15
|
+
|
|
16
|
+
import { constants } from "../../Constants";
|
|
17
|
+
import { ProvableStateTransition } from "../../model/StateTransition";
|
|
22
18
|
import {
|
|
19
|
+
MerkleWitnessBatch,
|
|
20
|
+
StateTransitionProvableBatch,
|
|
21
|
+
StateTransitionType,
|
|
22
|
+
} from "../../model/StateTransitionProvableBatch";
|
|
23
|
+
import { StateTransitionProverType } from "../../protocol/Protocol";
|
|
24
|
+
import { ProtocolModule } from "../../protocol/ProtocolModule";
|
|
25
|
+
import { DefaultProvableHashList } from "../../utils/ProvableHashList";
|
|
26
|
+
import { WitnessedRootHashList } from "../accumulators/WitnessedRootHashList";
|
|
27
|
+
import { AppliedBatchHashList } from "../accumulators/AppliedBatchHashList";
|
|
28
|
+
import { AppliedStateTransitionBatchState } from "../../model/AppliedStateTransitionBatch";
|
|
29
|
+
|
|
30
|
+
import {
|
|
31
|
+
StateTransitionProof,
|
|
23
32
|
StateTransitionProvable,
|
|
24
33
|
StateTransitionProverPublicInput,
|
|
25
|
-
StateTransitionProof,
|
|
26
34
|
StateTransitionProverPublicOutput,
|
|
27
35
|
} from "./StateTransitionProvable";
|
|
28
|
-
import { ProtocolModule } from "../../protocol/ProtocolModule";
|
|
29
|
-
import { StateTransitionWitnessProviderReference } from "./StateTransitionWitnessProviderReference";
|
|
30
36
|
|
|
31
37
|
const errors = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
stateTransitionsHashNotMatching: (step: string) =>
|
|
35
|
-
`State transitions hash not matching ${step}`,
|
|
38
|
+
propertyNotMatching: (property: string, step: string) =>
|
|
39
|
+
`${property} not matching ${step}`,
|
|
36
40
|
|
|
37
41
|
merkleWitnessNotCorrect: (index: number) =>
|
|
38
42
|
`MerkleWitness not valid for StateTransition (${index})`,
|
|
39
|
-
|
|
40
|
-
noWitnessProviderSet: () =>
|
|
41
|
-
new Error(
|
|
42
|
-
"WitnessProvider not set, set it before you use StateTransitionProvider"
|
|
43
|
-
),
|
|
44
|
-
|
|
45
|
-
propertyNotMatching: (propertyName: string) => `${propertyName} not matching`,
|
|
46
43
|
};
|
|
47
44
|
|
|
48
45
|
interface StateTransitionProverExecutionState {
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
currentBatch: AppliedStateTransitionBatchState;
|
|
47
|
+
batchList: AppliedBatchHashList;
|
|
48
|
+
finalizedRoot: Field;
|
|
49
|
+
witnessedRoots: WitnessedRootHashList;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
const StateTransitionSelfProofClass = SelfProof<
|
|
@@ -59,40 +58,54 @@ const StateTransitionSelfProofClass = SelfProof<
|
|
|
59
58
|
* StateTransitionProver is the prover that proves the application of some state
|
|
60
59
|
* transitions and checks and updates their merkle-tree entries
|
|
61
60
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
StateTransitionProverPublicOutput
|
|
67
|
-
>
|
|
68
|
-
implements StateTransitionProvable
|
|
69
|
-
{
|
|
61
|
+
export class StateTransitionProverProgrammable extends ZkProgrammable<
|
|
62
|
+
StateTransitionProverPublicInput,
|
|
63
|
+
StateTransitionProverPublicOutput
|
|
64
|
+
> {
|
|
70
65
|
public constructor(
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
private readonly stateTransitionProver: Pick<
|
|
67
|
+
StateTransitionProver,
|
|
68
|
+
"areProofsEnabled"
|
|
69
|
+
>
|
|
73
70
|
) {
|
|
74
71
|
super();
|
|
75
72
|
}
|
|
76
73
|
|
|
74
|
+
public get areProofsEnabled(): AreProofsEnabled | undefined {
|
|
75
|
+
return this.stateTransitionProver.areProofsEnabled;
|
|
76
|
+
}
|
|
77
|
+
|
|
77
78
|
public zkProgramFactory(): PlainZkProgram<
|
|
78
79
|
StateTransitionProverPublicInput,
|
|
79
80
|
StateTransitionProverPublicOutput
|
|
80
|
-
> {
|
|
81
|
+
>[] {
|
|
81
82
|
const instance = this;
|
|
82
83
|
|
|
83
|
-
const program =
|
|
84
|
+
const program = ZkProgram({
|
|
85
|
+
name: "StateTransitionProver",
|
|
84
86
|
publicInput: StateTransitionProverPublicInput,
|
|
85
87
|
publicOutput: StateTransitionProverPublicOutput,
|
|
86
88
|
|
|
87
89
|
methods: {
|
|
88
90
|
proveBatch: {
|
|
89
|
-
privateInputs: [
|
|
91
|
+
privateInputs: [
|
|
92
|
+
StateTransitionProvableBatch,
|
|
93
|
+
MerkleWitnessBatch,
|
|
94
|
+
AppliedStateTransitionBatchState,
|
|
95
|
+
],
|
|
90
96
|
|
|
91
|
-
method(
|
|
97
|
+
async method(
|
|
92
98
|
publicInput: StateTransitionProverPublicInput,
|
|
93
|
-
batch: StateTransitionProvableBatch
|
|
99
|
+
batch: StateTransitionProvableBatch,
|
|
100
|
+
witnesses: MerkleWitnessBatch,
|
|
101
|
+
currentAppliedBatch: AppliedStateTransitionBatchState
|
|
94
102
|
) {
|
|
95
|
-
return instance.
|
|
103
|
+
return await instance.proveBatch(
|
|
104
|
+
publicInput,
|
|
105
|
+
batch,
|
|
106
|
+
witnesses,
|
|
107
|
+
currentAppliedBatch
|
|
108
|
+
);
|
|
96
109
|
},
|
|
97
110
|
},
|
|
98
111
|
|
|
@@ -102,12 +115,12 @@ export class StateTransitionProver
|
|
|
102
115
|
StateTransitionSelfProofClass,
|
|
103
116
|
],
|
|
104
117
|
|
|
105
|
-
method(
|
|
118
|
+
async method(
|
|
106
119
|
publicInput: StateTransitionProverPublicInput,
|
|
107
120
|
proof1: StateTransitionProof,
|
|
108
121
|
proof2: StateTransitionProof
|
|
109
122
|
) {
|
|
110
|
-
return instance.merge(publicInput, proof1, proof2);
|
|
123
|
+
return await instance.merge(publicInput, proof1, proof2);
|
|
111
124
|
},
|
|
112
125
|
},
|
|
113
126
|
},
|
|
@@ -118,22 +131,39 @@ export class StateTransitionProver
|
|
|
118
131
|
merge: program.merge.bind(program),
|
|
119
132
|
};
|
|
120
133
|
|
|
121
|
-
const SelfProofClass =
|
|
134
|
+
const SelfProofClass = ZkProgram.Proof(program);
|
|
122
135
|
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
name: program.name,
|
|
139
|
+
compile: program.compile.bind(program),
|
|
140
|
+
verify: program.verify.bind(program),
|
|
141
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
142
|
+
Proof: SelfProofClass,
|
|
143
|
+
methods,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
129
146
|
}
|
|
130
147
|
|
|
131
|
-
private
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
private transitionToTreeWrite(
|
|
149
|
+
st: ProvableStateTransition,
|
|
150
|
+
witness: LinkedMerkleTreeWitness
|
|
151
|
+
): TreeWrite {
|
|
152
|
+
// If from isSome isn't set, the user "ignored the previous value", i.e. we
|
|
153
|
+
// can assume the value in the witness is correct
|
|
154
|
+
const from = Provable.if(
|
|
155
|
+
st.from.isSome,
|
|
156
|
+
st.from.value,
|
|
157
|
+
witness.leafCurrent.leaf.value
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// If the user doesn't want to write, we just carry over the from-value
|
|
161
|
+
const to = Provable.if(st.to.isSome, st.to.value, from);
|
|
162
|
+
return {
|
|
163
|
+
path: st.path,
|
|
164
|
+
from,
|
|
165
|
+
to,
|
|
166
|
+
};
|
|
137
167
|
}
|
|
138
168
|
|
|
139
169
|
/**
|
|
@@ -141,26 +171,94 @@ export class StateTransitionProver
|
|
|
141
171
|
* and returns the new prover state
|
|
142
172
|
*/
|
|
143
173
|
public applyTransitions(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
const
|
|
149
|
-
stateRoot,
|
|
150
|
-
|
|
151
|
-
stateTransitionList: new DefaultProvableHashList(
|
|
152
|
-
ProvableStateTransition,
|
|
153
|
-
stateTransitionCommitmentFrom
|
|
154
|
-
),
|
|
155
|
-
};
|
|
174
|
+
state: StateTransitionProverExecutionState,
|
|
175
|
+
batch: StateTransitionProvableBatch,
|
|
176
|
+
witnesses: MerkleWitnessBatch
|
|
177
|
+
) {
|
|
178
|
+
const transitions = batch.batch;
|
|
156
179
|
|
|
157
|
-
const transitions = transitionBatch.batch;
|
|
158
180
|
for (
|
|
159
181
|
let index = 0;
|
|
160
182
|
index < constants.stateTransitionProverBatchSize;
|
|
161
183
|
index++
|
|
162
184
|
) {
|
|
163
|
-
this.applyTransition(
|
|
185
|
+
const updatedBatchState = this.applyTransition(
|
|
186
|
+
state.currentBatch,
|
|
187
|
+
transitions[index].stateTransition,
|
|
188
|
+
witnesses.witnesses[index],
|
|
189
|
+
index
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// If the current batch is finished, we push it to the list
|
|
193
|
+
// and initialize the next
|
|
194
|
+
const { type, witnessRoot } = transitions[index];
|
|
195
|
+
const closing = type.isClosing();
|
|
196
|
+
const closingAndApply = type.type.equals(
|
|
197
|
+
StateTransitionType.closeAndApply
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Create the newBatch
|
|
201
|
+
// The root is based on if the previous batch will be applied or not
|
|
202
|
+
const base = Provable.if(
|
|
203
|
+
closingAndApply,
|
|
204
|
+
updatedBatchState.root,
|
|
205
|
+
state.finalizedRoot
|
|
206
|
+
);
|
|
207
|
+
const newBatchState = new AppliedStateTransitionBatchState({
|
|
208
|
+
batchHash: Field(0),
|
|
209
|
+
root: base,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const updatedBatch = {
|
|
213
|
+
applied: closingAndApply,
|
|
214
|
+
batchHash: updatedBatchState.batchHash,
|
|
215
|
+
};
|
|
216
|
+
state.batchList.pushIf(updatedBatch, closing);
|
|
217
|
+
state.finalizedRoot = Provable.if(
|
|
218
|
+
closingAndApply,
|
|
219
|
+
updatedBatchState.root,
|
|
220
|
+
state.finalizedRoot
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Add computed root to the witnessed root list if needed
|
|
224
|
+
witnessRoot
|
|
225
|
+
.implies(closing)
|
|
226
|
+
.assertTrue("Can only witness roots at closing batches");
|
|
227
|
+
state.witnessedRoots.pushIf(
|
|
228
|
+
{
|
|
229
|
+
root: state.finalizedRoot,
|
|
230
|
+
appliedBatchListState: state.batchList.commitment,
|
|
231
|
+
},
|
|
232
|
+
witnessRoot
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const isDummy = ProvableStateTransition.isDummy(
|
|
236
|
+
transitions[index].stateTransition
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
// Dummy STs cannot change any state, as to prevent any
|
|
240
|
+
// dummy-in-the-middle attacks. This is given if the type is nothing.
|
|
241
|
+
isDummy
|
|
242
|
+
.implies(type.isNothing())
|
|
243
|
+
.assertTrue("Dummies have to be of type 'nothing'");
|
|
244
|
+
|
|
245
|
+
isDummy
|
|
246
|
+
.implies(state.currentBatch.batchHash.equals(0))
|
|
247
|
+
.assertTrue("Dummies can only be placed on closed batchLists");
|
|
248
|
+
|
|
249
|
+
// Dummies don't close the batch, but we still want to ignore any
|
|
250
|
+
// updated batch, since we need to result to stay.
|
|
251
|
+
// This will break the pipeline if there is a dummy in the middle,
|
|
252
|
+
// but will only end up to invalid proofs (i.e. mismatched batches)
|
|
253
|
+
|
|
254
|
+
state.currentBatch = new AppliedStateTransitionBatchState(
|
|
255
|
+
Provable.if(
|
|
256
|
+
closing.or(isDummy),
|
|
257
|
+
AppliedStateTransitionBatchState,
|
|
258
|
+
newBatchState,
|
|
259
|
+
updatedBatchState
|
|
260
|
+
)
|
|
261
|
+
);
|
|
164
262
|
}
|
|
165
263
|
|
|
166
264
|
return state;
|
|
@@ -171,37 +269,45 @@ export class StateTransitionProver
|
|
|
171
269
|
* and mutates it in place
|
|
172
270
|
*/
|
|
173
271
|
public applyTransition(
|
|
174
|
-
|
|
272
|
+
currentBatch: AppliedStateTransitionBatchState,
|
|
175
273
|
transition: ProvableStateTransition,
|
|
274
|
+
witness: LinkedMerkleTreeWitness,
|
|
176
275
|
index = 0
|
|
177
276
|
) {
|
|
178
|
-
const
|
|
179
|
-
|
|
277
|
+
const impliedRoot = this.applyTransitionToRoot(
|
|
278
|
+
transition,
|
|
279
|
+
currentBatch.root,
|
|
280
|
+
witness,
|
|
281
|
+
index
|
|
180
282
|
);
|
|
181
283
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
transition.from.value
|
|
284
|
+
// Append ST to the current batch's ST-list
|
|
285
|
+
const stList = new DefaultProvableHashList(
|
|
286
|
+
ProvableStateTransition,
|
|
287
|
+
currentBatch.batchHash
|
|
187
288
|
);
|
|
188
|
-
|
|
189
|
-
.or(transition.from.isSome.not())
|
|
190
|
-
.assertTrue(errors.merkleWitnessNotCorrect(index));
|
|
289
|
+
stList.push(transition);
|
|
191
290
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
newRoot,
|
|
199
|
-
state.stateRoot
|
|
200
|
-
);
|
|
291
|
+
// Update batch
|
|
292
|
+
return new AppliedStateTransitionBatchState({
|
|
293
|
+
batchHash: stList.commitment,
|
|
294
|
+
root: impliedRoot,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
201
297
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
298
|
+
private applyTransitionToRoot(
|
|
299
|
+
transition: ProvableStateTransition,
|
|
300
|
+
root: Field,
|
|
301
|
+
merkleWitness: LinkedMerkleTreeWitness,
|
|
302
|
+
index: number
|
|
303
|
+
): Field {
|
|
304
|
+
const treeWrite = this.transitionToTreeWrite(transition, merkleWitness);
|
|
305
|
+
|
|
306
|
+
return LinkedMerkleTreeCircuitOps.applyTreeWrite(
|
|
307
|
+
root,
|
|
308
|
+
merkleWitness,
|
|
309
|
+
treeWrite,
|
|
310
|
+
index
|
|
205
311
|
);
|
|
206
312
|
}
|
|
207
313
|
|
|
@@ -209,55 +315,157 @@ export class StateTransitionProver
|
|
|
209
315
|
* Applies a whole batch of StateTransitions at once
|
|
210
316
|
*/
|
|
211
317
|
@provableMethod()
|
|
212
|
-
public
|
|
318
|
+
public async proveBatch(
|
|
213
319
|
publicInput: StateTransitionProverPublicInput,
|
|
214
|
-
batch: StateTransitionProvableBatch
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
320
|
+
batch: StateTransitionProvableBatch,
|
|
321
|
+
witnesses: MerkleWitnessBatch,
|
|
322
|
+
currentAppliedBatch: AppliedStateTransitionBatchState
|
|
323
|
+
): Promise<StateTransitionProverPublicOutput> {
|
|
324
|
+
currentAppliedBatch
|
|
325
|
+
.hashOrZero()
|
|
326
|
+
.assertEquals(
|
|
327
|
+
publicInput.currentBatchStateHash,
|
|
328
|
+
"Provided startingAppliedBatch not matching PI hash"
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
// Assert that either the currentAppliedBatch is somewhere intermediary
|
|
332
|
+
// or the root is the current "finalized" root
|
|
333
|
+
currentAppliedBatch.root
|
|
334
|
+
.equals(publicInput.root)
|
|
335
|
+
.or(publicInput.currentBatchStateHash.equals(0).not())
|
|
336
|
+
.assertTrue();
|
|
221
337
|
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
338
|
+
const state: StateTransitionProverExecutionState = {
|
|
339
|
+
batchList: new AppliedBatchHashList(publicInput.batchesHash),
|
|
340
|
+
currentBatch: currentAppliedBatch,
|
|
341
|
+
finalizedRoot: publicInput.root,
|
|
342
|
+
witnessedRoots: new WitnessedRootHashList(publicInput.witnessedRootsHash),
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const result = this.applyTransitions(state, batch, witnesses);
|
|
346
|
+
|
|
347
|
+
return new StateTransitionProverPublicOutput({
|
|
348
|
+
batchesHash: result.batchList.commitment,
|
|
349
|
+
currentBatchStateHash: result.currentBatch.hashOrZero(),
|
|
350
|
+
root: result.finalizedRoot,
|
|
351
|
+
witnessedRootsHash: result.witnessedRoots.commitment,
|
|
225
352
|
});
|
|
226
|
-
return output;
|
|
227
353
|
}
|
|
228
354
|
|
|
229
355
|
@provableMethod()
|
|
230
|
-
public merge(
|
|
356
|
+
public async merge(
|
|
231
357
|
publicInput: StateTransitionProverPublicInput,
|
|
232
358
|
proof1: StateTransitionProof,
|
|
233
359
|
proof2: StateTransitionProof
|
|
234
|
-
): StateTransitionProverPublicOutput {
|
|
360
|
+
): Promise<StateTransitionProverPublicOutput> {
|
|
235
361
|
proof1.verify();
|
|
236
362
|
proof2.verify();
|
|
237
363
|
|
|
238
|
-
// Check
|
|
239
|
-
publicInput.
|
|
240
|
-
proof1.publicInput.
|
|
241
|
-
errors.
|
|
364
|
+
// Check current batch hash
|
|
365
|
+
publicInput.currentBatchStateHash.assertEquals(
|
|
366
|
+
proof1.publicInput.currentBatchStateHash,
|
|
367
|
+
errors.propertyNotMatching(
|
|
368
|
+
"currentBatchStateHash",
|
|
369
|
+
"publicInput.from -> proof1.from"
|
|
370
|
+
)
|
|
371
|
+
);
|
|
372
|
+
proof1.publicOutput.currentBatchStateHash.assertEquals(
|
|
373
|
+
proof2.publicInput.currentBatchStateHash,
|
|
374
|
+
errors.propertyNotMatching(
|
|
375
|
+
"currentBatchStateHash",
|
|
376
|
+
"proof1.to -> proof2.from"
|
|
377
|
+
)
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
// Check batches hash
|
|
381
|
+
publicInput.batchesHash.assertEquals(
|
|
382
|
+
proof1.publicInput.batchesHash,
|
|
383
|
+
errors.propertyNotMatching(
|
|
384
|
+
"batchesHash",
|
|
385
|
+
"publicInput.from -> proof1.from"
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
proof1.publicOutput.batchesHash.assertEquals(
|
|
389
|
+
proof2.publicInput.batchesHash,
|
|
390
|
+
errors.propertyNotMatching("batchesHash", "proof1.to -> proof2.from")
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
// Check root
|
|
394
|
+
publicInput.root.assertEquals(
|
|
395
|
+
proof1.publicInput.root,
|
|
396
|
+
errors.propertyNotMatching("root", "publicInput.from -> proof1.from")
|
|
242
397
|
);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
398
|
+
|
|
399
|
+
proof1.publicOutput.root.assertEquals(
|
|
400
|
+
proof2.publicInput.root,
|
|
401
|
+
errors.propertyNotMatching("root", "proof1.to -> proof2.from")
|
|
246
402
|
);
|
|
247
403
|
|
|
248
|
-
// Check
|
|
249
|
-
publicInput.
|
|
250
|
-
proof1.publicInput.
|
|
251
|
-
errors.
|
|
404
|
+
// Check root accumulator
|
|
405
|
+
publicInput.witnessedRootsHash.assertEquals(
|
|
406
|
+
proof1.publicInput.witnessedRootsHash,
|
|
407
|
+
errors.propertyNotMatching(
|
|
408
|
+
"witnessedRootsHash",
|
|
409
|
+
"publicInput.from -> proof1.from"
|
|
410
|
+
)
|
|
252
411
|
);
|
|
253
|
-
proof1.publicOutput.
|
|
254
|
-
proof2.publicInput.
|
|
255
|
-
errors.
|
|
412
|
+
proof1.publicOutput.witnessedRootsHash.assertEquals(
|
|
413
|
+
proof2.publicInput.witnessedRootsHash,
|
|
414
|
+
errors.propertyNotMatching(
|
|
415
|
+
"witnessedRootsHash",
|
|
416
|
+
"proof1.to -> proof2.from"
|
|
417
|
+
)
|
|
256
418
|
);
|
|
257
419
|
|
|
258
420
|
return new StateTransitionProverPublicInput({
|
|
259
|
-
|
|
260
|
-
|
|
421
|
+
currentBatchStateHash: proof2.publicOutput.currentBatchStateHash,
|
|
422
|
+
batchesHash: proof2.publicOutput.batchesHash,
|
|
423
|
+
root: proof2.publicOutput.root,
|
|
424
|
+
witnessedRootsHash: proof2.publicOutput.witnessedRootsHash,
|
|
261
425
|
});
|
|
262
426
|
}
|
|
263
427
|
}
|
|
428
|
+
|
|
429
|
+
@injectable()
|
|
430
|
+
export class StateTransitionProver
|
|
431
|
+
extends ProtocolModule
|
|
432
|
+
implements
|
|
433
|
+
StateTransitionProvable,
|
|
434
|
+
StateTransitionProverType,
|
|
435
|
+
CompilableModule
|
|
436
|
+
{
|
|
437
|
+
public zkProgrammable: StateTransitionProverProgrammable;
|
|
438
|
+
|
|
439
|
+
public constructor() {
|
|
440
|
+
super();
|
|
441
|
+
this.zkProgrammable = new StateTransitionProverProgrammable(this);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
public async compile(
|
|
445
|
+
registry: CompileRegistry
|
|
446
|
+
): Promise<void | ArtifactRecord> {
|
|
447
|
+
return await this.zkProgrammable.compile(registry);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
public proveBatch(
|
|
451
|
+
publicInput: StateTransitionProverPublicInput,
|
|
452
|
+
batch: StateTransitionProvableBatch,
|
|
453
|
+
witnesses: MerkleWitnessBatch,
|
|
454
|
+
startingAppliedBatch: AppliedStateTransitionBatchState
|
|
455
|
+
): Promise<StateTransitionProverPublicOutput> {
|
|
456
|
+
return this.zkProgrammable.proveBatch(
|
|
457
|
+
publicInput,
|
|
458
|
+
batch,
|
|
459
|
+
witnesses,
|
|
460
|
+
startingAppliedBatch
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
public merge(
|
|
465
|
+
publicInput: StateTransitionProverPublicInput,
|
|
466
|
+
proof1: StateTransitionProof,
|
|
467
|
+
proof2: StateTransitionProof
|
|
468
|
+
): Promise<StateTransitionProverPublicOutput> {
|
|
469
|
+
return this.zkProgrammable.merge(publicInput, proof1, proof2);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArtifactRecord,
|
|
3
|
+
type CompilableModule,
|
|
4
|
+
CompileRegistry,
|
|
5
|
+
ConfigurableModule,
|
|
6
|
+
NoConfig,
|
|
7
|
+
TypedClass,
|
|
8
|
+
} from "@proto-kit/common";
|
|
9
|
+
import { SmartContract } from "o1js";
|
|
10
|
+
|
|
11
|
+
export type SmartContractClassFromInterface<Type> = typeof SmartContract &
|
|
12
|
+
TypedClass<Type>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This module type is used to define a contract module that can be used to
|
|
16
|
+
* construct and inject smart contract instances.
|
|
17
|
+
* It defines a method contractFactory, whose arguments can be configured via
|
|
18
|
+
* the Argument generic. It returns a smart contract class that is a subclass
|
|
19
|
+
* of SmartContract and implements a certain interface as specified by the
|
|
20
|
+
* ContractType generic.
|
|
21
|
+
*/
|
|
22
|
+
export abstract class ContractModule<ContractType, Config = NoConfig>
|
|
23
|
+
extends ConfigurableModule<Config>
|
|
24
|
+
implements CompilableModule
|
|
25
|
+
{
|
|
26
|
+
public abstract contractFactory(): SmartContractClassFromInterface<ContractType>;
|
|
27
|
+
|
|
28
|
+
public abstract compile(
|
|
29
|
+
registry: CompileRegistry
|
|
30
|
+
): Promise<ArtifactRecord | undefined>;
|
|
31
|
+
}
|