@proto-kit/protocol 0.1.1-develop.165 → 0.1.1-develop.1661
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/messages/Withdrawal.d.ts +2 -0
- package/dist/settlement/messages/Withdrawal.d.ts.map +1 -0
- package/dist/settlement/messages/Withdrawal.js +3 -0
- package/dist/settlement/messages/Withdrawal.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/SimpleAsyncStateService.d.ts +6 -0
- package/dist/state/SimpleAsyncStateService.d.ts.map +1 -0
- package/dist/state/SimpleAsyncStateService.js +2 -0
- package/dist/state/SimpleAsyncStateService.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/StateTransitionReductionList.d.ts +11 -0
- package/dist/utils/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/utils/StateTransitionReductionList.js +61 -0
- package/dist/utils/StateTransitionReductionList.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,201 +1,750 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
import { Experimental, Field, type Proof, Provable, SelfProof } from "snarkyjs";
|
|
3
|
-
import { inject, injectable } from "tsyringe";
|
|
4
1
|
import {
|
|
2
|
+
Bool,
|
|
3
|
+
Field,
|
|
4
|
+
Proof,
|
|
5
|
+
Provable,
|
|
6
|
+
SelfProof,
|
|
7
|
+
VerificationKey,
|
|
8
|
+
ZkProgram,
|
|
9
|
+
} from "o1js";
|
|
10
|
+
import { container, inject, injectable, injectAll } from "tsyringe";
|
|
11
|
+
import {
|
|
12
|
+
AreProofsEnabled,
|
|
13
|
+
CompilableModule,
|
|
14
|
+
CompileArtifact,
|
|
15
|
+
CompileRegistry,
|
|
16
|
+
log,
|
|
17
|
+
MAX_FIELD,
|
|
5
18
|
PlainZkProgram,
|
|
6
19
|
provableMethod,
|
|
7
20
|
WithZkProgrammable,
|
|
8
21
|
ZkProgrammable,
|
|
9
22
|
} from "@proto-kit/common";
|
|
10
23
|
|
|
11
|
-
import { DefaultProvableHashList } from "../../utils/ProvableHashList";
|
|
12
24
|
import { MethodPublicOutput } from "../../model/MethodPublicOutput";
|
|
13
25
|
import { ProtocolModule } from "../../protocol/ProtocolModule";
|
|
14
26
|
import {
|
|
15
27
|
StateTransitionProof,
|
|
28
|
+
StateTransitionProvable,
|
|
16
29
|
StateTransitionProverPublicInput,
|
|
17
30
|
StateTransitionProverPublicOutput,
|
|
18
31
|
} from "../statetransition/StateTransitionProvable";
|
|
19
32
|
import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
|
|
33
|
+
import {
|
|
34
|
+
ProvableStateTransition,
|
|
35
|
+
StateTransition,
|
|
36
|
+
} from "../../model/StateTransition";
|
|
37
|
+
import {
|
|
38
|
+
AfterTransactionHookArguments,
|
|
39
|
+
BeforeTransactionHookArguments,
|
|
40
|
+
ProvableTransactionHook,
|
|
41
|
+
toProvableHookBlockState,
|
|
42
|
+
} from "../../protocol/ProvableTransactionHook";
|
|
43
|
+
import {
|
|
44
|
+
RuntimeMethodExecutionContext,
|
|
45
|
+
RuntimeMethodExecutionData,
|
|
46
|
+
} from "../../state/context/RuntimeMethodExecutionContext";
|
|
47
|
+
import {
|
|
48
|
+
AfterBlockHookArguments,
|
|
49
|
+
BeforeBlockHookArguments,
|
|
50
|
+
ProvableBlockHook,
|
|
51
|
+
toAfterTransactionHookArgument,
|
|
52
|
+
toBeforeTransactionHookArgument,
|
|
53
|
+
} from "../../protocol/ProvableBlockHook";
|
|
54
|
+
import { NetworkState } from "../../model/network/NetworkState";
|
|
55
|
+
import { SignedTransaction } from "../../model/transaction/SignedTransaction";
|
|
56
|
+
import { MinaActions } from "../../utils/MinaPrefixedProvableHashList";
|
|
57
|
+
import { StateTransitionReductionList } from "../accumulators/StateTransitionReductionList";
|
|
58
|
+
import { assertEqualsIf } from "../../utils/utils";
|
|
59
|
+
import { WitnessedRootWitness } from "../accumulators/WitnessedRootHashList";
|
|
60
|
+
import { StateServiceProvider } from "../../state/StateServiceProvider";
|
|
61
|
+
import { AppliedStateTransitionBatch } from "../../model/AppliedStateTransitionBatch";
|
|
20
62
|
|
|
21
63
|
import {
|
|
22
64
|
BlockProvable,
|
|
23
|
-
BlockProverExecutionData,
|
|
24
65
|
BlockProverProof,
|
|
25
66
|
BlockProverPublicInput,
|
|
26
67
|
BlockProverPublicOutput,
|
|
68
|
+
DynamicRuntimeProof,
|
|
69
|
+
BlockProverMultiTransactionExecutionData,
|
|
70
|
+
BlockProverTransactionArguments,
|
|
71
|
+
BlockProverSingleTransactionExecutionData,
|
|
72
|
+
BlockProverState,
|
|
73
|
+
BlockProverStateCommitments,
|
|
27
74
|
} from "./BlockProvable";
|
|
75
|
+
import {
|
|
76
|
+
BlockHashMerkleTreeWitness,
|
|
77
|
+
BlockHashTreeEntry,
|
|
78
|
+
} from "./accummulators/BlockHashMerkleTree";
|
|
79
|
+
import {
|
|
80
|
+
MethodVKConfigData,
|
|
81
|
+
MinimalVKTreeService,
|
|
82
|
+
RuntimeVerificationKeyAttestation,
|
|
83
|
+
} from "./accummulators/RuntimeVerificationKeyTree";
|
|
84
|
+
import { RuntimeVerificationKeyRootService } from "./services/RuntimeVerificationKeyRootService";
|
|
28
85
|
|
|
29
86
|
const errors = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
stateTransitionsHashNotEqual: () =>
|
|
34
|
-
"StateTransition list commitments are not equal",
|
|
87
|
+
propertyNotMatchingStep: (propertyName: string, step: string) =>
|
|
88
|
+
`${propertyName} not matching: ${step}`,
|
|
35
89
|
|
|
36
90
|
propertyNotMatching: (propertyName: string) => `${propertyName} not matching`,
|
|
37
91
|
|
|
38
|
-
stateRootNotMatching: (step: string) =>
|
|
92
|
+
stateRootNotMatching: (step: string) =>
|
|
93
|
+
errors.propertyNotMatchingStep("StateRoots", step),
|
|
39
94
|
|
|
40
95
|
transactionsHashNotMatching: (step: string) =>
|
|
41
|
-
|
|
42
|
-
};
|
|
96
|
+
errors.propertyNotMatchingStep("Transactions hash", step),
|
|
43
97
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
stateRoot: Field;
|
|
98
|
+
networkStateHashNotMatching: (step: string) =>
|
|
99
|
+
errors.propertyNotMatchingStep("Network state hash", step),
|
|
47
100
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
52
|
-
transactionsHash: Field;
|
|
101
|
+
invalidZkProgramTreeRoot: () =>
|
|
102
|
+
"Root hash of the provided zkProgram config witness is invalid",
|
|
103
|
+
};
|
|
53
104
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
networkStateHash: Field;
|
|
59
|
-
}
|
|
105
|
+
type ApplyTransactionArguments = Omit<
|
|
106
|
+
BlockProverTransactionArguments,
|
|
107
|
+
"verificationKeyAttestation"
|
|
108
|
+
>;
|
|
60
109
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export class BlockProver
|
|
68
|
-
extends ProtocolModule<BlockProverPublicInput, BlockProverPublicOutput>
|
|
69
|
-
implements BlockProvable
|
|
70
|
-
{
|
|
110
|
+
export type BlockProof = Proof<BlockProverPublicInput, BlockProverPublicOutput>;
|
|
111
|
+
|
|
112
|
+
export class BlockProverProgrammable extends ZkProgrammable<
|
|
113
|
+
BlockProverPublicInput,
|
|
114
|
+
BlockProverPublicOutput
|
|
115
|
+
> {
|
|
71
116
|
public constructor(
|
|
72
|
-
|
|
73
|
-
|
|
117
|
+
private readonly prover: BlockProver,
|
|
118
|
+
public readonly stateTransitionProver: ZkProgrammable<
|
|
74
119
|
StateTransitionProverPublicInput,
|
|
75
120
|
StateTransitionProverPublicOutput
|
|
76
121
|
>,
|
|
77
|
-
|
|
78
|
-
private readonly
|
|
122
|
+
private readonly transactionHooks: ProvableTransactionHook<unknown>[],
|
|
123
|
+
private readonly blockHooks: ProvableBlockHook<unknown>[],
|
|
124
|
+
private readonly stateServiceProvider: StateServiceProvider,
|
|
125
|
+
private readonly verificationKeyService: MinimalVKTreeService
|
|
79
126
|
) {
|
|
80
127
|
super();
|
|
81
128
|
}
|
|
82
129
|
|
|
130
|
+
name = "BlockProver";
|
|
131
|
+
|
|
132
|
+
public get areProofsEnabled(): AreProofsEnabled | undefined {
|
|
133
|
+
return this.prover.areProofsEnabled;
|
|
134
|
+
}
|
|
135
|
+
|
|
83
136
|
/**
|
|
84
137
|
* Applies and checks the two proofs and applies the corresponding state
|
|
85
|
-
* changes to the given state
|
|
138
|
+
* changes to the given state.
|
|
139
|
+
*
|
|
140
|
+
* The rough high level workflow of this function:
|
|
141
|
+
* 1. Execute beforeTransaction hooks, pushing the ST batch
|
|
142
|
+
* 2. Add Transaction to bundle, meaning appending it to all the respective commitments
|
|
143
|
+
* 3. Push the runtime ST batch
|
|
144
|
+
* 4. Execute afterTransaction hooks, pushing the ST batch
|
|
145
|
+
* 5. Some consistency checks and signature verification
|
|
86
146
|
*
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
89
|
-
* @param
|
|
147
|
+
* @param fromState The from-state of the BlockProver
|
|
148
|
+
* @param runtimeOutput
|
|
149
|
+
* @param executionData
|
|
150
|
+
* @param networkState
|
|
90
151
|
* @returns The new BlockProver-state to be used as public output
|
|
91
152
|
*/
|
|
92
|
-
public applyTransaction(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{ transaction, networkState }: BlockProverExecutionData
|
|
100
|
-
): BlockProverState {
|
|
101
|
-
appProof.verify();
|
|
102
|
-
stateTransitionProof.verify();
|
|
153
|
+
public async applyTransaction(
|
|
154
|
+
fromState: BlockProverState,
|
|
155
|
+
runtimeOutput: MethodPublicOutput,
|
|
156
|
+
executionData: ApplyTransactionArguments,
|
|
157
|
+
networkState: NetworkState
|
|
158
|
+
): Promise<BlockProverState> {
|
|
159
|
+
const { transaction, signature } = executionData;
|
|
103
160
|
|
|
104
|
-
|
|
161
|
+
let state = { ...fromState };
|
|
105
162
|
|
|
106
|
-
|
|
107
|
-
// TODO Check methodId?
|
|
163
|
+
const { isMessage } = runtimeOutput;
|
|
108
164
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
165
|
+
const beforeTxHookArguments = toBeforeTransactionHookArgument(
|
|
166
|
+
executionData,
|
|
167
|
+
networkState,
|
|
168
|
+
state
|
|
113
169
|
);
|
|
114
170
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
171
|
+
// Apply beforeTransaction hook state transitions
|
|
172
|
+
const beforeBatch = await this.executeTransactionHooks(
|
|
173
|
+
async (module, args) => await module.beforeTransaction(args),
|
|
174
|
+
beforeTxHookArguments
|
|
118
175
|
);
|
|
119
176
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
177
|
+
state = this.addTransactionToBundle(
|
|
178
|
+
state,
|
|
179
|
+
runtimeOutput.isMessage,
|
|
180
|
+
transaction
|
|
124
181
|
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
182
|
+
|
|
183
|
+
state.pendingSTBatches.push(beforeBatch);
|
|
184
|
+
|
|
185
|
+
state.pendingSTBatches.push({
|
|
186
|
+
batchHash: runtimeOutput.stateTransitionsHash,
|
|
187
|
+
applied: runtimeOutput.status,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Apply afterTransaction hook state transitions
|
|
191
|
+
const afterTxHookArguments = toAfterTransactionHookArgument(
|
|
192
|
+
executionData,
|
|
193
|
+
networkState,
|
|
194
|
+
state,
|
|
195
|
+
runtimeOutput
|
|
129
196
|
);
|
|
130
197
|
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
.validateSignature()
|
|
134
|
-
.assertTrue("Transaction signature not valid");
|
|
198
|
+
// Switch to different state set for afterTx hooks
|
|
199
|
+
this.stateServiceProvider.popCurrentStateService();
|
|
135
200
|
|
|
136
|
-
|
|
137
|
-
|
|
201
|
+
const afterBatch = await this.executeTransactionHooks(
|
|
202
|
+
async (module, args) => await module.afterTransaction(args),
|
|
203
|
+
afterTxHookArguments
|
|
204
|
+
);
|
|
205
|
+
state.pendingSTBatches.push(afterBatch);
|
|
138
206
|
|
|
139
207
|
// Check transaction integrity against appProof
|
|
140
|
-
const blockTransactionHash =
|
|
141
|
-
RuntimeTransaction.fromProtocolTransaction(transaction).hash();
|
|
208
|
+
const blockTransactionHash = transaction.hash();
|
|
142
209
|
|
|
143
210
|
blockTransactionHash.assertEquals(
|
|
144
|
-
|
|
211
|
+
runtimeOutput.transactionHash,
|
|
145
212
|
"Transactions provided in AppProof and BlockProof do not match"
|
|
146
213
|
);
|
|
147
214
|
|
|
215
|
+
// Check transaction signature
|
|
216
|
+
new SignedTransaction({
|
|
217
|
+
transaction,
|
|
218
|
+
signature,
|
|
219
|
+
})
|
|
220
|
+
.validateSignature()
|
|
221
|
+
.or(isMessage)
|
|
222
|
+
.assertTrue("Transaction signature not valid");
|
|
223
|
+
|
|
224
|
+
// Validate layout of transaction witness
|
|
225
|
+
transaction.assertTransactionType(isMessage);
|
|
226
|
+
|
|
148
227
|
// Check network state integrity against appProof
|
|
149
|
-
state.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
228
|
+
state.networkState
|
|
229
|
+
.hash()
|
|
230
|
+
.assertEquals(
|
|
231
|
+
runtimeOutput.networkStateHash,
|
|
232
|
+
"Network state does not match state used in AppProof"
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
return state;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// eslint-disable-next-line max-len
|
|
239
|
+
// TODO How does this interact with the RuntimeMethodExecutionContext when executing runtimemethods?
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Constructs a AppliedBatch based on a list of STs and the flag whether to
|
|
243
|
+
* be applied or not. The AppliedBatch is a condensed commitment to a batch
|
|
244
|
+
* of STs.
|
|
245
|
+
*/
|
|
246
|
+
private constructBatch(
|
|
247
|
+
stateTransitions: StateTransition<any>[],
|
|
248
|
+
applied: Bool
|
|
249
|
+
) {
|
|
250
|
+
const transitions = stateTransitions.map((transition) =>
|
|
251
|
+
transition.toProvable()
|
|
156
252
|
);
|
|
157
253
|
|
|
254
|
+
const hashList = new StateTransitionReductionList(ProvableStateTransition);
|
|
255
|
+
transitions.forEach((transition) => {
|
|
256
|
+
hashList.push(transition);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return new AppliedStateTransitionBatch({
|
|
260
|
+
batchHash: hashList.commitment,
|
|
261
|
+
applied,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private async executeTransactionHooks<
|
|
266
|
+
T extends BeforeTransactionHookArguments | AfterTransactionHookArguments,
|
|
267
|
+
>(
|
|
268
|
+
hook: (module: ProvableTransactionHook<unknown>, args: T) => Promise<void>,
|
|
269
|
+
hookArguments: T
|
|
270
|
+
) {
|
|
271
|
+
const { batch } = await this.executeHooks(hookArguments, async () => {
|
|
272
|
+
for (const module of this.transactionHooks) {
|
|
273
|
+
// eslint-disable-next-line no-await-in-loop
|
|
274
|
+
await hook(module, hookArguments);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return batch;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private async executeHooks<T>(
|
|
281
|
+
contextArguments: RuntimeMethodExecutionData,
|
|
282
|
+
method: () => Promise<T>
|
|
283
|
+
) {
|
|
284
|
+
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
285
|
+
executionContext.clear();
|
|
286
|
+
|
|
287
|
+
// Setup context for potential calls to runtime methods.
|
|
288
|
+
// This way they can use this.transaction etc. while still having provable
|
|
289
|
+
// integrity between data
|
|
290
|
+
executionContext.setup(contextArguments);
|
|
291
|
+
executionContext.beforeMethod("", "", []);
|
|
292
|
+
|
|
293
|
+
const result = await method();
|
|
294
|
+
|
|
295
|
+
executionContext.afterMethod();
|
|
296
|
+
|
|
297
|
+
const { stateTransitions, status, statusMessage } =
|
|
298
|
+
executionContext.current().result;
|
|
299
|
+
|
|
300
|
+
status.assertTrue(`Transaction hook call failed: ${statusMessage ?? "-"}`);
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
batch: this.constructBatch(stateTransitions, Bool(true)),
|
|
304
|
+
result,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public async executeBlockHooks<
|
|
309
|
+
T extends BeforeBlockHookArguments | AfterBlockHookArguments,
|
|
310
|
+
>(
|
|
311
|
+
hook: (
|
|
312
|
+
module: ProvableBlockHook<unknown>,
|
|
313
|
+
networkState: NetworkState,
|
|
314
|
+
args: T
|
|
315
|
+
) => Promise<NetworkState>,
|
|
316
|
+
hookArguments: T,
|
|
317
|
+
inputNetworkState: NetworkState
|
|
318
|
+
) {
|
|
319
|
+
const transaction = RuntimeTransaction.dummyTransaction();
|
|
320
|
+
const startingInputs = {
|
|
321
|
+
transaction,
|
|
322
|
+
networkState: inputNetworkState,
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
return await this.executeHooks(startingInputs, async () => {
|
|
326
|
+
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
327
|
+
|
|
328
|
+
return await this.blockHooks.reduce<Promise<NetworkState>>(
|
|
329
|
+
async (networkStatePromise, blockHook) => {
|
|
330
|
+
const networkState = await networkStatePromise;
|
|
331
|
+
|
|
332
|
+
// Setup context for potential calls to runtime methods.
|
|
333
|
+
// With the special case that we set the new networkstate for every hook
|
|
334
|
+
// We also have to put in a dummy transaction for network.transaction
|
|
335
|
+
executionContext.setup({
|
|
336
|
+
transaction: RuntimeTransaction.dummyTransaction(),
|
|
337
|
+
networkState,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return await hook(blockHook, networkState, hookArguments);
|
|
341
|
+
},
|
|
342
|
+
Promise.resolve(inputNetworkState)
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
public addTransactionToBundle<
|
|
348
|
+
T extends Pick<
|
|
349
|
+
BlockProverState,
|
|
350
|
+
"transactionList" | "eternalTransactionsList" | "incomingMessages"
|
|
351
|
+
>,
|
|
352
|
+
>(state: T, isMessage: Bool, transaction: RuntimeTransaction): T {
|
|
353
|
+
const transactionHash = transaction.hash();
|
|
354
|
+
|
|
158
355
|
// Append tx to transaction list
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
356
|
+
state.transactionList.pushIf(transactionHash, isMessage.not());
|
|
357
|
+
|
|
358
|
+
// Append tx to eternal transaction list
|
|
359
|
+
// TODO Change that to the a sequence-state compatible transaction struct
|
|
360
|
+
state.eternalTransactionsList.push(transactionHash);
|
|
361
|
+
|
|
362
|
+
// Append tx to incomingMessagesHash
|
|
363
|
+
const actionHash = MinaActions.actionHash(transaction.hashData());
|
|
364
|
+
|
|
365
|
+
state.incomingMessages.pushIf(actionHash, isMessage);
|
|
366
|
+
|
|
367
|
+
return state;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private verifyVerificationKeyAttestation(
|
|
371
|
+
attestation: RuntimeVerificationKeyAttestation,
|
|
372
|
+
methodId: Field
|
|
373
|
+
): VerificationKey {
|
|
374
|
+
// Verify the [methodId, vk] tuple against the baked-in vk tree root
|
|
375
|
+
const { verificationKey, witness: verificationKeyTreeWitness } =
|
|
376
|
+
attestation;
|
|
377
|
+
|
|
378
|
+
const root = Field(this.verificationKeyService.getRoot());
|
|
379
|
+
const calculatedRoot = verificationKeyTreeWitness.calculateRoot(
|
|
380
|
+
new MethodVKConfigData({
|
|
381
|
+
methodId: methodId,
|
|
382
|
+
vkHash: verificationKey.hash,
|
|
383
|
+
}).hash()
|
|
384
|
+
);
|
|
385
|
+
root.assertEquals(calculatedRoot, errors.invalidZkProgramTreeRoot());
|
|
386
|
+
|
|
387
|
+
return verificationKey;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
public async proveTransactionInternal(
|
|
391
|
+
fromState: BlockProverState,
|
|
392
|
+
runtimeProof: DynamicRuntimeProof,
|
|
393
|
+
{ transaction, networkState }: BlockProverSingleTransactionExecutionData
|
|
394
|
+
): Promise<BlockProverState> {
|
|
395
|
+
const verificationKey = this.verifyVerificationKeyAttestation(
|
|
396
|
+
transaction.verificationKeyAttestation,
|
|
397
|
+
transaction.transaction.methodId
|
|
162
398
|
);
|
|
163
399
|
|
|
164
|
-
|
|
165
|
-
transactionList.push(transactionHash);
|
|
400
|
+
runtimeProof.verify(verificationKey);
|
|
166
401
|
|
|
167
|
-
|
|
402
|
+
return await this.applyTransaction(
|
|
403
|
+
fromState,
|
|
404
|
+
runtimeProof.publicOutput,
|
|
405
|
+
transaction,
|
|
406
|
+
networkState
|
|
407
|
+
);
|
|
408
|
+
}
|
|
168
409
|
|
|
169
|
-
|
|
410
|
+
private staticChecks(publicInput: BlockProverPublicInput) {
|
|
411
|
+
publicInput.blockNumber.assertEquals(
|
|
412
|
+
MAX_FIELD,
|
|
413
|
+
"blockNumber has to be MAX for transaction proofs"
|
|
414
|
+
);
|
|
170
415
|
}
|
|
171
416
|
|
|
172
417
|
@provableMethod()
|
|
173
|
-
public proveTransaction(
|
|
418
|
+
public async proveTransaction(
|
|
174
419
|
publicInput: BlockProverPublicInput,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
420
|
+
runtimeProof: DynamicRuntimeProof,
|
|
421
|
+
executionData: BlockProverSingleTransactionExecutionData
|
|
422
|
+
): Promise<BlockProverPublicOutput> {
|
|
423
|
+
const state = BlockProverStateCommitments.toBlockProverState(
|
|
424
|
+
publicInput,
|
|
425
|
+
executionData.networkState
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
this.staticChecks(publicInput);
|
|
429
|
+
|
|
430
|
+
const stateTo = await this.proveTransactionInternal(
|
|
431
|
+
state,
|
|
432
|
+
runtimeProof,
|
|
433
|
+
executionData
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
return new BlockProverPublicOutput({
|
|
437
|
+
...BlockProverStateCommitments.fromBlockProverState(stateTo),
|
|
438
|
+
closed: Bool(false),
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
@provableMethod()
|
|
443
|
+
public async proveTransactions(
|
|
444
|
+
publicInput: BlockProverPublicInput,
|
|
445
|
+
runtimeProof1: DynamicRuntimeProof,
|
|
446
|
+
runtimeProof2: DynamicRuntimeProof,
|
|
447
|
+
executionData: BlockProverMultiTransactionExecutionData
|
|
448
|
+
): Promise<BlockProverPublicOutput> {
|
|
449
|
+
const state = BlockProverStateCommitments.toBlockProverState(
|
|
450
|
+
publicInput,
|
|
451
|
+
executionData.networkState
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
this.staticChecks(publicInput);
|
|
455
|
+
|
|
456
|
+
const state1 = await this.proveTransactionInternal(state, runtimeProof1, {
|
|
457
|
+
transaction: executionData.transaction1,
|
|
458
|
+
networkState: executionData.networkState,
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// Switch to next state record for 2nd tx beforeTx hook
|
|
462
|
+
// TODO Can be prevented by merging 1st afterTx + 2nd beforeTx
|
|
463
|
+
this.stateServiceProvider.popCurrentStateService();
|
|
464
|
+
|
|
465
|
+
const stateTo = await this.proveTransactionInternal(state1, runtimeProof2, {
|
|
466
|
+
transaction: executionData.transaction2,
|
|
467
|
+
networkState: executionData.networkState,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
return new BlockProverPublicOutput({
|
|
471
|
+
...BlockProverStateCommitments.fromBlockProverState(stateTo),
|
|
472
|
+
closed: Bool(false),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public includeSTProof(
|
|
477
|
+
stateTransitionProof: StateTransitionProof,
|
|
478
|
+
apply: Bool,
|
|
479
|
+
stateRoot: Field,
|
|
480
|
+
pendingSTBatchesHash: Field,
|
|
481
|
+
witnessedRootsHash: Field
|
|
482
|
+
): {
|
|
483
|
+
stateRoot: Field;
|
|
484
|
+
pendingSTBatchesHash: Field;
|
|
485
|
+
witnessedRootsHash: Field;
|
|
486
|
+
} {
|
|
487
|
+
assertEqualsIf(
|
|
488
|
+
stateTransitionProof.publicInput.currentBatchStateHash,
|
|
489
|
+
Field(0),
|
|
490
|
+
apply,
|
|
491
|
+
"State for STProof has to be empty at the start"
|
|
492
|
+
);
|
|
493
|
+
assertEqualsIf(
|
|
494
|
+
stateTransitionProof.publicOutput.currentBatchStateHash,
|
|
495
|
+
Field(0),
|
|
496
|
+
apply,
|
|
497
|
+
"State for STProof has to be empty at the end"
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
assertEqualsIf(
|
|
501
|
+
stateTransitionProof.publicInput.batchesHash,
|
|
502
|
+
Field(0),
|
|
503
|
+
apply,
|
|
504
|
+
"Batcheshash doesn't start at 0"
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
// Assert from state root
|
|
508
|
+
assertEqualsIf(
|
|
509
|
+
stateRoot,
|
|
510
|
+
stateTransitionProof.publicInput.root,
|
|
511
|
+
apply,
|
|
512
|
+
errors.propertyNotMatching("from state root")
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
// Assert the stBatchesHash executed is the same
|
|
516
|
+
assertEqualsIf(
|
|
517
|
+
pendingSTBatchesHash,
|
|
518
|
+
stateTransitionProof.publicOutput.batchesHash,
|
|
519
|
+
apply,
|
|
520
|
+
"Pending STBatches are not the same that have been executed by the ST proof"
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
// Assert root Accumulator
|
|
524
|
+
assertEqualsIf(
|
|
525
|
+
Field(0),
|
|
526
|
+
stateTransitionProof.publicInput.witnessedRootsHash,
|
|
527
|
+
apply,
|
|
528
|
+
errors.propertyNotMatching("from state root")
|
|
529
|
+
);
|
|
530
|
+
// Assert the witnessedRootsHash created is the same
|
|
531
|
+
assertEqualsIf(
|
|
532
|
+
witnessedRootsHash,
|
|
533
|
+
stateTransitionProof.publicOutput.witnessedRootsHash,
|
|
534
|
+
apply,
|
|
535
|
+
"Root accumulator Commitment is not the same that have been executed by the ST proof"
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
// update root only if we didn't defer
|
|
539
|
+
const newRoot = Provable.if(
|
|
540
|
+
apply,
|
|
541
|
+
stateTransitionProof.publicOutput.root,
|
|
542
|
+
stateRoot
|
|
543
|
+
);
|
|
544
|
+
// Reset only if we didn't defer
|
|
545
|
+
const newBatchesHash = Provable.if(apply, Field(0), pendingSTBatchesHash);
|
|
546
|
+
const newWitnessedRootsHash = Provable.if(
|
|
547
|
+
apply,
|
|
548
|
+
Field(0),
|
|
549
|
+
witnessedRootsHash
|
|
550
|
+
);
|
|
551
|
+
return {
|
|
552
|
+
stateRoot: newRoot,
|
|
553
|
+
pendingSTBatchesHash: newBatchesHash,
|
|
554
|
+
witnessedRootsHash: newWitnessedRootsHash,
|
|
183
555
|
};
|
|
556
|
+
}
|
|
184
557
|
|
|
185
|
-
|
|
558
|
+
@provableMethod()
|
|
559
|
+
public async proveBlock(
|
|
560
|
+
publicInput: BlockProverPublicInput,
|
|
561
|
+
networkState: NetworkState,
|
|
562
|
+
blockWitness: BlockHashMerkleTreeWitness,
|
|
563
|
+
stateTransitionProof: StateTransitionProof,
|
|
564
|
+
deferSTProof: Bool,
|
|
565
|
+
afterBlockRootWitness: WitnessedRootWitness,
|
|
566
|
+
transactionProof: BlockProverProof
|
|
567
|
+
): Promise<BlockProverPublicOutput> {
|
|
568
|
+
// 1. Make assertions about the inputs
|
|
569
|
+
publicInput.transactionsHash.assertEquals(
|
|
570
|
+
Field(0),
|
|
571
|
+
"Transactionshash has to start at 0"
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
// TransactionProof format checks
|
|
575
|
+
transactionProof.publicInput.blockHashRoot.assertEquals(
|
|
576
|
+
Field(0),
|
|
577
|
+
"TransactionProof cannot carry the blockHashRoot - publicInput"
|
|
578
|
+
);
|
|
579
|
+
transactionProof.publicOutput.blockHashRoot.assertEquals(
|
|
580
|
+
Field(0),
|
|
581
|
+
"TransactionProof cannot carry the blockHashRoot - publicOutput"
|
|
582
|
+
);
|
|
583
|
+
transactionProof.publicInput.networkStateHash.assertEquals(
|
|
584
|
+
transactionProof.publicOutput.networkStateHash,
|
|
585
|
+
"TransactionProof cannot alter the network state"
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
const state = BlockProverStateCommitments.toBlockProverState(
|
|
589
|
+
publicInput,
|
|
590
|
+
networkState
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
// Verify Transaction proof if it has at least 1 tx - i.e. the
|
|
594
|
+
// input and output doesn't match fully
|
|
595
|
+
// We have to compare the whole input and output because we can make no
|
|
596
|
+
// assumptions about the values, since it can be an arbitrary dummy-proof
|
|
597
|
+
const txProofOutput = transactionProof.publicOutput;
|
|
598
|
+
const isEmptyTransition = txProofOutput.equals(
|
|
599
|
+
transactionProof.publicInput,
|
|
600
|
+
txProofOutput.closed
|
|
601
|
+
);
|
|
602
|
+
const skipTransactionProofVerification = isEmptyTransition;
|
|
603
|
+
const verifyTransactionProof = isEmptyTransition.not();
|
|
604
|
+
log.provable.debug("VerifyIf TxProof", verifyTransactionProof);
|
|
605
|
+
transactionProof.verifyIf(verifyTransactionProof);
|
|
606
|
+
|
|
607
|
+
// 2. Execute beforeBlock hooks
|
|
608
|
+
const beforeBlockArgs = toProvableHookBlockState(state);
|
|
609
|
+
const beforeBlockResult = await this.executeBlockHooks(
|
|
610
|
+
async (module, networkStateArg, args) =>
|
|
611
|
+
await module.beforeBlock(networkStateArg, args),
|
|
612
|
+
beforeBlockArgs,
|
|
613
|
+
networkState
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
state.pendingSTBatches.push(beforeBlockResult.batch);
|
|
617
|
+
|
|
618
|
+
// 4. Apply TX-type BlockProof
|
|
619
|
+
transactionProof.publicInput.networkStateHash
|
|
620
|
+
.equals(beforeBlockResult.result.hash())
|
|
621
|
+
.or(skipTransactionProofVerification)
|
|
622
|
+
.assertTrue(
|
|
623
|
+
"TransactionProof networkstate hash not matching beforeBlock hook result"
|
|
624
|
+
);
|
|
625
|
+
transactionProof.publicInput.stateRoot.assertEquals(
|
|
626
|
+
transactionProof.publicOutput.stateRoot,
|
|
627
|
+
"TransactionProofs can't change the state root"
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
// Check that the transaction proof's STs start after the beforeBlock hook
|
|
631
|
+
transactionProof.publicInput.pendingSTBatchesHash.assertEquals(
|
|
632
|
+
state.pendingSTBatches.commitment,
|
|
633
|
+
"Transaction proof doesn't start their STs after the beforeBlockHook"
|
|
634
|
+
);
|
|
635
|
+
// Fast-forward the stBatchHashList to after all transactions appended
|
|
636
|
+
state.pendingSTBatches.commitment =
|
|
637
|
+
transactionProof.publicOutput.pendingSTBatchesHash;
|
|
638
|
+
|
|
639
|
+
// Fast-forward block content commitments by the results of the aggregated transaction proof
|
|
640
|
+
// Implicitly, the 'from' values here are asserted against the publicInput, since the hashlists
|
|
641
|
+
// are created out of the public input
|
|
642
|
+
state.transactionList.fastForward({
|
|
643
|
+
from: transactionProof.publicInput.transactionsHash,
|
|
644
|
+
to: transactionProof.publicOutput.transactionsHash,
|
|
645
|
+
});
|
|
646
|
+
state.eternalTransactionsList.fastForward({
|
|
647
|
+
from: transactionProof.publicInput.eternalTransactionsHash,
|
|
648
|
+
to: transactionProof.publicOutput.eternalTransactionsHash,
|
|
649
|
+
});
|
|
650
|
+
state.incomingMessages.fastForward({
|
|
651
|
+
from: transactionProof.publicInput.incomingMessagesHash,
|
|
652
|
+
to: transactionProof.publicOutput.incomingMessagesHash,
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// Witness root
|
|
656
|
+
const isEmpty = state.pendingSTBatches.commitment.equals(0);
|
|
657
|
+
isEmpty
|
|
658
|
+
.implies(state.stateRoot.equals(afterBlockRootWitness.witnessedRoot))
|
|
659
|
+
.assertTrue();
|
|
660
|
+
|
|
661
|
+
state.witnessedRoots.witnessRoot(
|
|
662
|
+
{
|
|
663
|
+
appliedBatchListState: state.pendingSTBatches.commitment,
|
|
664
|
+
root: afterBlockRootWitness.witnessedRoot,
|
|
665
|
+
},
|
|
666
|
+
afterBlockRootWitness.preimage,
|
|
667
|
+
isEmpty.not()
|
|
668
|
+
);
|
|
669
|
+
|
|
670
|
+
// 5. Calculate the new block tree hash
|
|
671
|
+
const blockIndex = blockWitness.calculateIndex();
|
|
672
|
+
|
|
673
|
+
blockIndex.assertEquals(publicInput.blockNumber);
|
|
674
|
+
|
|
675
|
+
blockWitness
|
|
676
|
+
.calculateRoot(Field(0))
|
|
677
|
+
.assertEquals(
|
|
678
|
+
publicInput.blockHashRoot,
|
|
679
|
+
"Supplied block hash witness not matching state root"
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
state.blockHashRoot = blockWitness.calculateRoot(
|
|
683
|
+
new BlockHashTreeEntry({
|
|
684
|
+
block: {
|
|
685
|
+
index: blockIndex,
|
|
686
|
+
transactionListHash: state.transactionList.commitment,
|
|
687
|
+
},
|
|
688
|
+
closed: Bool(true),
|
|
689
|
+
}).hash()
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
// 6. Execute afterBlock hooks
|
|
693
|
+
|
|
694
|
+
// Switch state service to afterBlock one
|
|
695
|
+
this.stateServiceProvider.popCurrentStateService();
|
|
696
|
+
|
|
697
|
+
const afterBlockHookArgs = toProvableHookBlockState(state);
|
|
698
|
+
const afterBlockResult = await this.executeBlockHooks(
|
|
699
|
+
async (module, networkStateArg, args) =>
|
|
700
|
+
await module.afterBlock(networkStateArg, args),
|
|
701
|
+
{
|
|
702
|
+
...afterBlockHookArgs,
|
|
703
|
+
stateRoot: afterBlockRootWitness.witnessedRoot,
|
|
704
|
+
},
|
|
705
|
+
beforeBlockResult.result
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
state.pendingSTBatches.push(afterBlockResult.batch);
|
|
709
|
+
|
|
710
|
+
state.networkState = afterBlockResult.result;
|
|
711
|
+
|
|
712
|
+
// 7. Close block
|
|
713
|
+
|
|
714
|
+
// Verify ST Proof only if STs have been emitted,
|
|
715
|
+
// and we don't defer the verification of the STs
|
|
716
|
+
// otherwise we can input a dummy proof
|
|
717
|
+
const batchesEmpty = state.pendingSTBatches.commitment.equals(Field(0));
|
|
718
|
+
const verifyStProof = deferSTProof.not().and(batchesEmpty.not());
|
|
719
|
+
log.provable.debug("Verify STProof", verifyStProof);
|
|
720
|
+
stateTransitionProof.verifyIf(verifyStProof);
|
|
721
|
+
|
|
722
|
+
// Apply STProof if not deferred
|
|
723
|
+
const stateProofResult = this.includeSTProof(
|
|
724
|
+
stateTransitionProof,
|
|
725
|
+
verifyStProof,
|
|
726
|
+
state.stateRoot,
|
|
727
|
+
state.pendingSTBatches.commitment,
|
|
728
|
+
state.witnessedRoots.commitment
|
|
729
|
+
);
|
|
730
|
+
state.stateRoot = stateProofResult.stateRoot;
|
|
731
|
+
state.pendingSTBatches.commitment = stateProofResult.pendingSTBatchesHash;
|
|
732
|
+
state.witnessedRoots.commitment = stateProofResult.witnessedRootsHash;
|
|
733
|
+
|
|
734
|
+
state.blockNumber = blockIndex.add(1);
|
|
186
735
|
|
|
187
736
|
return new BlockProverPublicOutput({
|
|
188
|
-
|
|
189
|
-
|
|
737
|
+
...BlockProverStateCommitments.fromBlockProverState(state),
|
|
738
|
+
closed: Bool(true),
|
|
190
739
|
});
|
|
191
740
|
}
|
|
192
741
|
|
|
193
742
|
@provableMethod()
|
|
194
|
-
public merge(
|
|
743
|
+
public async merge(
|
|
195
744
|
publicInput: BlockProverPublicInput,
|
|
196
745
|
proof1: BlockProverProof,
|
|
197
746
|
proof2: BlockProverProof
|
|
198
|
-
): BlockProverPublicOutput {
|
|
747
|
+
): Promise<BlockProverPublicOutput> {
|
|
199
748
|
proof1.verify();
|
|
200
749
|
proof2.verify();
|
|
201
750
|
|
|
@@ -209,19 +758,144 @@ export class BlockProver
|
|
|
209
758
|
errors.stateRootNotMatching("proof1.to -> proof2.from")
|
|
210
759
|
);
|
|
211
760
|
|
|
212
|
-
// Check transaction list
|
|
213
|
-
|
|
214
|
-
|
|
761
|
+
// Check transaction list hash.
|
|
762
|
+
// Only assert them if these are tx proofs, skip for closed proofs
|
|
763
|
+
publicInput.transactionsHash
|
|
764
|
+
.equals(proof1.publicInput.transactionsHash)
|
|
765
|
+
.or(proof1.publicOutput.closed)
|
|
766
|
+
.assertTrue(
|
|
767
|
+
errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
|
|
768
|
+
);
|
|
769
|
+
proof1.publicOutput.transactionsHash
|
|
770
|
+
.equals(proof2.publicInput.transactionsHash)
|
|
771
|
+
.or(proof1.publicOutput.closed)
|
|
772
|
+
.assertTrue(
|
|
773
|
+
errors.transactionsHashNotMatching("proof1.to -> proof2.from")
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
// Check networkhash
|
|
777
|
+
publicInput.networkStateHash.assertEquals(
|
|
778
|
+
proof1.publicInput.networkStateHash,
|
|
779
|
+
errors.networkStateHashNotMatching("publicInput.from -> proof1.from")
|
|
780
|
+
);
|
|
781
|
+
proof1.publicOutput.networkStateHash.assertEquals(
|
|
782
|
+
proof2.publicInput.networkStateHash,
|
|
783
|
+
errors.networkStateHashNotMatching("proof1.to -> proof2.from")
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
// Check blockHashRoot
|
|
787
|
+
publicInput.blockHashRoot.assertEquals(
|
|
788
|
+
proof1.publicInput.blockHashRoot,
|
|
215
789
|
errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
|
|
216
790
|
);
|
|
217
|
-
proof1.publicOutput.
|
|
218
|
-
proof2.publicInput.
|
|
791
|
+
proof1.publicOutput.blockHashRoot.assertEquals(
|
|
792
|
+
proof2.publicInput.blockHashRoot,
|
|
219
793
|
errors.transactionsHashNotMatching("proof1.to -> proof2.from")
|
|
220
794
|
);
|
|
221
795
|
|
|
796
|
+
// Check eternalTransactionsHash
|
|
797
|
+
publicInput.eternalTransactionsHash.assertEquals(
|
|
798
|
+
proof1.publicInput.eternalTransactionsHash,
|
|
799
|
+
errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
|
|
800
|
+
);
|
|
801
|
+
proof1.publicOutput.eternalTransactionsHash.assertEquals(
|
|
802
|
+
proof2.publicInput.eternalTransactionsHash,
|
|
803
|
+
errors.transactionsHashNotMatching("proof1.to -> proof2.from")
|
|
804
|
+
);
|
|
805
|
+
|
|
806
|
+
// Check incomingMessagesHash
|
|
807
|
+
publicInput.incomingMessagesHash.assertEquals(
|
|
808
|
+
proof1.publicInput.incomingMessagesHash,
|
|
809
|
+
errors.propertyNotMatchingStep(
|
|
810
|
+
"IncomingMessagesHash",
|
|
811
|
+
"publicInput.from -> proof1.from"
|
|
812
|
+
)
|
|
813
|
+
);
|
|
814
|
+
proof1.publicOutput.incomingMessagesHash.assertEquals(
|
|
815
|
+
proof2.publicInput.incomingMessagesHash,
|
|
816
|
+
errors.propertyNotMatchingStep(
|
|
817
|
+
"IncomingMessagesHash",
|
|
818
|
+
"proof1.to -> proof2.from"
|
|
819
|
+
)
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
// Check pendingSTBatchesHash
|
|
823
|
+
publicInput.pendingSTBatchesHash.assertEquals(
|
|
824
|
+
proof1.publicInput.pendingSTBatchesHash,
|
|
825
|
+
errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
|
|
826
|
+
);
|
|
827
|
+
proof1.publicOutput.pendingSTBatchesHash.assertEquals(
|
|
828
|
+
proof2.publicInput.pendingSTBatchesHash,
|
|
829
|
+
errors.transactionsHashNotMatching("proof1.to -> proof2.from")
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
// Check witnessedRootsHash
|
|
833
|
+
publicInput.witnessedRootsHash.assertEquals(
|
|
834
|
+
proof1.publicInput.witnessedRootsHash,
|
|
835
|
+
errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
|
|
836
|
+
);
|
|
837
|
+
proof1.publicOutput.witnessedRootsHash.assertEquals(
|
|
838
|
+
proof2.publicInput.witnessedRootsHash,
|
|
839
|
+
errors.transactionsHashNotMatching("proof1.to -> proof2.from")
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
// Assert closed indicator matches
|
|
843
|
+
// (i.e. we can only merge TX-Type and Block-Type with each other)
|
|
844
|
+
proof1.publicOutput.closed.assertEquals(
|
|
845
|
+
proof2.publicOutput.closed,
|
|
846
|
+
"Closed indicators not matching"
|
|
847
|
+
);
|
|
848
|
+
|
|
849
|
+
// Either
|
|
850
|
+
// blockNumbers are unset and proofs are unclosed or
|
|
851
|
+
// both blocks are closed, then they have to increment or
|
|
852
|
+
// one block is closed, then height has to be the same
|
|
853
|
+
|
|
854
|
+
// Imperative algo would look like
|
|
855
|
+
// if(proof1.height == MAX && proof2.height == MAX){
|
|
856
|
+
// assert !proof1.closed && !proof2.closed;
|
|
857
|
+
// }else if(proof1.closed && proof2.closed){
|
|
858
|
+
// assert proof1.height + 1 == proof2.height
|
|
859
|
+
// // next one is omitted for now
|
|
860
|
+
// }else if(proof1.closed || proof2.closed{
|
|
861
|
+
// assert proof1.height == proof2.height
|
|
862
|
+
// }
|
|
863
|
+
|
|
864
|
+
const proof1Closed = proof1.publicOutput.closed;
|
|
865
|
+
const proof2Closed = proof2.publicOutput.closed;
|
|
866
|
+
|
|
867
|
+
const blockNumberProgressionValid = publicInput.blockNumber
|
|
868
|
+
.equals(proof1.publicInput.blockNumber)
|
|
869
|
+
.and(
|
|
870
|
+
proof1.publicOutput.blockNumber.equals(proof2.publicInput.blockNumber)
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
// For tx proofs, we check that the progression starts and end with MAX
|
|
874
|
+
// in addition to that both proofs are non-closed
|
|
875
|
+
const isValidTransactionMerge = publicInput.blockNumber
|
|
876
|
+
.equals(MAX_FIELD)
|
|
877
|
+
.and(blockNumberProgressionValid)
|
|
878
|
+
.and(proof1Closed.or(proof2Closed).not());
|
|
879
|
+
|
|
880
|
+
const isValidClosedMerge = proof1Closed
|
|
881
|
+
.and(proof2Closed)
|
|
882
|
+
.and(blockNumberProgressionValid);
|
|
883
|
+
|
|
884
|
+
isValidTransactionMerge
|
|
885
|
+
.or(isValidClosedMerge)
|
|
886
|
+
.assertTrue("Invalid BlockProof merge");
|
|
887
|
+
|
|
222
888
|
return new BlockProverPublicOutput({
|
|
223
889
|
stateRoot: proof2.publicOutput.stateRoot,
|
|
224
890
|
transactionsHash: proof2.publicOutput.transactionsHash,
|
|
891
|
+
networkStateHash: proof2.publicOutput.networkStateHash,
|
|
892
|
+
blockHashRoot: proof2.publicOutput.blockHashRoot,
|
|
893
|
+
eternalTransactionsHash: proof2.publicOutput.eternalTransactionsHash,
|
|
894
|
+
incomingMessagesHash: proof2.publicOutput.incomingMessagesHash,
|
|
895
|
+
closed: isValidClosedMerge,
|
|
896
|
+
blockNumber: proof2.publicOutput.blockNumber,
|
|
897
|
+
pendingSTBatchesHash: proof2.publicOutput.pendingSTBatchesHash,
|
|
898
|
+
witnessedRootsHash: proof2.publicOutput.witnessedRootsHash,
|
|
225
899
|
});
|
|
226
900
|
}
|
|
227
901
|
|
|
@@ -233,53 +907,103 @@ export class BlockProver
|
|
|
233
907
|
public zkProgramFactory(): PlainZkProgram<
|
|
234
908
|
BlockProverPublicInput,
|
|
235
909
|
BlockProverPublicOutput
|
|
236
|
-
> {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
const merge =
|
|
910
|
+
>[] {
|
|
911
|
+
const { prover, stateTransitionProver } = this;
|
|
912
|
+
const StateTransitionProofClass = stateTransitionProver.zkProgram[0].Proof;
|
|
913
|
+
const proveTransaction = prover.proveTransaction.bind(prover);
|
|
914
|
+
const proveTransactions = prover.proveTransactions.bind(prover);
|
|
915
|
+
const proveBlock = prover.proveBlock.bind(prover);
|
|
916
|
+
const merge = prover.merge.bind(prover);
|
|
243
917
|
|
|
244
|
-
const program =
|
|
918
|
+
const program = ZkProgram({
|
|
919
|
+
name: "BlockProver",
|
|
245
920
|
publicInput: BlockProverPublicInput,
|
|
246
921
|
publicOutput: BlockProverPublicOutput,
|
|
247
922
|
|
|
248
923
|
methods: {
|
|
249
924
|
proveTransaction: {
|
|
250
925
|
privateInputs: [
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
926
|
+
DynamicRuntimeProof,
|
|
927
|
+
BlockProverSingleTransactionExecutionData,
|
|
928
|
+
],
|
|
929
|
+
|
|
930
|
+
async method(
|
|
931
|
+
publicInput: BlockProverPublicInput,
|
|
932
|
+
runtimeProof: DynamicRuntimeProof,
|
|
933
|
+
executionData: BlockProverSingleTransactionExecutionData
|
|
934
|
+
) {
|
|
935
|
+
return await proveTransaction(
|
|
936
|
+
publicInput,
|
|
937
|
+
runtimeProof,
|
|
938
|
+
executionData
|
|
939
|
+
);
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
|
|
943
|
+
proveTransactions: {
|
|
944
|
+
privateInputs: [
|
|
945
|
+
DynamicRuntimeProof,
|
|
946
|
+
DynamicRuntimeProof,
|
|
947
|
+
BlockProverMultiTransactionExecutionData,
|
|
254
948
|
],
|
|
255
949
|
|
|
256
|
-
method(
|
|
950
|
+
async method(
|
|
257
951
|
publicInput: BlockProverPublicInput,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
executionData:
|
|
952
|
+
runtimeProof1: DynamicRuntimeProof,
|
|
953
|
+
runtimeProof2: DynamicRuntimeProof,
|
|
954
|
+
executionData: BlockProverMultiTransactionExecutionData
|
|
261
955
|
) {
|
|
262
|
-
return
|
|
956
|
+
return await proveTransactions(
|
|
263
957
|
publicInput,
|
|
264
|
-
|
|
265
|
-
|
|
958
|
+
runtimeProof1,
|
|
959
|
+
runtimeProof2,
|
|
266
960
|
executionData
|
|
267
961
|
);
|
|
268
962
|
},
|
|
269
963
|
},
|
|
270
964
|
|
|
965
|
+
proveBlock: {
|
|
966
|
+
privateInputs: [
|
|
967
|
+
NetworkState,
|
|
968
|
+
BlockHashMerkleTreeWitness,
|
|
969
|
+
StateTransitionProofClass,
|
|
970
|
+
Bool,
|
|
971
|
+
WitnessedRootWitness,
|
|
972
|
+
SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
|
|
973
|
+
],
|
|
974
|
+
async method(
|
|
975
|
+
publicInput: BlockProverPublicInput,
|
|
976
|
+
networkState: NetworkState,
|
|
977
|
+
blockWitness: BlockHashMerkleTreeWitness,
|
|
978
|
+
stateTransitionProof: StateTransitionProof,
|
|
979
|
+
deferSTs: Bool,
|
|
980
|
+
afterBlockRootWitness: WitnessedRootWitness,
|
|
981
|
+
transactionProof: BlockProverProof
|
|
982
|
+
) {
|
|
983
|
+
return await proveBlock(
|
|
984
|
+
publicInput,
|
|
985
|
+
networkState,
|
|
986
|
+
blockWitness,
|
|
987
|
+
stateTransitionProof,
|
|
988
|
+
deferSTs,
|
|
989
|
+
afterBlockRootWitness,
|
|
990
|
+
transactionProof
|
|
991
|
+
);
|
|
992
|
+
},
|
|
993
|
+
},
|
|
994
|
+
|
|
271
995
|
merge: {
|
|
272
996
|
privateInputs: [
|
|
273
997
|
SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
|
|
274
998
|
SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
|
|
275
999
|
],
|
|
276
1000
|
|
|
277
|
-
method(
|
|
1001
|
+
async method(
|
|
278
1002
|
publicInput: BlockProverPublicInput,
|
|
279
1003
|
proof1: BlockProverProof,
|
|
280
1004
|
proof2: BlockProverProof
|
|
281
1005
|
) {
|
|
282
|
-
return merge(publicInput, proof1, proof2);
|
|
1006
|
+
return await merge(publicInput, proof1, proof2);
|
|
283
1007
|
},
|
|
284
1008
|
},
|
|
285
1009
|
},
|
|
@@ -287,16 +1011,128 @@ export class BlockProver
|
|
|
287
1011
|
|
|
288
1012
|
const methods = {
|
|
289
1013
|
proveTransaction: program.proveTransaction,
|
|
1014
|
+
proveTransactions: program.proveTransactions,
|
|
1015
|
+
proveBlock: program.proveBlock,
|
|
290
1016
|
merge: program.merge,
|
|
291
1017
|
};
|
|
292
1018
|
|
|
293
|
-
const SelfProofClass =
|
|
1019
|
+
const SelfProofClass = ZkProgram.Proof(program);
|
|
294
1020
|
|
|
295
|
-
return
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
1021
|
+
return [
|
|
1022
|
+
{
|
|
1023
|
+
name: program.name,
|
|
1024
|
+
compile: program.compile.bind(program),
|
|
1025
|
+
verify: program.verify.bind(program),
|
|
1026
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
1027
|
+
Proof: SelfProofClass,
|
|
1028
|
+
methods,
|
|
1029
|
+
},
|
|
1030
|
+
];
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* BlockProver class, which aggregates a AppChainProof and
|
|
1036
|
+
* a StateTransitionProof into a single BlockProof, that can
|
|
1037
|
+
* then be merged to be committed to the base-layer contract
|
|
1038
|
+
*/
|
|
1039
|
+
@injectable()
|
|
1040
|
+
export class BlockProver
|
|
1041
|
+
extends ProtocolModule
|
|
1042
|
+
implements BlockProvable, CompilableModule
|
|
1043
|
+
{
|
|
1044
|
+
public zkProgrammable: BlockProverProgrammable;
|
|
1045
|
+
|
|
1046
|
+
public constructor(
|
|
1047
|
+
@inject("StateTransitionProver")
|
|
1048
|
+
public readonly stateTransitionProver: WithZkProgrammable<
|
|
1049
|
+
StateTransitionProverPublicInput,
|
|
1050
|
+
StateTransitionProverPublicOutput
|
|
1051
|
+
> &
|
|
1052
|
+
StateTransitionProvable,
|
|
1053
|
+
@inject("Runtime")
|
|
1054
|
+
public readonly runtime: WithZkProgrammable<undefined, MethodPublicOutput> &
|
|
1055
|
+
CompilableModule,
|
|
1056
|
+
@injectAll("ProvableTransactionHook")
|
|
1057
|
+
transactionHooks: ProvableTransactionHook<unknown>[],
|
|
1058
|
+
@injectAll("ProvableBlockHook")
|
|
1059
|
+
blockHooks: ProvableBlockHook<unknown>[],
|
|
1060
|
+
@inject("StateServiceProvider")
|
|
1061
|
+
stateServiceProvider: StateServiceProvider,
|
|
1062
|
+
verificationKeyService: RuntimeVerificationKeyRootService
|
|
1063
|
+
) {
|
|
1064
|
+
super();
|
|
1065
|
+
this.zkProgrammable = new BlockProverProgrammable(
|
|
1066
|
+
this,
|
|
1067
|
+
stateTransitionProver.zkProgrammable,
|
|
1068
|
+
transactionHooks,
|
|
1069
|
+
blockHooks,
|
|
1070
|
+
stateServiceProvider,
|
|
1071
|
+
verificationKeyService
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
public async compile(
|
|
1076
|
+
registry: CompileRegistry
|
|
1077
|
+
): Promise<Record<string, CompileArtifact> | undefined> {
|
|
1078
|
+
return await registry.forceProverExists(async () => {
|
|
1079
|
+
await this.stateTransitionProver.compile(registry);
|
|
1080
|
+
await this.runtime.compile(registry);
|
|
1081
|
+
return await this.zkProgrammable.compile(registry);
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
public proveTransaction(
|
|
1086
|
+
publicInput: BlockProverPublicInput,
|
|
1087
|
+
runtimeProof: DynamicRuntimeProof,
|
|
1088
|
+
executionData: BlockProverSingleTransactionExecutionData
|
|
1089
|
+
): Promise<BlockProverPublicOutput> {
|
|
1090
|
+
return this.zkProgrammable.proveTransaction(
|
|
1091
|
+
publicInput,
|
|
1092
|
+
runtimeProof,
|
|
1093
|
+
executionData
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
public proveTransactions(
|
|
1098
|
+
publicInput: BlockProverPublicInput,
|
|
1099
|
+
runtimeProof1: DynamicRuntimeProof,
|
|
1100
|
+
runtimeProof2: DynamicRuntimeProof,
|
|
1101
|
+
executionData: BlockProverMultiTransactionExecutionData
|
|
1102
|
+
): Promise<BlockProverPublicOutput> {
|
|
1103
|
+
return this.zkProgrammable.proveTransactions(
|
|
1104
|
+
publicInput,
|
|
1105
|
+
runtimeProof1,
|
|
1106
|
+
runtimeProof2,
|
|
1107
|
+
executionData
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
public proveBlock(
|
|
1112
|
+
publicInput: BlockProverPublicInput,
|
|
1113
|
+
networkState: NetworkState,
|
|
1114
|
+
blockWitness: BlockHashMerkleTreeWitness,
|
|
1115
|
+
stateTransitionProof: StateTransitionProof,
|
|
1116
|
+
deferSTs: Bool,
|
|
1117
|
+
afterBlockRootWitness: WitnessedRootWitness,
|
|
1118
|
+
transactionProof: BlockProverProof
|
|
1119
|
+
): Promise<BlockProverPublicOutput> {
|
|
1120
|
+
return this.zkProgrammable.proveBlock(
|
|
1121
|
+
publicInput,
|
|
1122
|
+
networkState,
|
|
1123
|
+
blockWitness,
|
|
1124
|
+
stateTransitionProof,
|
|
1125
|
+
deferSTs,
|
|
1126
|
+
afterBlockRootWitness,
|
|
1127
|
+
transactionProof
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
public merge(
|
|
1132
|
+
publicInput: BlockProverPublicInput,
|
|
1133
|
+
proof1: BlockProverProof,
|
|
1134
|
+
proof2: BlockProverProof
|
|
1135
|
+
): Promise<BlockProverPublicOutput> {
|
|
1136
|
+
return this.zkProgrammable.merge(publicInput, proof1, proof2);
|
|
301
1137
|
}
|
|
302
1138
|
}
|