@proto-kit/protocol 0.1.1-develop.190 → 0.1.1-develop.2024
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 +56 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -0
- package/dist/hooks/AccountStateHook.js +62 -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 +59 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -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 -28
- 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 -46
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +62 -57
- 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 +58 -18
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +13 -4
- 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 +87 -10
- 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 +22 -2
- package/dist/model/network/NetworkState.js.map +1 -0
- package/dist/model/transaction/AuthorizedTransaction.d.ts +122 -0
- package/dist/model/transaction/AuthorizedTransaction.d.ts.map +1 -0
- package/dist/model/transaction/AuthorizedTransaction.js +39 -0
- package/dist/model/transaction/AuthorizedTransaction.js.map +1 -0
- package/dist/model/transaction/RuntimeTransaction.d.ts +94 -34
- package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
- package/dist/model/transaction/RuntimeTransaction.js +72 -11
- package/dist/model/transaction/RuntimeTransaction.js.map +1 -0
- package/dist/model/transaction/SignedTransaction.d.ts +110 -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 +187 -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 +47 -21
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +127 -26
- 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 +29 -0
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
- package/dist/protocol/ProvableBlockHook.js +20 -0
- package/dist/protocol/ProvableBlockHook.js.map +1 -0
- package/dist/protocol/ProvableTransactionHook.d.ts +35 -0
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -0
- package/dist/protocol/ProvableTransactionHook.js +28 -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/BlockHashList.d.ts +263 -0
- package/dist/prover/accumulators/BlockHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/BlockHashList.js +97 -0
- package/dist/prover/accumulators/BlockHashList.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 +123 -0
- package/dist/prover/accumulators/WitnessedRootHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js +51 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js.map +1 -0
- package/dist/prover/block/BlockProvable.d.ts +565 -96
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +196 -12
- package/dist/prover/block/BlockProvable.js.map +1 -0
- package/dist/prover/block/BlockProver.d.ts +52 -37
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +327 -107
- 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 +29 -17
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +171 -73
- package/dist/prover/statetransition/StateTransitionProver.js.map +1 -0
- package/dist/prover/transaction/TransactionProvable.d.ts +626 -0
- package/dist/prover/transaction/TransactionProvable.d.ts.map +1 -0
- package/dist/prover/transaction/TransactionProvable.js +87 -0
- package/dist/prover/transaction/TransactionProvable.js.map +1 -0
- package/dist/prover/transaction/TransactionProver.d.ts +68 -0
- package/dist/prover/transaction/TransactionProver.d.ts.map +1 -0
- package/dist/prover/transaction/TransactionProver.js +301 -0
- package/dist/prover/transaction/TransactionProver.js.map +1 -0
- package/dist/prover/utils.d.ts +19 -0
- package/dist/prover/utils.d.ts.map +1 -0
- package/dist/prover/utils.js +67 -0
- package/dist/prover/utils.js.map +1 -0
- package/dist/settlement/ContractArgsRegistry.d.ts +13 -0
- package/dist/settlement/ContractArgsRegistry.d.ts.map +1 -0
- package/dist/settlement/ContractArgsRegistry.js +53 -0
- package/dist/settlement/ContractArgsRegistry.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 +47 -0
- package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/SettlementContractModule.js +81 -0
- package/dist/settlement/SettlementContractModule.js.map +1 -0
- package/dist/settlement/contracts/BridgeContract.d.ts +119 -0
- package/dist/settlement/contracts/BridgeContract.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContract.js +269 -0
- package/dist/settlement/contracts/BridgeContract.js.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts +18 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js +42 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/BridgingSettlementContractModule.d.ts +21 -0
- package/dist/settlement/contracts/BridgingSettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgingSettlementContractModule.js +81 -0
- package/dist/settlement/contracts/BridgingSettlementContractModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +23 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js +55 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts +50 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.js +234 -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/SettlementSmartContractModule.d.ts +20 -0
- package/dist/settlement/contracts/SettlementSmartContractModule.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContractModule.js +56 -0
- package/dist/settlement/contracts/SettlementSmartContractModule.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/contracts/settlement/BridgingSettlementContract.d.ts +107 -0
- package/dist/settlement/contracts/settlement/BridgingSettlementContract.d.ts.map +1 -0
- package/dist/settlement/contracts/settlement/BridgingSettlementContract.js +188 -0
- package/dist/settlement/contracts/settlement/BridgingSettlementContract.js.map +1 -0
- package/dist/settlement/contracts/settlement/SettlementBase.d.ts +41 -0
- package/dist/settlement/contracts/settlement/SettlementBase.d.ts.map +1 -0
- package/dist/settlement/contracts/settlement/SettlementBase.js +105 -0
- package/dist/settlement/contracts/settlement/SettlementBase.js.map +1 -0
- package/dist/settlement/contracts/settlement/SettlementContract.d.ts +15 -0
- package/dist/settlement/contracts/settlement/SettlementContract.d.ts.map +1 -0
- package/dist/settlement/contracts/settlement/SettlementContract.js +72 -0
- package/dist/settlement/contracts/settlement/SettlementContract.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 +494 -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 +9 -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 +141 -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/WitnessBlockContext.d.ts +5 -0
- package/dist/state/WitnessBlockContext.d.ts.map +1 -0
- package/dist/state/WitnessBlockContext.js +42 -0
- package/dist/state/WitnessBlockContext.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 +20 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.js +49 -0
- package/dist/utils/MinaPrefixedProvableHashList.js.map +1 -0
- package/dist/utils/PrefixedProvableHashList.d.ts +3 -2
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/PrefixedProvableHashList.js +5 -1
- package/dist/utils/PrefixedProvableHashList.js.map +1 -0
- package/dist/utils/ProvableHashList.d.ts +27 -4
- package/dist/utils/ProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableHashList.js +51 -3
- 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 +11 -5
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +13 -13
- 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 +80 -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 +59 -9
- package/src/model/AppliedStateTransitionBatch.ts +16 -0
- package/src/model/MethodPublicOutput.ts +3 -1
- package/src/model/Option.ts +99 -73
- package/src/model/Path.ts +9 -5
- package/src/model/RuntimeLike.ts +12 -0
- package/src/model/StateTransition.ts +19 -5
- package/src/model/StateTransitionProvableBatch.ts +114 -12
- package/src/model/Transaction.ts +3 -1
- package/src/model/network/NetworkState.ts +22 -2
- package/src/model/transaction/AuthorizedTransaction.ts +50 -0
- package/src/model/transaction/RuntimeTransaction.ts +86 -15
- package/src/model/transaction/ValueOption.ts +28 -0
- package/src/protocol/Protocol.ts +201 -69
- package/src/protocol/ProtocolEnvironment.ts +10 -0
- package/src/protocol/ProtocolModule.ts +16 -15
- package/src/protocol/ProvableBlockHook.ts +67 -0
- package/src/protocol/ProvableTransactionHook.ts +96 -0
- package/src/protocol/TransitioningProtocolModule.ts +12 -0
- package/src/prover/accumulators/AppliedBatchHashList.ts +32 -0
- package/src/prover/accumulators/BlockHashList.ts +117 -0
- package/src/prover/accumulators/StateTransitionReductionList.ts +92 -0
- package/src/prover/accumulators/TransactionHashList.ts +9 -0
- package/src/prover/accumulators/WitnessedRootHashList.ts +62 -0
- package/src/prover/block/BlockProvable.ts +360 -28
- package/src/prover/block/BlockProver.ts +721 -186
- 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 +337 -126
- package/src/prover/transaction/TransactionProvable.ts +183 -0
- package/src/prover/transaction/TransactionProver.ts +561 -0
- package/src/prover/utils.ts +108 -0
- package/src/settlement/ContractArgsRegistry.ts +60 -0
- package/src/settlement/ContractModule.ts +31 -0
- package/src/settlement/SettlementContractModule.ts +150 -0
- package/src/settlement/contracts/BridgeContract.ts +385 -0
- package/src/settlement/contracts/BridgeContractProtocolModule.ts +49 -0
- package/src/settlement/contracts/BridgingSettlementContractModule.ts +116 -0
- package/src/settlement/contracts/DispatchContractProtocolModule.ts +77 -0
- package/src/settlement/contracts/DispatchSmartContract.ts +359 -0
- package/src/settlement/contracts/SettlementSmartContractModule.ts +79 -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/contracts/settlement/BridgingSettlementContract.ts +283 -0
- package/src/settlement/contracts/settlement/SettlementBase.ts +249 -0
- package/src/settlement/contracts/settlement/SettlementContract.ts +75 -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 +23 -0
- package/src/settlement/modules/NetworkStateSettlementModule.ts +42 -0
- package/src/state/State.ts +190 -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/WitnessBlockContext.ts +50 -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 +70 -0
- package/src/utils/PrefixedProvableHashList.ts +6 -2
- package/src/utils/ProvableHashList.ts +109 -4
- package/src/utils/ProvableReductionHashList.ts +77 -0
- package/src/utils/utils.ts +21 -16
- 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 +36 -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 +0 -3
- package/LICENSE.md +0 -201
- 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/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/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/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 -255
- package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
- package/tsconfig.test.json +0 -9
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { inject, injectable, injectAll } from "tsyringe";
|
|
2
|
+
import {
|
|
3
|
+
ArtifactRecord,
|
|
4
|
+
ChildVerificationKeyService,
|
|
5
|
+
CompileRegistry,
|
|
6
|
+
log,
|
|
7
|
+
} from "@proto-kit/common";
|
|
8
|
+
|
|
9
|
+
import { BlockProvable } from "../../prover/block/BlockProvable";
|
|
10
|
+
import {
|
|
11
|
+
ContractModule,
|
|
12
|
+
SmartContractClassFromInterface,
|
|
13
|
+
} from "../ContractModule";
|
|
14
|
+
import { ProvableSettlementHook } from "../modularity/ProvableSettlementHook";
|
|
15
|
+
import { ContractArgsRegistry } from "../ContractArgsRegistry";
|
|
16
|
+
|
|
17
|
+
import { DispatchContractArgs } from "./DispatchSmartContract";
|
|
18
|
+
import {
|
|
19
|
+
BridgingSettlementContractType,
|
|
20
|
+
BridgingSettlementContract,
|
|
21
|
+
BridgingSettlementContractArgs,
|
|
22
|
+
} from "./settlement/BridgingSettlementContract";
|
|
23
|
+
import { BridgeContractArgs } from "./BridgeContract";
|
|
24
|
+
import { DispatchContractProtocolModule } from "./DispatchContractProtocolModule";
|
|
25
|
+
import { BridgeContractProtocolModule } from "./BridgeContractProtocolModule";
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_ESCAPE_HATCH,
|
|
28
|
+
SettlementContractConfig,
|
|
29
|
+
} from "./SettlementSmartContractModule";
|
|
30
|
+
import { SettlementContract } from "./settlement/SettlementContract";
|
|
31
|
+
|
|
32
|
+
@injectable()
|
|
33
|
+
export class BridgingSettlementContractModule extends ContractModule<
|
|
34
|
+
BridgingSettlementContractType,
|
|
35
|
+
SettlementContractConfig
|
|
36
|
+
> {
|
|
37
|
+
public constructor(
|
|
38
|
+
@injectAll("ProvableSettlementHook")
|
|
39
|
+
private readonly hooks: ProvableSettlementHook<unknown>[],
|
|
40
|
+
@inject("BlockProver")
|
|
41
|
+
private readonly blockProver: BlockProvable,
|
|
42
|
+
@inject("DispatchContract")
|
|
43
|
+
private readonly dispatchContractModule: DispatchContractProtocolModule,
|
|
44
|
+
@inject("BridgeContract")
|
|
45
|
+
private readonly bridgeContractModule: BridgeContractProtocolModule,
|
|
46
|
+
private readonly childVerificationKeyService: ChildVerificationKeyService,
|
|
47
|
+
private readonly argsRegistry: ContractArgsRegistry
|
|
48
|
+
) {
|
|
49
|
+
super();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public contractFactory(): SmartContractClassFromInterface<BridgingSettlementContractType> {
|
|
53
|
+
const { hooks, config } = this;
|
|
54
|
+
const dispatchContract = this.dispatchContractModule.contractFactory();
|
|
55
|
+
const bridgeContract = this.bridgeContractModule.contractFactory();
|
|
56
|
+
|
|
57
|
+
const escapeHatchSlotsInterval =
|
|
58
|
+
config.escapeHatchSlotsInterval ?? DEFAULT_ESCAPE_HATCH;
|
|
59
|
+
|
|
60
|
+
this.argsRegistry.addArgs<BridgingSettlementContractArgs>(
|
|
61
|
+
"SettlementContract",
|
|
62
|
+
{
|
|
63
|
+
DispatchContract: dispatchContract,
|
|
64
|
+
hooks,
|
|
65
|
+
escapeHatchSlotsInterval,
|
|
66
|
+
BridgeContract: bridgeContract,
|
|
67
|
+
ChildVerificationKeyService: this.childVerificationKeyService,
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Ideally, we don't want to have this cyclic dependency, but we have it in the protocol,
|
|
72
|
+
// So it's logical that we can't avoid that here
|
|
73
|
+
this.argsRegistry.addArgs<BridgeContractArgs>("BridgeContract", {
|
|
74
|
+
SettlementContract: BridgingSettlementContract,
|
|
75
|
+
});
|
|
76
|
+
this.argsRegistry.addArgs<DispatchContractArgs>("DispatchContract", {
|
|
77
|
+
settlementContractClass: BridgingSettlementContract,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return BridgingSettlementContract;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public async compile(
|
|
84
|
+
registry: CompileRegistry
|
|
85
|
+
): Promise<ArtifactRecord | undefined> {
|
|
86
|
+
// Dependencies
|
|
87
|
+
const bridgeArtifact = await this.bridgeContractModule.compile(registry);
|
|
88
|
+
|
|
89
|
+
await this.blockProver.compile(registry);
|
|
90
|
+
|
|
91
|
+
this.contractFactory();
|
|
92
|
+
|
|
93
|
+
// Init params
|
|
94
|
+
this.argsRegistry.addArgs<BridgingSettlementContractArgs>(
|
|
95
|
+
"SettlementContract",
|
|
96
|
+
{
|
|
97
|
+
BridgeContractVerificationKey:
|
|
98
|
+
bridgeArtifact.BridgeContract.verificationKey,
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
log.debug("Compiling Settlement Contract");
|
|
103
|
+
|
|
104
|
+
const artifact = await registry.forceProverExists(
|
|
105
|
+
async (reg) =>
|
|
106
|
+
await registry.compile(
|
|
107
|
+
BridgingSettlementContract,
|
|
108
|
+
SettlementContract.name
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
SettlementSmartContract: artifact,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { inject, injectable } from "tsyringe";
|
|
2
|
+
import { PublicKey } from "o1js";
|
|
3
|
+
import { CompileRegistry } from "@proto-kit/common";
|
|
4
|
+
|
|
5
|
+
import { RuntimeLike, RuntimeMethodIdMapping } from "../../model/RuntimeLike";
|
|
6
|
+
import {
|
|
7
|
+
ContractModule,
|
|
8
|
+
SmartContractClassFromInterface,
|
|
9
|
+
} from "../ContractModule";
|
|
10
|
+
import { ContractArgsRegistry } from "../ContractArgsRegistry";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
DispatchSmartContract,
|
|
14
|
+
DispatchContractType,
|
|
15
|
+
DispatchContractArgs,
|
|
16
|
+
} from "./DispatchSmartContract";
|
|
17
|
+
|
|
18
|
+
export type DispatchContractConfig = {
|
|
19
|
+
incomingMessagesMethods: Record<string, `${string}.${string}`>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
@injectable()
|
|
23
|
+
export class DispatchContractProtocolModule extends ContractModule<
|
|
24
|
+
DispatchContractType,
|
|
25
|
+
DispatchContractConfig
|
|
26
|
+
> {
|
|
27
|
+
public constructor(
|
|
28
|
+
@inject("Runtime") private readonly runtime: RuntimeLike,
|
|
29
|
+
private readonly contractArgsRegistry: ContractArgsRegistry
|
|
30
|
+
) {
|
|
31
|
+
super();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public eventsDefinition() {
|
|
35
|
+
return new DispatchSmartContract(PublicKey.empty<typeof PublicKey>())
|
|
36
|
+
.events;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private checkConfigIntegrity(
|
|
40
|
+
incomingMessagesMethods: Record<string, `${string}.${string}`>,
|
|
41
|
+
runtimeMethodIds: RuntimeMethodIdMapping
|
|
42
|
+
) {
|
|
43
|
+
const missing = Object.values(incomingMessagesMethods).filter(
|
|
44
|
+
(method) => runtimeMethodIds[method] === undefined
|
|
45
|
+
);
|
|
46
|
+
if (missing.length > 0) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Incoming messages config references a unknown methods: [${missing}]`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public contractFactory(): SmartContractClassFromInterface<DispatchContractType> {
|
|
54
|
+
const { incomingMessagesMethods } = this.config;
|
|
55
|
+
const methodIdMappings = this.runtime.methodIdResolver.methodIdMap();
|
|
56
|
+
|
|
57
|
+
this.checkConfigIntegrity(incomingMessagesMethods, methodIdMappings);
|
|
58
|
+
|
|
59
|
+
this.contractArgsRegistry.addArgs<DispatchContractArgs>(
|
|
60
|
+
"DispatchContract",
|
|
61
|
+
{
|
|
62
|
+
incomingMessagesPaths: incomingMessagesMethods,
|
|
63
|
+
methodIdMappings,
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return DispatchSmartContract;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async compile(registry: CompileRegistry) {
|
|
71
|
+
return {
|
|
72
|
+
DispatchSmartContract: await registry.forceProverExists(
|
|
73
|
+
async () => await registry.compile(DispatchSmartContract)
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountUpdate,
|
|
3
|
+
Bool,
|
|
4
|
+
DeployArgs,
|
|
5
|
+
Field,
|
|
6
|
+
method,
|
|
7
|
+
Poseidon,
|
|
8
|
+
Provable,
|
|
9
|
+
ProvableExtended,
|
|
10
|
+
PublicKey,
|
|
11
|
+
Reducer,
|
|
12
|
+
SmartContract,
|
|
13
|
+
State,
|
|
14
|
+
state,
|
|
15
|
+
TokenId,
|
|
16
|
+
UInt64,
|
|
17
|
+
Permissions,
|
|
18
|
+
} from "o1js";
|
|
19
|
+
import { InMemoryMerkleTreeStorage, TypedClass } from "@proto-kit/common";
|
|
20
|
+
import { container } from "tsyringe";
|
|
21
|
+
|
|
22
|
+
import { RuntimeMethodIdMapping } from "../../model/RuntimeLike";
|
|
23
|
+
import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
|
|
24
|
+
import {
|
|
25
|
+
MinaActions,
|
|
26
|
+
MinaEvents,
|
|
27
|
+
} from "../../utils/MinaPrefixedProvableHashList";
|
|
28
|
+
import { Deposit } from "../messages/Deposit";
|
|
29
|
+
import {
|
|
30
|
+
ContractArgsRegistry,
|
|
31
|
+
NaiveObjectSchema,
|
|
32
|
+
StaticInitializationContract,
|
|
33
|
+
} from "../ContractArgsRegistry";
|
|
34
|
+
|
|
35
|
+
import type { BridgingSettlementContractType } from "./settlement/BridgingSettlementContract";
|
|
36
|
+
import { TokenBridgeDeploymentAuth } from "./authorizations/TokenBridgeDeploymentAuth";
|
|
37
|
+
import { UpdateMessagesHashAuth } from "./authorizations/UpdateMessagesHashAuth";
|
|
38
|
+
import {
|
|
39
|
+
TokenBridgeAttestation,
|
|
40
|
+
TokenBridgeEntry,
|
|
41
|
+
TokenBridgeTree,
|
|
42
|
+
TokenBridgeTreeAddition,
|
|
43
|
+
TokenBridgeTreeWitness,
|
|
44
|
+
} from "./TokenBridgeTree";
|
|
45
|
+
|
|
46
|
+
export const ACTIONS_EMPTY_HASH = Reducer.initialActionState;
|
|
47
|
+
|
|
48
|
+
export interface DispatchContractType {
|
|
49
|
+
events: {
|
|
50
|
+
"token-bridge-added": typeof TokenBridgeTreeAddition;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
updateMessagesHash: (
|
|
54
|
+
executedMessagesHash: Field,
|
|
55
|
+
newPromisedMessagesHash: Field
|
|
56
|
+
) => Promise<void>;
|
|
57
|
+
enableTokenDeposits: (
|
|
58
|
+
tokenId: Field,
|
|
59
|
+
bridgeContractAddress: PublicKey,
|
|
60
|
+
settlementContractAddress: PublicKey
|
|
61
|
+
) => Promise<void>;
|
|
62
|
+
|
|
63
|
+
promisedMessagesHash: State<Field>;
|
|
64
|
+
|
|
65
|
+
deployAndInitialize: (
|
|
66
|
+
args: DeployArgs | undefined,
|
|
67
|
+
permissions: Permissions,
|
|
68
|
+
settlementContract: PublicKey
|
|
69
|
+
) => Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tokenBridgeRoot = new TokenBridgeTree(
|
|
73
|
+
new InMemoryMerkleTreeStorage()
|
|
74
|
+
).getRoot();
|
|
75
|
+
|
|
76
|
+
export interface DispatchContractArgs {
|
|
77
|
+
methodIdMappings: RuntimeMethodIdMapping;
|
|
78
|
+
incomingMessagesPaths: Record<string, `${string}.${string}`>;
|
|
79
|
+
settlementContractClass: TypedClass<BridgingSettlementContractType> &
|
|
80
|
+
typeof SmartContract;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const DispatchContractArgsSchema: NaiveObjectSchema<DispatchContractArgs> =
|
|
84
|
+
{
|
|
85
|
+
incomingMessagesPaths: "Required",
|
|
86
|
+
methodIdMappings: "Required",
|
|
87
|
+
settlementContractClass: "Required",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export abstract class DispatchSmartContractBase
|
|
91
|
+
extends SmartContract
|
|
92
|
+
implements StaticInitializationContract<DispatchContractArgs>
|
|
93
|
+
{
|
|
94
|
+
events = {
|
|
95
|
+
"token-bridge-added": TokenBridgeTreeAddition,
|
|
96
|
+
// We need a placeholder event here, so that o1js internally adds a identifier to the
|
|
97
|
+
// emitted event-fields. That will lead to the o1js API being able to distinguish the
|
|
98
|
+
// TokenBridgeEvents from the manually emitted events for the incoming messages
|
|
99
|
+
"incoming-message-placeholder": Field,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
abstract promisedMessagesHash: State<Field>;
|
|
103
|
+
|
|
104
|
+
abstract honoredMessagesHash: State<Field>;
|
|
105
|
+
|
|
106
|
+
abstract settlementContract: State<PublicKey>;
|
|
107
|
+
|
|
108
|
+
abstract tokenBridgeRoot: State<Field>;
|
|
109
|
+
|
|
110
|
+
abstract tokenBridgeCount: State<Field>;
|
|
111
|
+
|
|
112
|
+
getInitializationArgs(): DispatchContractArgs {
|
|
113
|
+
return container
|
|
114
|
+
.resolve(ContractArgsRegistry)
|
|
115
|
+
.getArgs("DispatchContract", DispatchContractArgsSchema);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
protected updateMessagesHashBase(
|
|
119
|
+
executedMessagesHash: Field,
|
|
120
|
+
newPromisedMessagesHash: Field
|
|
121
|
+
) {
|
|
122
|
+
const promisedMessagesHash =
|
|
123
|
+
this.promisedMessagesHash.getAndRequireEquals();
|
|
124
|
+
this.honoredMessagesHash.getAndRequireEquals();
|
|
125
|
+
|
|
126
|
+
executedMessagesHash.assertEquals(promisedMessagesHash);
|
|
127
|
+
|
|
128
|
+
this.honoredMessagesHash.set(executedMessagesHash);
|
|
129
|
+
|
|
130
|
+
// Assert and apply new promisedMessagesHash
|
|
131
|
+
this.self.account.actionState.requireEquals(newPromisedMessagesHash);
|
|
132
|
+
this.promisedMessagesHash.set(newPromisedMessagesHash);
|
|
133
|
+
|
|
134
|
+
const args = this.getInitializationArgs();
|
|
135
|
+
const settlementContractAddress =
|
|
136
|
+
this.settlementContract.getAndRequireEquals();
|
|
137
|
+
const settlementContract = new args.settlementContractClass!(
|
|
138
|
+
settlementContractAddress
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
settlementContract.authorizationField.requireEquals(
|
|
142
|
+
new UpdateMessagesHashAuth({
|
|
143
|
+
target: this.address,
|
|
144
|
+
executedMessagesHash,
|
|
145
|
+
newPromisedMessagesHash,
|
|
146
|
+
}).hash()
|
|
147
|
+
);
|
|
148
|
+
this.approve(settlementContract.self);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected initializeBase(settlementContract: PublicKey) {
|
|
152
|
+
this.promisedMessagesHash.set(ACTIONS_EMPTY_HASH);
|
|
153
|
+
this.honoredMessagesHash.set(ACTIONS_EMPTY_HASH);
|
|
154
|
+
this.settlementContract.set(settlementContract);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected dispatchMessage<Type>(
|
|
158
|
+
methodId: Field,
|
|
159
|
+
value: Type,
|
|
160
|
+
valueType: ProvableExtended<Type>
|
|
161
|
+
) {
|
|
162
|
+
const args = valueType.toFields(value);
|
|
163
|
+
// Should be the same as RuntimeTransaction.hash
|
|
164
|
+
const argsHash = Poseidon.hash(args);
|
|
165
|
+
const runtimeTransaction = RuntimeTransaction.fromMessage({
|
|
166
|
+
methodId,
|
|
167
|
+
argsHash,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Append tx to incomingMessagesHash
|
|
171
|
+
const actionData = runtimeTransaction.hashData();
|
|
172
|
+
const actionHash = MinaActions.actionHash(actionData);
|
|
173
|
+
|
|
174
|
+
this.self.body.actions = {
|
|
175
|
+
hash: actionHash,
|
|
176
|
+
data: [actionData],
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Find event index of placeholder event that we can use for manual event dispatching
|
|
180
|
+
const eventIndex = Object.keys(this.events)
|
|
181
|
+
.sort()
|
|
182
|
+
.indexOf("incoming-message-placeholder");
|
|
183
|
+
if (eventIndex === -1) {
|
|
184
|
+
throw new Error("Unknown event type for placeholder event");
|
|
185
|
+
}
|
|
186
|
+
const paddedArgs = [Field(eventIndex), ...args];
|
|
187
|
+
|
|
188
|
+
const eventHash = MinaEvents.eventHash(paddedArgs);
|
|
189
|
+
this.self.body.events = {
|
|
190
|
+
hash: eventHash,
|
|
191
|
+
data: [paddedArgs],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
protected async enableTokenDepositsBase(
|
|
196
|
+
tokenId: Field,
|
|
197
|
+
bridgeContractAddress: PublicKey,
|
|
198
|
+
// Witness it here, since o1js doesn't fetch this state correctly since
|
|
199
|
+
// its updated in a parent AU
|
|
200
|
+
settlementContractAddress: PublicKey
|
|
201
|
+
// treeWitness: TokenBridgeTreeWitness
|
|
202
|
+
) {
|
|
203
|
+
this.settlementContract.requireEquals(settlementContractAddress);
|
|
204
|
+
const args = this.getInitializationArgs();
|
|
205
|
+
const settlementContract = new args.settlementContractClass!(
|
|
206
|
+
settlementContractAddress
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// Append bridge address to the tree
|
|
210
|
+
// TODO This not concurrent and will fail if multiple users deploy bridges at the same time
|
|
211
|
+
const counter = this.tokenBridgeCount.getAndRequireEquals();
|
|
212
|
+
const root = this.tokenBridgeRoot.getAndRequireEquals();
|
|
213
|
+
|
|
214
|
+
const treeWitness = await Provable.witnessAsync(
|
|
215
|
+
TokenBridgeTreeWitness,
|
|
216
|
+
async () => {
|
|
217
|
+
const tree = await TokenBridgeTree.buildTreeFromEvents(this);
|
|
218
|
+
return tree.getWitness(counter.toBigInt());
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
treeWitness
|
|
223
|
+
.checkMembership(root, counter, Field(0))
|
|
224
|
+
.assertTrue("Bridge Tree Witness not valid");
|
|
225
|
+
|
|
226
|
+
const entry = new TokenBridgeEntry({
|
|
227
|
+
tokenId,
|
|
228
|
+
address: bridgeContractAddress,
|
|
229
|
+
});
|
|
230
|
+
const newRoot = treeWitness.calculateRoot(entry.hash());
|
|
231
|
+
this.tokenBridgeRoot.set(newRoot);
|
|
232
|
+
this.tokenBridgeCount.set(counter.add(1));
|
|
233
|
+
|
|
234
|
+
this.emitEvent(
|
|
235
|
+
"token-bridge-added",
|
|
236
|
+
new TokenBridgeTreeAddition({
|
|
237
|
+
index: counter,
|
|
238
|
+
value: entry,
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// Authenticate call via callback
|
|
243
|
+
settlementContract.authorizationField.requireEquals(
|
|
244
|
+
new TokenBridgeDeploymentAuth({
|
|
245
|
+
target: this.address,
|
|
246
|
+
tokenId,
|
|
247
|
+
address: bridgeContractAddress,
|
|
248
|
+
}).hash()
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
this.approve(settlementContract.self);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export class DispatchSmartContract
|
|
256
|
+
extends DispatchSmartContractBase
|
|
257
|
+
implements DispatchContractType
|
|
258
|
+
{
|
|
259
|
+
@state(Field) public promisedMessagesHash = State<Field>();
|
|
260
|
+
|
|
261
|
+
@state(Field) public honoredMessagesHash = State<Field>();
|
|
262
|
+
|
|
263
|
+
@state(PublicKey) public settlementContract = State<PublicKey>();
|
|
264
|
+
|
|
265
|
+
@state(Field) public tokenBridgeRoot = State<Field>(tokenBridgeRoot);
|
|
266
|
+
|
|
267
|
+
@state(Field) public tokenBridgeCount = State<Field>();
|
|
268
|
+
|
|
269
|
+
public async deployAndInitialize(
|
|
270
|
+
args: DeployArgs | undefined,
|
|
271
|
+
permissions: Permissions,
|
|
272
|
+
settlementContract: PublicKey
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
await super.deploy(args);
|
|
275
|
+
|
|
276
|
+
this.self.account.permissions.set(permissions);
|
|
277
|
+
|
|
278
|
+
this.initializeBase(settlementContract);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@method
|
|
282
|
+
public async enableTokenDeposits(
|
|
283
|
+
tokenId: Field,
|
|
284
|
+
bridgeContractAddress: PublicKey,
|
|
285
|
+
settlementContractAddress: PublicKey
|
|
286
|
+
) {
|
|
287
|
+
await this.enableTokenDepositsBase(
|
|
288
|
+
tokenId,
|
|
289
|
+
bridgeContractAddress,
|
|
290
|
+
settlementContractAddress
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
@method
|
|
295
|
+
public async updateMessagesHash(
|
|
296
|
+
executedMessagesHash: Field,
|
|
297
|
+
newPromisedMessagesHash: Field
|
|
298
|
+
) {
|
|
299
|
+
return this.updateMessagesHashBase(
|
|
300
|
+
executedMessagesHash,
|
|
301
|
+
newPromisedMessagesHash
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
@method
|
|
306
|
+
public async deposit(
|
|
307
|
+
amount: UInt64,
|
|
308
|
+
tokenId: Field,
|
|
309
|
+
bridgingContract: PublicKey,
|
|
310
|
+
bridgingContractAttestation: TokenBridgeAttestation,
|
|
311
|
+
l2Receiver: PublicKey
|
|
312
|
+
) {
|
|
313
|
+
const childrenMayUseToken: AccountUpdate["body"]["mayUseToken"] = {
|
|
314
|
+
parentsOwnToken: Bool(false),
|
|
315
|
+
// MayUseToken has to be set only for custom tokens
|
|
316
|
+
inheritFromParent: tokenId.equals(TokenId.default).not(),
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// Check that the bridgingContract parameter is valid => is in the offchain tree
|
|
320
|
+
const bridgeTreeRoot = this.tokenBridgeRoot.getAndRequireEquals();
|
|
321
|
+
const entry = new TokenBridgeEntry({
|
|
322
|
+
tokenId,
|
|
323
|
+
address: bridgingContract,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
bridgingContractAttestation.witness
|
|
327
|
+
.checkMembership(
|
|
328
|
+
bridgeTreeRoot,
|
|
329
|
+
bridgingContractAttestation.index,
|
|
330
|
+
entry.hash()
|
|
331
|
+
)
|
|
332
|
+
.assertTrue("Bridging Contract Attestation not valid");
|
|
333
|
+
|
|
334
|
+
// Credit the amount to the settlement contract
|
|
335
|
+
const balanceAU = AccountUpdate.create(bridgingContract, tokenId);
|
|
336
|
+
balanceAU.balance.addInPlace(amount);
|
|
337
|
+
balanceAU.body.mayUseToken = childrenMayUseToken;
|
|
338
|
+
this.approve(balanceAU);
|
|
339
|
+
|
|
340
|
+
const action = new Deposit({
|
|
341
|
+
tokenId,
|
|
342
|
+
address: l2Receiver,
|
|
343
|
+
amount,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const { methodIdMappings, incomingMessagesPaths } =
|
|
347
|
+
this.getInitializationArgs();
|
|
348
|
+
|
|
349
|
+
const methodId = Field(
|
|
350
|
+
methodIdMappings[incomingMessagesPaths.deposit].methodId
|
|
351
|
+
).toConstant();
|
|
352
|
+
this.dispatchMessage(methodId.toConstant(), action, Deposit);
|
|
353
|
+
|
|
354
|
+
this.self.body.mayUseToken = {
|
|
355
|
+
parentsOwnToken: tokenId.equals(TokenId.default).not(),
|
|
356
|
+
inheritFromParent: Bool(false),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { inject, injectable, injectAll } from "tsyringe";
|
|
2
|
+
import {
|
|
3
|
+
ArtifactRecord,
|
|
4
|
+
ChildVerificationKeyService,
|
|
5
|
+
CompileRegistry,
|
|
6
|
+
log,
|
|
7
|
+
} from "@proto-kit/common";
|
|
8
|
+
|
|
9
|
+
import { BlockProvable } from "../../prover/block/BlockProvable";
|
|
10
|
+
import {
|
|
11
|
+
ContractModule,
|
|
12
|
+
SmartContractClassFromInterface,
|
|
13
|
+
} from "../ContractModule";
|
|
14
|
+
import { ProvableSettlementHook } from "../modularity/ProvableSettlementHook";
|
|
15
|
+
import { ContractArgsRegistry } from "../ContractArgsRegistry";
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
SettlementContractArgs,
|
|
19
|
+
SettlementContractType,
|
|
20
|
+
} from "./settlement/SettlementBase";
|
|
21
|
+
import { SettlementContract } from "./settlement/SettlementContract";
|
|
22
|
+
|
|
23
|
+
export type SettlementContractConfig = {
|
|
24
|
+
escapeHatchSlotsInterval?: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 24 hours
|
|
28
|
+
export const DEFAULT_ESCAPE_HATCH = (60 / 3) * 24;
|
|
29
|
+
|
|
30
|
+
@injectable()
|
|
31
|
+
export class SettlementSmartContractModule extends ContractModule<
|
|
32
|
+
SettlementContractType,
|
|
33
|
+
SettlementContractConfig
|
|
34
|
+
> {
|
|
35
|
+
public constructor(
|
|
36
|
+
@injectAll("ProvableSettlementHook")
|
|
37
|
+
private readonly hooks: ProvableSettlementHook<unknown>[],
|
|
38
|
+
@inject("BlockProver")
|
|
39
|
+
private readonly blockProver: BlockProvable,
|
|
40
|
+
private readonly childVerificationKeyService: ChildVerificationKeyService,
|
|
41
|
+
private readonly argsRegistry: ContractArgsRegistry
|
|
42
|
+
) {
|
|
43
|
+
super();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public contractFactory(): SmartContractClassFromInterface<SettlementContractType> {
|
|
47
|
+
const { hooks, config } = this;
|
|
48
|
+
|
|
49
|
+
const escapeHatchSlotsInterval =
|
|
50
|
+
config.escapeHatchSlotsInterval ?? DEFAULT_ESCAPE_HATCH;
|
|
51
|
+
|
|
52
|
+
this.argsRegistry.addArgs<SettlementContractArgs>("SettlementContract", {
|
|
53
|
+
hooks,
|
|
54
|
+
escapeHatchSlotsInterval,
|
|
55
|
+
ChildVerificationKeyService: this.childVerificationKeyService,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return SettlementContract;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public async compile(
|
|
62
|
+
registry: CompileRegistry
|
|
63
|
+
): Promise<ArtifactRecord | undefined> {
|
|
64
|
+
// Dependencies
|
|
65
|
+
await this.blockProver.compile(registry);
|
|
66
|
+
|
|
67
|
+
this.contractFactory();
|
|
68
|
+
|
|
69
|
+
log.debug("Compiling Settlement Contract");
|
|
70
|
+
|
|
71
|
+
const artifact = await registry.forceProverExists(
|
|
72
|
+
async (reg) => await registry.compile(SettlementContract)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
SettlementSmartContract: artifact,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMerkleTree,
|
|
3
|
+
InMemoryMerkleTreeStorage,
|
|
4
|
+
log,
|
|
5
|
+
} from "@proto-kit/common";
|
|
6
|
+
import { Field, Poseidon, PublicKey, SmartContract, Struct } from "o1js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Merkle tree that contains all the deployed token bridges as a mapping of
|
|
10
|
+
* tokenId => PublicKey
|
|
11
|
+
*
|
|
12
|
+
* It should be used as an append-only tree with incremental indizes - this allows
|
|
13
|
+
* us to reduce the height of it
|
|
14
|
+
*/
|
|
15
|
+
export class TokenBridgeTree extends createMerkleTree(256) {
|
|
16
|
+
public indizes: Record<string, bigint> = {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initializes and fills the tree based on all on-chain events that have been
|
|
20
|
+
* emitted by every emit
|
|
21
|
+
*/
|
|
22
|
+
public static async buildTreeFromEvents(
|
|
23
|
+
contract: SmartContract & {
|
|
24
|
+
events: { "token-bridge-added": typeof TokenBridgeTreeAddition };
|
|
25
|
+
}
|
|
26
|
+
) {
|
|
27
|
+
const events = await contract.fetchEvents();
|
|
28
|
+
|
|
29
|
+
log.debug(`Found ${events.length} token bridge add events`);
|
|
30
|
+
|
|
31
|
+
const tree = new TokenBridgeTree(new InMemoryMerkleTreeStorage());
|
|
32
|
+
const indizes: Record<string, bigint> = {};
|
|
33
|
+
|
|
34
|
+
events.forEach(({ type, event }) => {
|
|
35
|
+
if (type === "token-bridge-added") {
|
|
36
|
+
const addition =
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
38
|
+
event.data as unknown as TokenBridgeTreeAddition;
|
|
39
|
+
|
|
40
|
+
tree.setLeaf(addition.index.toBigInt(), addition.value.hash());
|
|
41
|
+
|
|
42
|
+
indizes[addition.value.tokenId.toString()] = addition.index.toBigInt();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
tree.indizes = indizes;
|
|
46
|
+
return tree;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getIndex(tokenId: Field): bigint {
|
|
50
|
+
return this.indizes[tokenId.toString()];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class TokenBridgeTreeWitness extends TokenBridgeTree.WITNESS {}
|
|
55
|
+
|
|
56
|
+
export class TokenBridgeEntry extends Struct({
|
|
57
|
+
address: PublicKey,
|
|
58
|
+
tokenId: Field,
|
|
59
|
+
}) {
|
|
60
|
+
public hash() {
|
|
61
|
+
return Poseidon.hash(TokenBridgeEntry.toFields(this));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class TokenBridgeAttestation extends Struct({
|
|
66
|
+
witness: TokenBridgeTreeWitness,
|
|
67
|
+
index: Field,
|
|
68
|
+
}) {}
|
|
69
|
+
|
|
70
|
+
export class TokenBridgeTreeAddition extends Struct({
|
|
71
|
+
index: Field,
|
|
72
|
+
value: TokenBridgeEntry,
|
|
73
|
+
}) {}
|