@proto-kit/protocol 0.1.1-develop.211 → 0.1.1-develop.2137
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 +51 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -13
- 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 +66 -42
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +58 -45
- 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 +369 -54
- package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
- package/dist/model/StateTransitionProvableBatch.js +74 -51
- 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 +45 -34
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +115 -57
- 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 -6
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +10 -5
- 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 +32 -3
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
- package/dist/protocol/ProvableTransactionHook.js +25 -0
- package/dist/protocol/ProvableTransactionHook.js.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts +6 -1
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.js +6 -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 +45 -44
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +306 -143
- 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 -64
- package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProvable.js +10 -7
- package/dist/prover/statetransition/StateTransitionProvable.js.map +1 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +26 -24
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +159 -93
- 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 +58 -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 +114 -0
- package/dist/settlement/contracts/BridgeContract.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContract.js +270 -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 +588 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js +42 -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 +28 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts.map +1 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.js +39 -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 +13 -5
- package/dist/state/State.d.ts.map +1 -1
- package/dist/state/State.js +42 -17
- package/dist/state/State.js.map +1 -0
- package/dist/state/StateMap.d.ts +4 -4
- package/dist/state/StateMap.d.ts.map +1 -1
- package/dist/state/StateMap.js +5 -5
- package/dist/state/StateMap.js.map +1 -0
- package/dist/state/StateService.d.ts +4 -4
- package/dist/state/StateService.d.ts.map +1 -1
- package/dist/state/StateService.js +1 -0
- package/dist/state/StateService.js.map +1 -0
- package/dist/state/StateServiceProvider.d.ts +5 -7
- package/dist/state/StateServiceProvider.d.ts.map +1 -1
- package/dist/state/StateServiceProvider.js +18 -23
- 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 +48 -0
- package/dist/state/WitnessBlockContext.js.map +1 -0
- package/dist/state/assert/assert.d.ts +2 -2
- package/dist/state/assert/assert.d.ts.map +1 -1
- package/dist/state/assert/assert.js +16 -6
- package/dist/state/assert/assert.js.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +137 -4
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.js +44 -11
- package/dist/state/context/RuntimeMethodExecutionContext.js.map +1 -0
- package/dist/state/context/TransitionMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/TransitionMethodExecutionContext.js +1 -1
- package/dist/state/context/TransitionMethodExecutionContext.js.map +1 -0
- package/dist/state/protocol/ProtocolState.d.ts +8 -2
- package/dist/state/protocol/ProtocolState.d.ts.map +1 -1
- package/dist/state/protocol/ProtocolState.js +36 -20
- 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 +10 -10
- 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/{blockmodules → hooks}/NoopTransactionHook.ts +9 -3
- package/src/index.ts +51 -13
- package/src/model/AppliedStateTransitionBatch.ts +16 -0
- package/src/model/MethodPublicOutput.ts +3 -1
- package/src/model/Option.ts +87 -57
- 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 +94 -73
- 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 +186 -116
- package/src/protocol/ProtocolEnvironment.ts +10 -0
- package/src/protocol/ProtocolModule.ts +18 -11
- package/src/protocol/ProvableBlockHook.ts +67 -0
- package/src/protocol/ProvableTransactionHook.ts +92 -3
- package/src/protocol/TransitioningProtocolModule.ts +8 -1
- 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 +668 -251
- 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 +25 -20
- package/src/prover/statetransition/StateTransitionProver.ts +299 -168
- 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 +64 -0
- package/src/settlement/ContractModule.ts +31 -0
- package/src/settlement/SettlementContractModule.ts +150 -0
- package/src/settlement/contracts/BridgeContract.ts +383 -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 +86 -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 +62 -0
- package/src/settlement/modularity/OutgoingMessageProcessor.ts +78 -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 +49 -19
- package/src/state/StateMap.ts +5 -6
- package/src/state/StateService.ts +5 -5
- package/src/state/StateServiceProvider.ts +18 -18
- package/src/state/WitnessBlockContext.ts +54 -0
- package/src/state/assert/assert.ts +18 -8
- package/src/state/context/RuntimeMethodExecutionContext.ts +68 -11
- package/src/state/context/TransitionMethodExecutionContext.ts +0 -1
- package/src/state/protocol/ProtocolState.ts +61 -26
- 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 +124 -140
- package/test/Protocol.test.ts +14 -21
- 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/{src → test}/state/assert/assert.test.ts +10 -3
- 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/blockmodules/AccountStateModule.d.ts +0 -38
- package/dist/blockmodules/AccountStateModule.d.ts.map +0 -1
- package/dist/blockmodules/AccountStateModule.js +0 -38
- package/dist/blockmodules/NoopTransactionHook.d.ts +0 -6
- package/dist/blockmodules/NoopTransactionHook.d.ts.map +0 -1
- package/dist/blockmodules/NoopTransactionHook.js +0 -5
- 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/state/context/ProtocolMethodExecutionContext.d.ts +0 -22
- package/dist/state/context/ProtocolMethodExecutionContext.d.ts.map +0 -1
- package/dist/state/context/ProtocolMethodExecutionContext.js +0 -28
- 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/blockmodules/AccountStateModule.ts +0 -31
- 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/state/context/ProtocolMethodExecutionContext.ts +0 -36
- 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
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import { log } from "@proto-kit/common";
|
|
3
|
-
import { RollupMerkleTree } from "./RollupMerkleTree.js";
|
|
4
|
-
export class InMemoryMerkleTreeStorage {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.nodes = {};
|
|
7
|
-
}
|
|
8
|
-
getNode(key, level) {
|
|
9
|
-
return this.nodes[level]?.[key.toString()];
|
|
10
|
-
}
|
|
11
|
-
setNode(key, level, value) {
|
|
12
|
-
var _a;
|
|
13
|
-
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
17
|
-
constructor(parent) {
|
|
18
|
-
super();
|
|
19
|
-
this.parent = parent;
|
|
20
|
-
this.writeCache = {};
|
|
21
|
-
}
|
|
22
|
-
setNode(key, level, value) {
|
|
23
|
-
var _a;
|
|
24
|
-
super.setNode(key, level, value);
|
|
25
|
-
((_a = this.writeCache)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
26
|
-
}
|
|
27
|
-
getWrittenNodes() {
|
|
28
|
-
return this.writeCache;
|
|
29
|
-
}
|
|
30
|
-
resetWrittenNodes() {
|
|
31
|
-
this.writeCache = {};
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
34
|
-
async preloadKey(index) {
|
|
35
|
-
// Algo from RollupMerkleTree.getWitness()
|
|
36
|
-
const { leafCount, height } = RollupMerkleTree;
|
|
37
|
-
if (index >= leafCount) {
|
|
38
|
-
index %= leafCount;
|
|
39
|
-
}
|
|
40
|
-
// eslint-disable-next-line no-warning-comments,max-len
|
|
41
|
-
// TODO Not practical at the moment. Improve pattern when implementing DB storage
|
|
42
|
-
for (let level = 0; level < height; level++) {
|
|
43
|
-
const key = index;
|
|
44
|
-
const isLeft = index % 2n === 0n;
|
|
45
|
-
const siblingKey = isLeft ? index + 1n : index - 1n;
|
|
46
|
-
// eslint-disable-next-line no-await-in-loop
|
|
47
|
-
const value = await this.parent.getNode(key, level);
|
|
48
|
-
// eslint-disable-next-line no-await-in-loop
|
|
49
|
-
const sibling = await this.parent.getNode(siblingKey, level);
|
|
50
|
-
if (level === 0) {
|
|
51
|
-
log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
|
|
52
|
-
}
|
|
53
|
-
if (value !== undefined) {
|
|
54
|
-
this.setNode(key, level, value);
|
|
55
|
-
}
|
|
56
|
-
if (sibling !== undefined) {
|
|
57
|
-
this.setNode(siblingKey, level, sibling);
|
|
58
|
-
}
|
|
59
|
-
index /= 2n;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async mergeIntoParent() {
|
|
63
|
-
// In case no state got set we can skip this step
|
|
64
|
-
if (Object.keys(this.writeCache).length === 0) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.parent.openTransaction();
|
|
68
|
-
const { height } = RollupMerkleTree;
|
|
69
|
-
const nodes = this.getWrittenNodes();
|
|
70
|
-
const promises = Array.from({ length: height }).flatMap((ignored, level) => Object.entries(nodes[level]).map(async (entry) => {
|
|
71
|
-
await this.parent.setNode(BigInt(entry[0]), level, entry[1]);
|
|
72
|
-
}));
|
|
73
|
-
await Promise.all(promises);
|
|
74
|
-
this.parent.commit();
|
|
75
|
-
this.resetWrittenNodes();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type MerkleTreeStore, type SyncMerkleTreeStore } from "./RollupMerkleTree.js";
|
|
2
|
-
export declare class NoOpMerkleTreeStorage implements SyncMerkleTreeStore {
|
|
3
|
-
parent: MerkleTreeStore;
|
|
4
|
-
openTransaction(): void;
|
|
5
|
-
commit(): void;
|
|
6
|
-
getNode(): bigint | undefined;
|
|
7
|
-
setNode(): void;
|
|
8
|
-
virtualize(): MerkleTreeStore;
|
|
9
|
-
getNodeAsync(): Promise<bigint | undefined>;
|
|
10
|
-
setNodeAsync(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare class MemoryMerkleTreeStorage implements SyncMerkleTreeStore {
|
|
13
|
-
private readonly nodes;
|
|
14
|
-
private readonly cache;
|
|
15
|
-
parent: SyncMerkleTreeStore;
|
|
16
|
-
constructor(parent?: SyncMerkleTreeStore | undefined);
|
|
17
|
-
openTransaction(): void;
|
|
18
|
-
commit(): void;
|
|
19
|
-
getNode(key: bigint, level: number): bigint | undefined;
|
|
20
|
-
setNode(key: bigint, level: number, value: bigint): void;
|
|
21
|
-
virtualize(): MerkleTreeStore;
|
|
22
|
-
getNodeAsync(key: bigint, level: number): Promise<bigint | undefined>;
|
|
23
|
-
setNodeAsync(key: bigint, level: number, value: bigint): Promise<void>;
|
|
24
|
-
cacheFromParent(index: bigint): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=MemoryMerkleTreeStorage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,qBAAsB,YAAW,mBAAmB;IACxD,MAAM,EAAE,eAAe,CAAQ;IAE/B,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,IAAI,MAAM,GAAG,SAAS;IAI7B,OAAO,IAAI,IAAI;IAIf,UAAU,IAAI,eAAe;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3C;AAED,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEP,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEA,MAAM,EAAE,mBAAmB,CAAC;gBAEhB,MAAM,GAAE,mBAAmB,GAAG,SAAqB;IAI/D,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAQvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxD,UAAU,IAAI,eAAe;IAIvB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAKH,eAAe,CAAC,KAAK,EAAE,MAAM;CAoB3C"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import noop from "lodash/noop";
|
|
3
|
-
import { RollupMerkleTree, } from "./RollupMerkleTree.js";
|
|
4
|
-
export class NoOpMerkleTreeStorage {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.parent = this;
|
|
7
|
-
}
|
|
8
|
-
openTransaction() {
|
|
9
|
-
noop();
|
|
10
|
-
}
|
|
11
|
-
commit() {
|
|
12
|
-
noop();
|
|
13
|
-
}
|
|
14
|
-
getNode() {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
setNode() {
|
|
18
|
-
noop();
|
|
19
|
-
}
|
|
20
|
-
virtualize() {
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
async getNodeAsync() {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
async setNodeAsync() {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class MemoryMerkleTreeStorage {
|
|
31
|
-
constructor(parent = undefined) {
|
|
32
|
-
this.nodes = {};
|
|
33
|
-
this.cache = {};
|
|
34
|
-
this.parent = parent ?? new NoOpMerkleTreeStorage();
|
|
35
|
-
}
|
|
36
|
-
openTransaction() {
|
|
37
|
-
noop();
|
|
38
|
-
}
|
|
39
|
-
commit() {
|
|
40
|
-
noop();
|
|
41
|
-
}
|
|
42
|
-
getNode(key, level) {
|
|
43
|
-
return (this.nodes[level]?.[key.toString()] ??
|
|
44
|
-
this.cache[level]?.[key.toString()] ??
|
|
45
|
-
this.parent.getNode(key, level));
|
|
46
|
-
}
|
|
47
|
-
setNode(key, level, value) {
|
|
48
|
-
var _a;
|
|
49
|
-
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
50
|
-
}
|
|
51
|
-
virtualize() {
|
|
52
|
-
return new MemoryMerkleTreeStorage(this);
|
|
53
|
-
}
|
|
54
|
-
async getNodeAsync(key, level) {
|
|
55
|
-
return this.getNode(key, level);
|
|
56
|
-
}
|
|
57
|
-
async setNodeAsync(key, level, value) {
|
|
58
|
-
this.setNode(key, level, value);
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
async cacheFromParent(index) {
|
|
62
|
-
var _a;
|
|
63
|
-
// Algo from RollupMerkleTree.getWitness()
|
|
64
|
-
const { leafCount, height } = RollupMerkleTree;
|
|
65
|
-
if (index >= leafCount) {
|
|
66
|
-
index %= leafCount;
|
|
67
|
-
}
|
|
68
|
-
for (let level = 0; level < height - 1; level++) {
|
|
69
|
-
const isLeft = index % 2n === 0n;
|
|
70
|
-
const key = isLeft ? index + 1n : index - 1n;
|
|
71
|
-
// eslint-disable-next-line no-await-in-loop
|
|
72
|
-
const value = await this.parent.getNodeAsync(key, level);
|
|
73
|
-
if (value !== undefined) {
|
|
74
|
-
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
75
|
-
}
|
|
76
|
-
index /= 2n;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface AsyncMerkleTreeStore {
|
|
2
|
-
openTransaction: () => void;
|
|
3
|
-
commit: () => void;
|
|
4
|
-
setNode: (key: bigint, level: number, value: bigint) => Promise<void>;
|
|
5
|
-
getNode: (key: bigint, level: number) => Promise<bigint | undefined>;
|
|
6
|
-
}
|
|
7
|
-
export interface MerkleTreeStore {
|
|
8
|
-
setNode: (key: bigint, level: number, value: bigint) => void;
|
|
9
|
-
getNode: (key: bigint, level: number) => bigint | undefined;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=MerkleTreeStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MerkleTreeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MerkleTreeStore.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE7D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Bool, Field } from "snarkyjs";
|
|
2
|
-
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
3
|
-
export { RollupMerkleTree, RollupMerkleWitness };
|
|
4
|
-
export { maybeSwap };
|
|
5
|
-
declare const RollupMerkleWitness_base: (new (value: {
|
|
6
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
7
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
8
|
-
}) => {
|
|
9
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
10
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
11
|
-
}) & {
|
|
12
|
-
_isStruct: true;
|
|
13
|
-
} & import("snarkyjs/dist/node/snarky").ProvablePure<{
|
|
14
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
15
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
16
|
-
}> & {
|
|
17
|
-
toInput: (x: {
|
|
18
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
19
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
20
|
-
}) => {
|
|
21
|
-
fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
|
|
22
|
-
packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
|
|
23
|
-
};
|
|
24
|
-
toJSON: (x: {
|
|
25
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
26
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
27
|
-
}) => {
|
|
28
|
-
path: string[];
|
|
29
|
-
isLeft: boolean[];
|
|
30
|
-
};
|
|
31
|
-
fromJSON: (x: {
|
|
32
|
-
path: string[];
|
|
33
|
-
isLeft: boolean[];
|
|
34
|
-
}) => {
|
|
35
|
-
path: import("snarkyjs/dist/node/lib/field").Field[];
|
|
36
|
-
isLeft: import("snarkyjs/dist/node/lib/bool").Bool[];
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* The {@link BaseMerkleWitness} class defines a circuit-compatible base class
|
|
41
|
-
* for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
|
|
42
|
-
*/
|
|
43
|
-
declare class RollupMerkleWitness extends RollupMerkleWitness_base {
|
|
44
|
-
static height: number;
|
|
45
|
-
height(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Calculates a root depending on the leaf value.
|
|
48
|
-
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
49
|
-
* @returns The calculated root.
|
|
50
|
-
*/
|
|
51
|
-
calculateRoot(hash: Field): Field;
|
|
52
|
-
/**
|
|
53
|
-
* Calculates the index of the leaf node that belongs to this Witness.
|
|
54
|
-
* @returns Index of the leaf.
|
|
55
|
-
*/
|
|
56
|
-
calculateIndex(): Field;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
|
|
60
|
-
* which every leaf is the cryptography hash of a piece of data,
|
|
61
|
-
* and every node is the hash of the concatenation of its two child nodes.
|
|
62
|
-
*
|
|
63
|
-
* A Merkle Tree allows developers to easily and securely verify
|
|
64
|
-
* the integrity of large amounts of data.
|
|
65
|
-
*
|
|
66
|
-
* Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
|
|
67
|
-
* on how to use Merkle Trees in combination with zkApps and
|
|
68
|
-
* zero knowledge programming!
|
|
69
|
-
*
|
|
70
|
-
* Levels are indexed from leaves (level 0) to root (level N - 1).
|
|
71
|
-
*/
|
|
72
|
-
declare class RollupMerkleTree {
|
|
73
|
-
static height: number;
|
|
74
|
-
static get leafCount(): bigint;
|
|
75
|
-
private readonly zeroes;
|
|
76
|
-
readonly store: MerkleTreeStore;
|
|
77
|
-
constructor(store: MerkleTreeStore);
|
|
78
|
-
/**
|
|
79
|
-
* Returns a node which lives at a given index and level.
|
|
80
|
-
* @param level Level of the node.
|
|
81
|
-
* @param index Index of the node.
|
|
82
|
-
* @returns The data of the node.
|
|
83
|
-
*/
|
|
84
|
-
getNode(level: number, index: bigint): Field;
|
|
85
|
-
/**
|
|
86
|
-
* Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
|
|
87
|
-
* @returns The root of the Merkle Tree.
|
|
88
|
-
*/
|
|
89
|
-
getRoot(): Field;
|
|
90
|
-
private setNode;
|
|
91
|
-
/**
|
|
92
|
-
* TODO: if this is passed an index bigger than the max, it will set a couple
|
|
93
|
-
* of out-of-bounds nodes but not affect the real Merkle root. OK?
|
|
94
|
-
*/
|
|
95
|
-
/**
|
|
96
|
-
* Sets the value of a leaf node at a given index to a given value.
|
|
97
|
-
* @param index Position of the leaf node.
|
|
98
|
-
* @param leaf New value.
|
|
99
|
-
*/
|
|
100
|
-
setLeaf(index: bigint, leaf: Field): void;
|
|
101
|
-
/**
|
|
102
|
-
* Returns the witness (also known as
|
|
103
|
-
* [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
|
|
104
|
-
* for the leaf at the given index.
|
|
105
|
-
* @param index Position of the leaf node.
|
|
106
|
-
* @returns The witness that belongs to the leaf.
|
|
107
|
-
*/
|
|
108
|
-
getWitness(index: bigint): RollupMerkleWitness;
|
|
109
|
-
/**
|
|
110
|
-
* Fills all leaves of the tree.
|
|
111
|
-
* @param leaves Values to fill the leaves with.
|
|
112
|
-
*/
|
|
113
|
-
fill(leaves: Field[]): void;
|
|
114
|
-
/**
|
|
115
|
-
* Returns the amount of leaf nodes.
|
|
116
|
-
* @returns Amount of leaf nodes.
|
|
117
|
-
*/
|
|
118
|
-
get leafCount(): bigint;
|
|
119
|
-
}
|
|
120
|
-
export declare namespace MerkleTreeUtils {
|
|
121
|
-
function normalizeKey(key: Field): Field;
|
|
122
|
-
function checkMembership(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): Bool;
|
|
123
|
-
function computeRoot(witness: RollupMerkleWitness, value: Field): Field;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* More efficient version of `maybeSwapBad` which
|
|
127
|
-
* reuses an intermediate variable
|
|
128
|
-
*/
|
|
129
|
-
declare function maybeSwap(b: Bool, x: Field, y: Field): [Field, Field];
|
|
130
|
-
//# sourceMappingURL=RollupMerkleTree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/RollupMerkleTree.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,UAAU,CAAC;AAInE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AAIjD,OAAO,EAAE,SAAS,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErB;;;GAGG;AACH,cAAM,mBAAoB,SAAQ,wBAGhC;IACA,OAAc,MAAM,SAAO;IAEpB,MAAM,IAAI,MAAM;IAIvB;;;;OAIG;IACI,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK;IAaxC;;;OAGG;IACI,cAAc,IAAI,KAAK;CAiB/B;AAED;;;;;;;;;;;;;GAaG;AACH,cAAM,gBAAgB;IACpB,OAAc,MAAM,SAAO;IAE3B,WAAkB,SAAS,IAAI,MAAM,CAEpC;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAElC,SAAgB,KAAK,EAAE,eAAe,CAAC;gBAEpB,KAAK,EAAE,eAAe;IAYzC;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;IAInD;;;OAGG;IAEI,OAAO,IAAI,KAAK;IAMvB,OAAO,CAAC,OAAO;IAIf;;;OAGG;IAEH;;;;OAIG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK;IAgBzC;;;;;;OAMG;IAEI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB;IAqBrD;;;OAGG;IAEI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE;IAM3B;;;OAGG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;CACF;AAGD,yBAAiB,eAAe,CAAC;IAC/B,SAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,CAS9C;IAED,SAAgB,eAAe,CAC7B,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,IAAI,CAKN;IAED,SAAgB,WAAW,CACzB,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,KAAK,GACX,KAAK,CAEP;CACF;AAED;;;GAGG;AACH,iBAAS,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAK9D"}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
/* eslint-disable id-length */
|
|
11
|
-
/* eslint-disable line-comment-position */
|
|
12
|
-
/* eslint-disable no-inline-comments */
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
14
|
-
import { Bool, Field, Poseidon, Provable, Struct } from "snarkyjs";
|
|
15
|
-
import { notInCircuit } from "../utils";
|
|
16
|
-
// external API
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
18
|
-
export { RollupMerkleTree, RollupMerkleWitness };
|
|
19
|
-
// internal API
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
21
|
-
export { maybeSwap };
|
|
22
|
-
/**
|
|
23
|
-
* The {@link BaseMerkleWitness} class defines a circuit-compatible base class
|
|
24
|
-
* for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
|
|
25
|
-
*/
|
|
26
|
-
class RollupMerkleWitness extends Struct({
|
|
27
|
-
path: Provable.Array(Field, 256 - 1),
|
|
28
|
-
isLeft: Provable.Array(Bool, 256 - 1),
|
|
29
|
-
}) {
|
|
30
|
-
height() {
|
|
31
|
-
return RollupMerkleWitness.height;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Calculates a root depending on the leaf value.
|
|
35
|
-
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
36
|
-
* @returns The calculated root.
|
|
37
|
-
*/
|
|
38
|
-
calculateRoot(hash) {
|
|
39
|
-
const n = this.height();
|
|
40
|
-
for (let index = 1; index < n; ++index) {
|
|
41
|
-
const isLeft = this.isLeft[index - 1];
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
43
|
-
const [left, right] = maybeSwap(isLeft, hash, this.path[index - 1]);
|
|
44
|
-
hash = Poseidon.hash([left, right]);
|
|
45
|
-
}
|
|
46
|
-
return hash;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Calculates the index of the leaf node that belongs to this Witness.
|
|
50
|
-
* @returns Index of the leaf.
|
|
51
|
-
*/
|
|
52
|
-
calculateIndex() {
|
|
53
|
-
let powerOfTwo = Field(1);
|
|
54
|
-
let index = Field(0);
|
|
55
|
-
const n = this.height();
|
|
56
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
57
|
-
for (let index_ = 1; index_ < n; ++index_) {
|
|
58
|
-
index = Provable.if(this.isLeft[index_ - 1], index, index.add(powerOfTwo));
|
|
59
|
-
powerOfTwo = powerOfTwo.mul(2);
|
|
60
|
-
}
|
|
61
|
-
return index;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
RollupMerkleWitness.height = 256;
|
|
65
|
-
/**
|
|
66
|
-
* A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
|
|
67
|
-
* which every leaf is the cryptography hash of a piece of data,
|
|
68
|
-
* and every node is the hash of the concatenation of its two child nodes.
|
|
69
|
-
*
|
|
70
|
-
* A Merkle Tree allows developers to easily and securely verify
|
|
71
|
-
* the integrity of large amounts of data.
|
|
72
|
-
*
|
|
73
|
-
* Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
|
|
74
|
-
* on how to use Merkle Trees in combination with zkApps and
|
|
75
|
-
* zero knowledge programming!
|
|
76
|
-
*
|
|
77
|
-
* Levels are indexed from leaves (level 0) to root (level N - 1).
|
|
78
|
-
*/
|
|
79
|
-
class RollupMerkleTree {
|
|
80
|
-
static get leafCount() {
|
|
81
|
-
return 2n ** BigInt(RollupMerkleTree.height - 1);
|
|
82
|
-
}
|
|
83
|
-
constructor(store) {
|
|
84
|
-
this.store = store;
|
|
85
|
-
// eslint-disable-next-line @shopify/prefer-class-properties
|
|
86
|
-
this.zeroes = [0n];
|
|
87
|
-
for (let index = 1; index < RollupMerkleTree.height; index += 1) {
|
|
88
|
-
const previousLevel = Field(this.zeroes[index - 1]);
|
|
89
|
-
this.zeroes.push(Poseidon.hash([previousLevel, previousLevel]).toBigInt());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns a node which lives at a given index and level.
|
|
94
|
-
* @param level Level of the node.
|
|
95
|
-
* @param index Index of the node.
|
|
96
|
-
* @returns The data of the node.
|
|
97
|
-
*/
|
|
98
|
-
getNode(level, index) {
|
|
99
|
-
return Field(this.store.getNode(index, level) ?? this.zeroes[level]);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
|
|
103
|
-
* @returns The root of the Merkle Tree.
|
|
104
|
-
*/
|
|
105
|
-
getRoot() {
|
|
106
|
-
return this.getNode(RollupMerkleTree.height - 1, 0n);
|
|
107
|
-
}
|
|
108
|
-
// eslint-disable-next-line no-warning-comments
|
|
109
|
-
// TODO: this allows to set a node at an index larger than the size. OK?
|
|
110
|
-
setNode(level, index, value) {
|
|
111
|
-
this.store.setNode(index, level, value.toBigInt());
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* TODO: if this is passed an index bigger than the max, it will set a couple
|
|
115
|
-
* of out-of-bounds nodes but not affect the real Merkle root. OK?
|
|
116
|
-
*/
|
|
117
|
-
/**
|
|
118
|
-
* Sets the value of a leaf node at a given index to a given value.
|
|
119
|
-
* @param index Position of the leaf node.
|
|
120
|
-
* @param leaf New value.
|
|
121
|
-
*/
|
|
122
|
-
setLeaf(index, leaf) {
|
|
123
|
-
if (index >= this.leafCount) {
|
|
124
|
-
index %= this.leafCount;
|
|
125
|
-
}
|
|
126
|
-
this.setNode(0, index, leaf);
|
|
127
|
-
let currentIndex = index;
|
|
128
|
-
for (let level = 1; level < RollupMerkleTree.height; level += 1) {
|
|
129
|
-
currentIndex /= 2n;
|
|
130
|
-
const left = this.getNode(level - 1, currentIndex * 2n);
|
|
131
|
-
const right = this.getNode(level - 1, currentIndex * 2n + 1n);
|
|
132
|
-
this.setNode(level, currentIndex, Poseidon.hash([left, right]));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns the witness (also known as
|
|
137
|
-
* [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
|
|
138
|
-
* for the leaf at the given index.
|
|
139
|
-
* @param index Position of the leaf node.
|
|
140
|
-
* @returns The witness that belongs to the leaf.
|
|
141
|
-
*/
|
|
142
|
-
getWitness(index) {
|
|
143
|
-
if (index >= this.leafCount) {
|
|
144
|
-
index %= this.leafCount;
|
|
145
|
-
}
|
|
146
|
-
const path = [];
|
|
147
|
-
const isLefts = [];
|
|
148
|
-
for (let level = 0; level < RollupMerkleTree.height - 1; level += 1) {
|
|
149
|
-
const isLeft = index % 2n === 0n;
|
|
150
|
-
const sibling = this.getNode(level, isLeft ? index + 1n : index - 1n);
|
|
151
|
-
isLefts.push(Bool(isLeft));
|
|
152
|
-
path.push(sibling);
|
|
153
|
-
index /= 2n;
|
|
154
|
-
}
|
|
155
|
-
return new RollupMerkleWitness({
|
|
156
|
-
isLeft: isLefts,
|
|
157
|
-
path,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
// eslint-disable-next-line no-warning-comments, max-len
|
|
161
|
-
// TODO: should this take an optional offset? should it fail if the array is too long?
|
|
162
|
-
/**
|
|
163
|
-
* Fills all leaves of the tree.
|
|
164
|
-
* @param leaves Values to fill the leaves with.
|
|
165
|
-
*/
|
|
166
|
-
fill(leaves) {
|
|
167
|
-
leaves.forEach((value, index) => {
|
|
168
|
-
this.setLeaf(BigInt(index), value);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Returns the amount of leaf nodes.
|
|
173
|
-
* @returns Amount of leaf nodes.
|
|
174
|
-
*/
|
|
175
|
-
get leafCount() {
|
|
176
|
-
return RollupMerkleTree.leafCount;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
RollupMerkleTree.height = 256;
|
|
180
|
-
__decorate([
|
|
181
|
-
notInCircuit(),
|
|
182
|
-
__metadata("design:type", Function),
|
|
183
|
-
__metadata("design:paramtypes", [Number, BigInt]),
|
|
184
|
-
__metadata("design:returntype", Field)
|
|
185
|
-
], RollupMerkleTree.prototype, "getNode", null);
|
|
186
|
-
__decorate([
|
|
187
|
-
notInCircuit(),
|
|
188
|
-
__metadata("design:type", Function),
|
|
189
|
-
__metadata("design:paramtypes", []),
|
|
190
|
-
__metadata("design:returntype", Field)
|
|
191
|
-
], RollupMerkleTree.prototype, "getRoot", null);
|
|
192
|
-
__decorate([
|
|
193
|
-
notInCircuit(),
|
|
194
|
-
__metadata("design:type", Function),
|
|
195
|
-
__metadata("design:paramtypes", [BigInt, Field]),
|
|
196
|
-
__metadata("design:returntype", void 0)
|
|
197
|
-
], RollupMerkleTree.prototype, "setLeaf", null);
|
|
198
|
-
__decorate([
|
|
199
|
-
notInCircuit(),
|
|
200
|
-
__metadata("design:type", Function),
|
|
201
|
-
__metadata("design:paramtypes", [BigInt]),
|
|
202
|
-
__metadata("design:returntype", RollupMerkleWitness)
|
|
203
|
-
], RollupMerkleTree.prototype, "getWitness", null);
|
|
204
|
-
__decorate([
|
|
205
|
-
notInCircuit(),
|
|
206
|
-
__metadata("design:type", Function),
|
|
207
|
-
__metadata("design:paramtypes", [Array]),
|
|
208
|
-
__metadata("design:returntype", void 0)
|
|
209
|
-
], RollupMerkleTree.prototype, "fill", null);
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
211
|
-
export var MerkleTreeUtils;
|
|
212
|
-
(function (MerkleTreeUtils) {
|
|
213
|
-
function normalizeKey(key) {
|
|
214
|
-
// if(NJORD_MERKLE_TREE_HEIGHT < 256){
|
|
215
|
-
// return fieldMod(key, Field(RollupMerkleTree.leafCount).toConstant())
|
|
216
|
-
// eslint-disable-next-line max-len
|
|
217
|
-
// // return modPower2(key, RollupMerkleTree.height - 1) //TODO Fix modPower2
|
|
218
|
-
// }else{
|
|
219
|
-
return key;
|
|
220
|
-
// }
|
|
221
|
-
}
|
|
222
|
-
MerkleTreeUtils.normalizeKey = normalizeKey;
|
|
223
|
-
function checkMembership(witness, root, key, value) {
|
|
224
|
-
const root2 = witness.calculateRoot(value);
|
|
225
|
-
const key2 = witness.calculateIndex();
|
|
226
|
-
key.assertEquals(key2, "Keys of MerkleWitness does not match");
|
|
227
|
-
return root.equals(root2);
|
|
228
|
-
}
|
|
229
|
-
MerkleTreeUtils.checkMembership = checkMembership;
|
|
230
|
-
function computeRoot(witness, value) {
|
|
231
|
-
return witness.calculateRoot(value);
|
|
232
|
-
}
|
|
233
|
-
MerkleTreeUtils.computeRoot = computeRoot;
|
|
234
|
-
})(MerkleTreeUtils || (MerkleTreeUtils = {}));
|
|
235
|
-
/**
|
|
236
|
-
* More efficient version of `maybeSwapBad` which
|
|
237
|
-
* reuses an intermediate variable
|
|
238
|
-
*/
|
|
239
|
-
function maybeSwap(b, x, y) {
|
|
240
|
-
const m = b.toField().mul(x.sub(y)); // b*(x - y)
|
|
241
|
-
const x1 = y.add(m); // y + b*(x - y)
|
|
242
|
-
const y2 = x.sub(m); // x - b*(x - y) = x + b*(y - x)
|
|
243
|
-
return [x1, y2];
|
|
244
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Provable, PublicKey, Struct, UInt64 } from "snarkyjs";
|
|
2
|
-
|
|
3
|
-
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
4
|
-
import { StateMap } from "../state/StateMap";
|
|
5
|
-
import { protocolState } from "../state/protocol/ProtocolState";
|
|
6
|
-
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
7
|
-
import { assert } from "../state/assert/assert";
|
|
8
|
-
|
|
9
|
-
export class AccountState extends Struct({
|
|
10
|
-
nonce: UInt64,
|
|
11
|
-
}) {}
|
|
12
|
-
|
|
13
|
-
export class AccountStateModule extends ProvableTransactionHook {
|
|
14
|
-
@protocolState() public accountState = StateMap.from<PublicKey, AccountState>(PublicKey, AccountState);
|
|
15
|
-
|
|
16
|
-
public onTransaction({ transaction }: BlockProverExecutionData): void {
|
|
17
|
-
const accountState = this.accountState
|
|
18
|
-
.get(transaction.sender)
|
|
19
|
-
.orElse(new AccountState({ nonce: UInt64.zero }));
|
|
20
|
-
|
|
21
|
-
const currentNonce = accountState.nonce;
|
|
22
|
-
Provable.log("Current Nonce", currentNonce);
|
|
23
|
-
Provable.log("Tx Nonce", transaction.nonce);
|
|
24
|
-
assert(currentNonce.equals(transaction.nonce), "Nonce not matching");
|
|
25
|
-
|
|
26
|
-
this.accountState.set(
|
|
27
|
-
transaction.sender,
|
|
28
|
-
new AccountState({ nonce: currentNonce.add(1) })
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/model/Option.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Bool, Field, Poseidon } from "snarkyjs";
|
|
2
|
-
|
|
3
|
-
import { Option } from "./Option";
|
|
4
|
-
|
|
5
|
-
describe("option", () => {
|
|
6
|
-
it.each([
|
|
7
|
-
[Bool(true), Field(0), Field, true],
|
|
8
|
-
[Bool(false), Field(0), Field, false],
|
|
9
|
-
])(
|
|
10
|
-
"should serialize to the correct tree value",
|
|
11
|
-
(isSome, value, valueType, shouldHash) => {
|
|
12
|
-
expect.assertions(1);
|
|
13
|
-
|
|
14
|
-
const option = Option.from(isSome, value, valueType);
|
|
15
|
-
// eslint-disable-next-line jest/no-conditional-in-test
|
|
16
|
-
const treeValue = shouldHash ? Poseidon.hash(value.toFields()) : Field(0);
|
|
17
|
-
|
|
18
|
-
expect(option.treeValue.toString()).toStrictEqual(treeValue.toString());
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Bool, Field, PublicKey, Signature, Struct, UInt64 } from "snarkyjs";
|
|
2
|
-
|
|
3
|
-
export class ProtocolTransaction extends Struct({
|
|
4
|
-
methodId: Field,
|
|
5
|
-
nonce: UInt64,
|
|
6
|
-
sender: PublicKey,
|
|
7
|
-
argsHash: Field,
|
|
8
|
-
signature: Signature,
|
|
9
|
-
}) {
|
|
10
|
-
public static getSignatureData(args: {
|
|
11
|
-
methodId: Field;
|
|
12
|
-
nonce: UInt64;
|
|
13
|
-
argsHash: Field;
|
|
14
|
-
}): Field[] {
|
|
15
|
-
return [args.methodId, ...args.nonce.toFields(), args.argsHash];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public getSignatureData(): Field[] {
|
|
19
|
-
return ProtocolTransaction.getSignatureData(this);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public validateSignature(): Bool {
|
|
23
|
-
return this.signature.verify(this.sender, this.getSignatureData());
|
|
24
|
-
}
|
|
25
|
-
}
|