@proto-kit/protocol 0.1.1-develop.457 → 0.1.1-develop.651
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/blockmodules/AccountStateModule.d.ts.map +1 -1
- package/dist/blockmodules/AccountStateModule.js +10 -3
- package/dist/blockmodules/BlockHeightHook.d.ts +3 -3
- package/dist/blockmodules/BlockHeightHook.d.ts.map +1 -1
- package/dist/blockmodules/BlockHeightHook.js +5 -4
- package/dist/blockmodules/LastStateRootBlockHook.d.ts +8 -0
- package/dist/blockmodules/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/blockmodules/LastStateRootBlockHook.js +15 -0
- package/dist/blockmodules/NoopBlockHook.d.ts +6 -4
- package/dist/blockmodules/NoopBlockHook.d.ts.map +1 -1
- package/dist/blockmodules/NoopBlockHook.js +4 -4
- package/dist/blockmodules/NoopSettlementHook.d.ts +6 -0
- package/dist/blockmodules/NoopSettlementHook.d.ts.map +1 -0
- package/dist/blockmodules/NoopSettlementHook.js +18 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -1
- package/dist/hooks/AccountStateHook.js +17 -5
- package/dist/hooks/BlockHeightHook.d.ts +3 -3
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -1
- package/dist/hooks/BlockHeightHook.js +5 -4
- package/dist/hooks/LastStateRootBlockHook.d.ts +8 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.js +15 -0
- package/dist/hooks/NoopBlockHook.d.ts +6 -4
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -1
- package/dist/hooks/NoopBlockHook.js +4 -4
- package/dist/hooks/NoopSettlementHook.d.ts +6 -0
- package/dist/hooks/NoopSettlementHook.d.ts.map +1 -0
- package/dist/hooks/NoopSettlementHook.js +18 -0
- package/dist/index.d.ts +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -6
- package/dist/model/MethodPublicOutput.d.ts +8 -0
- package/dist/model/MethodPublicOutput.d.ts.map +1 -1
- package/dist/model/MethodPublicOutput.js +1 -0
- package/dist/model/Option.d.ts +3 -2
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +5 -0
- package/dist/model/RuntimeLike.d.ts +11 -0
- package/dist/model/RuntimeLike.d.ts.map +1 -0
- package/dist/model/RuntimeLike.js +1 -0
- package/dist/model/StateTransition.d.ts +6 -5
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +3 -0
- package/dist/model/StateTransitionReduction.d.ts +3 -0
- package/dist/model/StateTransitionReduction.d.ts.map +1 -0
- package/dist/model/StateTransitionReduction.js +26 -0
- package/dist/model/network/NetworkState.d.ts +40 -0
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +14 -2
- package/dist/model/transaction/RuntimeTransaction.d.ts +45 -20
- package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
- package/dist/model/transaction/RuntimeTransaction.js +68 -11
- package/dist/model/transaction/SignedTransaction.d.ts +71 -0
- package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
- package/dist/model/transaction/SignedTransaction.js +33 -0
- package/dist/model/transaction/ValueOption.d.ts +119 -0
- package/dist/model/transaction/ValueOption.d.ts.map +1 -0
- package/dist/model/transaction/ValueOption.js +24 -0
- package/dist/protocol/Protocol.d.ts +13 -16
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +26 -39
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +1 -1
- package/dist/protocol/ProvableBlockHook.d.ts +2 -10
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -1
- package/dist/protocol/ProvableBlockHook.js +1 -1
- package/dist/protocol/ProvableTransactionHook.d.ts +1 -1
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.d.ts +3 -2
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.js +3 -2
- package/dist/prover/block/BlockProvable.d.ts +106 -28
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +23 -5
- package/dist/prover/block/BlockProver.d.ts +29 -8
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +244 -78
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +45 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js +16 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +3 -2
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +1 -0
- package/dist/settlement/ContractModule.d.ts +15 -0
- package/dist/settlement/ContractModule.d.ts.map +1 -0
- package/dist/settlement/ContractModule.js +11 -0
- package/dist/settlement/ProvableSettlementHook.d.ts +26 -0
- package/dist/settlement/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/ProvableSettlementHook.js +3 -0
- package/dist/settlement/SettlementContract.d.ts +230 -0
- package/dist/settlement/SettlementContract.d.ts.map +1 -0
- package/dist/settlement/SettlementContract.js +346 -0
- package/dist/settlement/SettlementContractModule.d.ts +39 -0
- package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/SettlementContractModule.js +68 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +12 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js +36 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts +22 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.js +110 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts +19 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js +44 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts +41 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.js +235 -0
- package/dist/settlement/messages/Deposit.d.ts +39 -0
- package/dist/settlement/messages/Deposit.d.ts.map +1 -0
- package/dist/settlement/messages/Deposit.js +6 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts +109 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js +32 -0
- package/dist/settlement/messages/Withdrawal.d.ts +40 -0
- package/dist/settlement/messages/Withdrawal.d.ts.map +1 -0
- package/dist/settlement/messages/Withdrawal.js +13 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts +24 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js +3 -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 +12 -0
- package/dist/state/State.d.ts.map +1 -1
- package/dist/state/State.js +2 -1
- package/dist/state/assert/assert.d.ts.map +1 -1
- package/dist/state/assert/assert.js +8 -5
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +75 -1
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.js +21 -2
- package/dist/utils/MinaPrefixedProvableHashList.d.ts +24 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.js +51 -0
- package/dist/utils/PrefixedProvableHashList.d.ts +2 -2
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableHashList.d.ts +3 -3
- package/dist/utils/ProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableReductionHashList.d.ts +14 -0
- package/dist/utils/ProvableReductionHashList.d.ts.map +1 -0
- package/dist/utils/ProvableReductionHashList.js +50 -0
- package/dist/utils/StateTransitionReductionList.d.ts +11 -0
- package/dist/utils/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/utils/StateTransitionReductionList.js +60 -0
- package/package.json +2 -2
- package/src/hooks/AccountStateHook.ts +46 -0
- package/src/hooks/BlockHeightHook.ts +18 -0
- package/src/hooks/LastStateRootBlockHook.ts +26 -0
- package/src/hooks/NoopBlockHook.ts +20 -0
- package/src/hooks/NoopSettlementHook.ts +20 -0
- package/src/hooks/SequenceStateTransactionModule.ts +25 -0
- package/src/index.ts +24 -6
- package/src/model/MethodPublicOutput.ts +3 -2
- package/src/model/Option.ts +16 -0
- package/src/model/RuntimeLike.ts +12 -0
- package/src/model/StateTransition.ts +10 -2
- package/src/model/network/NetworkState.ts +15 -3
- package/src/model/transaction/RuntimeTransaction.ts +90 -16
- package/src/model/transaction/SignedTransaction.ts +54 -0
- package/src/model/transaction/ValueOption.ts +28 -0
- package/src/protocol/Protocol.ts +60 -67
- package/src/protocol/ProtocolModule.ts +3 -2
- package/src/protocol/ProvableBlockHook.ts +10 -13
- package/src/protocol/ProvableTransactionHook.ts +2 -1
- package/src/protocol/TransitioningProtocolModule.ts +3 -2
- package/src/prover/block/BlockProvable.ts +39 -6
- package/src/prover/block/BlockProver.ts +484 -142
- package/src/prover/block/accummulators/BlockHashMerkleTree.ts +16 -0
- package/src/prover/statetransition/StateTransitionProver.ts +4 -2
- package/src/settlement/ContractModule.ts +24 -0
- package/src/settlement/SettlementContractModule.ts +127 -0
- package/src/settlement/contracts/DispatchContractProtocolModule.ts +39 -0
- package/src/settlement/contracts/DispatchSmartContract.ts +135 -0
- package/src/settlement/contracts/SettlementContractProtocolModule.ts +65 -0
- package/src/settlement/contracts/SettlementSmartContract.ts +329 -0
- package/src/settlement/messages/Deposit.ts +6 -0
- package/src/settlement/messages/OutgoingMessageArgument.ts +41 -0
- package/src/settlement/messages/Withdrawal.ts +14 -0
- package/src/settlement/modularity/ProvableSettlementHook.ts +34 -0
- package/src/settlement/modules/NetworkStateSettlementModule.ts +39 -0
- package/src/state/State.ts +2 -1
- package/src/state/assert/assert.ts +8 -6
- package/src/state/context/RuntimeMethodExecutionContext.ts +22 -2
- package/src/utils/MinaPrefixedProvableHashList.ts +72 -0
- package/src/utils/PrefixedProvableHashList.ts +2 -2
- package/src/utils/ProvableHashList.ts +3 -3
- package/src/utils/ProvableReductionHashList.ts +68 -0
- package/src/utils/StateTransitionReductionList.ts +88 -0
- package/test/BlockProver.test.ts +4 -5
- package/test/Protocol.test.ts +15 -10
- package/test/settlement/SettlementContract.test.ts +45 -0
- package/test/utils/ProvableReductionHashList.test.ts +114 -0
- package/src/blockmodules/AccountStateModule.ts +0 -33
- package/src/blockmodules/BlockHeightHook.ts +0 -21
- package/src/blockmodules/NoopBlockHook.ts +0 -16
- package/src/model/transaction/ProtocolTransaction.ts +0 -25
- package/src/prover/block/BlockTransactionPosition.ts +0 -34
- /package/src/{blockmodules → hooks}/NoopTransactionHook.ts +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
import { prefixToField, RollupMerkleTree } from "@proto-kit/common";
|
|
11
|
+
import { AccountUpdate, Bool, Field, method, Mina, Poseidon, Proof, Provable, PublicKey, Signature, SmartContract, State, state, TokenId, UInt32, UInt64, } from "o1js";
|
|
12
|
+
import { NetworkState } from "../../model/network/NetworkState";
|
|
13
|
+
import { Path } from "../../model/Path";
|
|
14
|
+
import { BlockHashMerkleTree } from "../../prover/block/accummulators/BlockHashMerkleTree";
|
|
15
|
+
import { BlockProverPublicInput, BlockProverPublicOutput, } from "../../prover/block/BlockProvable";
|
|
16
|
+
import { OUTGOING_MESSAGE_BATCH_SIZE, OutgoingMessageArgumentBatch, } from "../messages/OutgoingMessageArgument";
|
|
17
|
+
import { Withdrawal } from "../messages/Withdrawal";
|
|
18
|
+
export class LazyBlockProof extends Proof {
|
|
19
|
+
}
|
|
20
|
+
LazyBlockProof.publicInputType = BlockProverPublicInput;
|
|
21
|
+
LazyBlockProof.publicOutputType = BlockProverPublicOutput;
|
|
22
|
+
LazyBlockProof.tag = () => {
|
|
23
|
+
throw new Error("Tag not initialized yet");
|
|
24
|
+
};
|
|
25
|
+
// Some random prefix for the sequencer signature
|
|
26
|
+
export const BATCH_SIGNATURE_PREFIX = prefixToField("pk-batchSignature");
|
|
27
|
+
export class SettlementSmartContract extends SmartContract {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.sequencerKey = State();
|
|
31
|
+
this.lastSettlementL1Block = State();
|
|
32
|
+
this.stateRoot = State();
|
|
33
|
+
this.networkStateHash = State();
|
|
34
|
+
this.blockHashRoot = State();
|
|
35
|
+
this.dispatchContractAddressX = State();
|
|
36
|
+
this.outgoingMessageCursor = State();
|
|
37
|
+
}
|
|
38
|
+
initialize(sequencer, dispatchContract) {
|
|
39
|
+
this.sequencerKey.getAndAssertEquals().assertEquals(Field(0));
|
|
40
|
+
this.stateRoot.getAndAssertEquals().assertEquals(Field(0));
|
|
41
|
+
this.blockHashRoot.getAndAssertEquals().assertEquals(Field(0));
|
|
42
|
+
this.networkStateHash.getAndAssertEquals().assertEquals(Field(0));
|
|
43
|
+
this.dispatchContractAddressX.getAndAssertEquals().assertEquals(Field(0));
|
|
44
|
+
this.sequencerKey.set(sequencer.x);
|
|
45
|
+
this.stateRoot.set(Field(RollupMerkleTree.EMPTY_ROOT));
|
|
46
|
+
this.blockHashRoot.set(Field(BlockHashMerkleTree.EMPTY_ROOT));
|
|
47
|
+
this.networkStateHash.set(NetworkState.empty().hash());
|
|
48
|
+
this.dispatchContractAddressX.set(dispatchContract.x);
|
|
49
|
+
const DispatchContract = SettlementSmartContract.args.DispatchContract;
|
|
50
|
+
new DispatchContract(dispatchContract).initialize(this.address);
|
|
51
|
+
}
|
|
52
|
+
settle(blockProof, signature, dispatchContractAddress, publicKey, inputNetworkState, outputNetworkState, newPromisedMessagesHash) {
|
|
53
|
+
// Verify the blockproof
|
|
54
|
+
blockProof.verify();
|
|
55
|
+
// Get and assert on-chain values
|
|
56
|
+
const stateRoot = this.stateRoot.getAndAssertEquals();
|
|
57
|
+
const networkStateHash = this.networkStateHash.getAndAssertEquals();
|
|
58
|
+
const blockHashRoot = this.blockHashRoot.getAndAssertEquals();
|
|
59
|
+
const sequencerKey = this.sequencerKey.getAndAssertEquals();
|
|
60
|
+
const lastSettlementL1Block = this.lastSettlementL1Block.getAndAssertEquals();
|
|
61
|
+
const onChainDispatchContractAddressX = this.dispatchContractAddressX.getAndAssertEquals();
|
|
62
|
+
onChainDispatchContractAddressX.assertEquals(dispatchContractAddress.x, "DispatchContract address not provided correctly");
|
|
63
|
+
const { DispatchContract, escapeHatchSlotsInterval, hooks } = SettlementSmartContract.args;
|
|
64
|
+
// Get dispatch contract values
|
|
65
|
+
// These values are witnesses but will be checked later on the AU
|
|
66
|
+
// call to the dispatch contract via .updateMessagesHash()
|
|
67
|
+
const dispatchContract = new DispatchContract(dispatchContractAddress);
|
|
68
|
+
const promisedMessagesHash = dispatchContract.promisedMessagesHash.get();
|
|
69
|
+
// Get block height and use the lower bound for all ops
|
|
70
|
+
const minBlockIncluded = this.network.globalSlotSinceGenesis.get();
|
|
71
|
+
this.network.globalSlotSinceGenesis.assertBetween(minBlockIncluded,
|
|
72
|
+
// 5 because that is the length the newPromisedMessagesHash will be valid
|
|
73
|
+
minBlockIncluded.add(4));
|
|
74
|
+
// Check signature/escape catch
|
|
75
|
+
publicKey.x.assertEquals(sequencerKey, "Sequencer public key witness not matching");
|
|
76
|
+
const signatureValid = signature.verify(publicKey, [
|
|
77
|
+
BATCH_SIGNATURE_PREFIX,
|
|
78
|
+
lastSettlementL1Block.value,
|
|
79
|
+
]);
|
|
80
|
+
const escapeHatchActivated = lastSettlementL1Block
|
|
81
|
+
.add(UInt32.from(escapeHatchSlotsInterval))
|
|
82
|
+
.lessThan(minBlockIncluded);
|
|
83
|
+
signatureValid
|
|
84
|
+
.or(escapeHatchActivated)
|
|
85
|
+
.assertTrue("Sequencer signature not valid and escape hatch not activated");
|
|
86
|
+
// Assert correctness of networkState witness
|
|
87
|
+
Provable.log("Network State Hash ", networkStateHash);
|
|
88
|
+
Provable.log("input Hash ", inputNetworkState.hash());
|
|
89
|
+
Provable.log("equals ", inputNetworkState.hash().equals(networkStateHash));
|
|
90
|
+
inputNetworkState
|
|
91
|
+
.hash()
|
|
92
|
+
.assertEquals(networkStateHash, "InputNetworkState witness not valid");
|
|
93
|
+
outputNetworkState
|
|
94
|
+
.hash()
|
|
95
|
+
.assertEquals(blockProof.publicOutput.networkStateHash, "OutputNetworkState witness not valid");
|
|
96
|
+
blockProof.publicOutput.closed.assertEquals(Bool(true), "Supplied proof is not a closed BlockProof");
|
|
97
|
+
// Execute onSettlementHooks for additional checks
|
|
98
|
+
const stateRecord = {
|
|
99
|
+
blockHashRoot,
|
|
100
|
+
stateRoot,
|
|
101
|
+
networkStateHash,
|
|
102
|
+
lastSettlementL1Block,
|
|
103
|
+
sequencerKey: publicKey,
|
|
104
|
+
};
|
|
105
|
+
const inputs = {
|
|
106
|
+
blockProof,
|
|
107
|
+
contractState: stateRecord,
|
|
108
|
+
newPromisedMessagesHash,
|
|
109
|
+
fromNetworkState: inputNetworkState,
|
|
110
|
+
toNetworkState: outputNetworkState,
|
|
111
|
+
currentL1Block: minBlockIncluded,
|
|
112
|
+
};
|
|
113
|
+
hooks.forEach((hook) => {
|
|
114
|
+
hook.beforeSettlement(this, inputs);
|
|
115
|
+
});
|
|
116
|
+
// Apply blockProof
|
|
117
|
+
stateRoot.assertEquals(blockProof.publicInput.stateRoot, "Input state root not matching");
|
|
118
|
+
Provable.log("Network State Hash ", networkStateHash);
|
|
119
|
+
Provable.log("input Hash ", inputNetworkState.hash());
|
|
120
|
+
Provable.log("Proof Hash ", blockProof.publicInput.networkStateHash);
|
|
121
|
+
networkStateHash.assertEquals(blockProof.publicInput.networkStateHash, "Input networkStateHash not matching");
|
|
122
|
+
blockHashRoot.assertEquals(blockProof.publicInput.blockHashRoot, "Input blockHashRoot not matching");
|
|
123
|
+
this.stateRoot.set(blockProof.publicOutput.stateRoot);
|
|
124
|
+
this.networkStateHash.set(blockProof.publicOutput.networkStateHash);
|
|
125
|
+
this.blockHashRoot.set(blockProof.publicOutput.blockHashRoot);
|
|
126
|
+
// Assert and apply deposit commitments
|
|
127
|
+
promisedMessagesHash.assertEquals(blockProof.publicOutput.incomingMessagesHash, "Promised messages not honored");
|
|
128
|
+
// Call DispatchContract
|
|
129
|
+
// This call checks that the promisedMessagesHash, which is already proven
|
|
130
|
+
// to be the blockProofs publicoutput, is actually the current on-chain
|
|
131
|
+
// promisedMessageHash. It also checks the newPromisedMessagesHash to be
|
|
132
|
+
// a current sequencestate value
|
|
133
|
+
dispatchContract.updateMessagesHash(promisedMessagesHash, newPromisedMessagesHash);
|
|
134
|
+
this.lastSettlementL1Block.set(minBlockIncluded);
|
|
135
|
+
}
|
|
136
|
+
rollupOutgoingMessages(batch) {
|
|
137
|
+
let counter = this.outgoingMessageCursor.getAndAssertEquals();
|
|
138
|
+
const stateRoot = this.stateRoot.getAndAssertEquals();
|
|
139
|
+
const [withdrawalModule, withdrawalStateName] = SettlementSmartContract.args.withdrawalStatePath;
|
|
140
|
+
const mapPath = Path.fromProperty(withdrawalModule, withdrawalStateName);
|
|
141
|
+
let accountCreationFeePaid = Field(0);
|
|
142
|
+
for (let i = 0; i < OUTGOING_MESSAGE_BATCH_SIZE; i++) {
|
|
143
|
+
const args = batch.arguments[i];
|
|
144
|
+
// Check witness
|
|
145
|
+
const path = Path.fromKey(mapPath, Field, counter);
|
|
146
|
+
args.witness
|
|
147
|
+
.checkMembership(stateRoot, path, Poseidon.hash(Withdrawal.toFields(args.value)))
|
|
148
|
+
.assertTrue("Provided Withdrawal witness not valid");
|
|
149
|
+
// Process message
|
|
150
|
+
const { address, amount } = args.value;
|
|
151
|
+
const isDummy = address.equals(this.address);
|
|
152
|
+
const tokenAu = this.token.mint({ address, amount });
|
|
153
|
+
const isNewAccount = tokenAu.account.isNew.getAndAssertEquals();
|
|
154
|
+
tokenAu.body.balanceChange.magnitude =
|
|
155
|
+
tokenAu.body.balanceChange.magnitude.sub(Provable.if(isNewAccount, Mina.accountCreationFee().toConstant(), UInt64.zero));
|
|
156
|
+
accountCreationFeePaid = accountCreationFeePaid.add(Provable.if(isNewAccount, Field(1e9), Field(0)));
|
|
157
|
+
counter = counter.add(Provable.if(isDummy, Field(0), Field(1)));
|
|
158
|
+
}
|
|
159
|
+
this.balance.subInPlace(UInt64.from(accountCreationFeePaid));
|
|
160
|
+
this.outgoingMessageCursor.set(counter);
|
|
161
|
+
}
|
|
162
|
+
redeem(additionUpdate) {
|
|
163
|
+
additionUpdate.body.tokenId.assertEquals(TokenId.default, "Tokenid not default token");
|
|
164
|
+
additionUpdate.body.balanceChange.sgn
|
|
165
|
+
.isPositive()
|
|
166
|
+
.assertTrue("Sign not correct");
|
|
167
|
+
const amount = additionUpdate.body.balanceChange.magnitude;
|
|
168
|
+
// Burn tokens
|
|
169
|
+
this.token.burn({
|
|
170
|
+
address: additionUpdate.publicKey,
|
|
171
|
+
amount,
|
|
172
|
+
});
|
|
173
|
+
// Send mina
|
|
174
|
+
this.approve(additionUpdate);
|
|
175
|
+
this.balance.subInPlace(amount);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
__decorate([
|
|
179
|
+
state(Field),
|
|
180
|
+
__metadata("design:type", Object)
|
|
181
|
+
], SettlementSmartContract.prototype, "sequencerKey", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
state(UInt32),
|
|
184
|
+
__metadata("design:type", Object)
|
|
185
|
+
], SettlementSmartContract.prototype, "lastSettlementL1Block", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
state(Field),
|
|
188
|
+
__metadata("design:type", Object)
|
|
189
|
+
], SettlementSmartContract.prototype, "stateRoot", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
state(Field),
|
|
192
|
+
__metadata("design:type", Object)
|
|
193
|
+
], SettlementSmartContract.prototype, "networkStateHash", void 0);
|
|
194
|
+
__decorate([
|
|
195
|
+
state(Field),
|
|
196
|
+
__metadata("design:type", Object)
|
|
197
|
+
], SettlementSmartContract.prototype, "blockHashRoot", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
state(Field),
|
|
200
|
+
__metadata("design:type", Object)
|
|
201
|
+
], SettlementSmartContract.prototype, "dispatchContractAddressX", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
state(Field),
|
|
204
|
+
__metadata("design:type", Object)
|
|
205
|
+
], SettlementSmartContract.prototype, "outgoingMessageCursor", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
method,
|
|
208
|
+
__metadata("design:type", Function),
|
|
209
|
+
__metadata("design:paramtypes", [PublicKey, PublicKey]),
|
|
210
|
+
__metadata("design:returntype", void 0)
|
|
211
|
+
], SettlementSmartContract.prototype, "initialize", null);
|
|
212
|
+
__decorate([
|
|
213
|
+
method,
|
|
214
|
+
__metadata("design:type", Function),
|
|
215
|
+
__metadata("design:paramtypes", [LazyBlockProof,
|
|
216
|
+
Signature,
|
|
217
|
+
PublicKey,
|
|
218
|
+
PublicKey,
|
|
219
|
+
NetworkState,
|
|
220
|
+
NetworkState,
|
|
221
|
+
Field]),
|
|
222
|
+
__metadata("design:returntype", void 0)
|
|
223
|
+
], SettlementSmartContract.prototype, "settle", null);
|
|
224
|
+
__decorate([
|
|
225
|
+
method,
|
|
226
|
+
__metadata("design:type", Function),
|
|
227
|
+
__metadata("design:paramtypes", [OutgoingMessageArgumentBatch]),
|
|
228
|
+
__metadata("design:returntype", void 0)
|
|
229
|
+
], SettlementSmartContract.prototype, "rollupOutgoingMessages", null);
|
|
230
|
+
__decorate([
|
|
231
|
+
method,
|
|
232
|
+
__metadata("design:type", Function),
|
|
233
|
+
__metadata("design:paramtypes", [AccountUpdate]),
|
|
234
|
+
__metadata("design:returntype", void 0)
|
|
235
|
+
], SettlementSmartContract.prototype, "redeem", null);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PublicKey, UInt64 } from "o1js";
|
|
2
|
+
declare const Deposit_base: (new (value: {
|
|
3
|
+
address: PublicKey;
|
|
4
|
+
amount: UInt64;
|
|
5
|
+
}) => {
|
|
6
|
+
address: PublicKey;
|
|
7
|
+
amount: UInt64;
|
|
8
|
+
}) & {
|
|
9
|
+
_isStruct: true;
|
|
10
|
+
} & import("o1js/dist/node/snarky").ProvablePure<{
|
|
11
|
+
address: PublicKey;
|
|
12
|
+
amount: UInt64;
|
|
13
|
+
}> & {
|
|
14
|
+
toInput: (x: {
|
|
15
|
+
address: PublicKey;
|
|
16
|
+
amount: UInt64;
|
|
17
|
+
}) => {
|
|
18
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
19
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
20
|
+
};
|
|
21
|
+
toJSON: (x: {
|
|
22
|
+
address: PublicKey;
|
|
23
|
+
amount: UInt64;
|
|
24
|
+
}) => {
|
|
25
|
+
address: string;
|
|
26
|
+
amount: string;
|
|
27
|
+
};
|
|
28
|
+
fromJSON: (x: {
|
|
29
|
+
address: string;
|
|
30
|
+
amount: string;
|
|
31
|
+
}) => {
|
|
32
|
+
address: PublicKey;
|
|
33
|
+
amount: UInt64;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare class Deposit extends Deposit_base {
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=Deposit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Deposit.d.ts","sourceRoot":"","sources":["../../../src/settlement/messages/Deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjD,qBAAa,OAAQ,SAAQ,YAG3B;CAAG"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
2
|
+
import { Withdrawal } from "./Withdrawal";
|
|
3
|
+
export declare const OUTGOING_MESSAGE_BATCH_SIZE = 1;
|
|
4
|
+
declare const OutgoingMessageArgument_base: (new (value: {
|
|
5
|
+
witness: RollupMerkleTreeWitness;
|
|
6
|
+
value: Withdrawal;
|
|
7
|
+
}) => {
|
|
8
|
+
witness: RollupMerkleTreeWitness;
|
|
9
|
+
value: Withdrawal;
|
|
10
|
+
}) & {
|
|
11
|
+
_isStruct: true;
|
|
12
|
+
} & import("o1js/dist/node/snarky").ProvablePure<{
|
|
13
|
+
witness: RollupMerkleTreeWitness;
|
|
14
|
+
value: Withdrawal;
|
|
15
|
+
}> & {
|
|
16
|
+
toInput: (x: {
|
|
17
|
+
witness: RollupMerkleTreeWitness;
|
|
18
|
+
value: Withdrawal;
|
|
19
|
+
}) => {
|
|
20
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
21
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
22
|
+
};
|
|
23
|
+
toJSON: (x: {
|
|
24
|
+
witness: RollupMerkleTreeWitness;
|
|
25
|
+
value: Withdrawal;
|
|
26
|
+
}) => {
|
|
27
|
+
witness: {
|
|
28
|
+
path: string[];
|
|
29
|
+
isLeft: boolean[];
|
|
30
|
+
};
|
|
31
|
+
value: {
|
|
32
|
+
address: string;
|
|
33
|
+
amount: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
fromJSON: (x: {
|
|
37
|
+
witness: {
|
|
38
|
+
path: string[];
|
|
39
|
+
isLeft: boolean[];
|
|
40
|
+
};
|
|
41
|
+
value: {
|
|
42
|
+
address: string;
|
|
43
|
+
amount: string;
|
|
44
|
+
};
|
|
45
|
+
}) => {
|
|
46
|
+
witness: RollupMerkleTreeWitness;
|
|
47
|
+
value: Withdrawal;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare class OutgoingMessageArgument extends OutgoingMessageArgument_base {
|
|
51
|
+
static dummy(): OutgoingMessageArgument;
|
|
52
|
+
}
|
|
53
|
+
declare const OutgoingMessageArgumentBatch_base: (new (value: {
|
|
54
|
+
arguments: OutgoingMessageArgument[];
|
|
55
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
56
|
+
}) => {
|
|
57
|
+
arguments: OutgoingMessageArgument[];
|
|
58
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
59
|
+
}) & {
|
|
60
|
+
_isStruct: true;
|
|
61
|
+
} & import("o1js/dist/node/snarky").ProvablePure<{
|
|
62
|
+
arguments: OutgoingMessageArgument[];
|
|
63
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
64
|
+
}> & {
|
|
65
|
+
toInput: (x: {
|
|
66
|
+
arguments: OutgoingMessageArgument[];
|
|
67
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
68
|
+
}) => {
|
|
69
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
70
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
71
|
+
};
|
|
72
|
+
toJSON: (x: {
|
|
73
|
+
arguments: OutgoingMessageArgument[];
|
|
74
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
75
|
+
}) => {
|
|
76
|
+
arguments: {
|
|
77
|
+
witness: {
|
|
78
|
+
path: string[];
|
|
79
|
+
isLeft: boolean[];
|
|
80
|
+
};
|
|
81
|
+
value: {
|
|
82
|
+
address: string;
|
|
83
|
+
amount: string;
|
|
84
|
+
};
|
|
85
|
+
}[];
|
|
86
|
+
isDummys: boolean[];
|
|
87
|
+
};
|
|
88
|
+
fromJSON: (x: {
|
|
89
|
+
arguments: {
|
|
90
|
+
witness: {
|
|
91
|
+
path: string[];
|
|
92
|
+
isLeft: boolean[];
|
|
93
|
+
};
|
|
94
|
+
value: {
|
|
95
|
+
address: string;
|
|
96
|
+
amount: string;
|
|
97
|
+
};
|
|
98
|
+
}[];
|
|
99
|
+
isDummys: boolean[];
|
|
100
|
+
}) => {
|
|
101
|
+
arguments: OutgoingMessageArgument[];
|
|
102
|
+
isDummys: import("o1js/dist/node/lib/bool").Bool[];
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export declare class OutgoingMessageArgumentBatch extends OutgoingMessageArgumentBatch_base {
|
|
106
|
+
static fromMessages(providedArguments: OutgoingMessageArgument[]): OutgoingMessageArgumentBatch;
|
|
107
|
+
}
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=OutgoingMessageArgument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutgoingMessageArgument.d.ts","sourceRoot":"","sources":["../../../src/settlement/messages/OutgoingMessageArgument.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,eAAO,MAAM,2BAA2B,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,uBAAwB,SAAQ,4BAG3C;WACc,KAAK,IAAI,uBAAuB;CAM/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,qBAAa,4BAA6B,SAAQ,iCAOhD;WACc,YAAY,CAAC,iBAAiB,EAAE,uBAAuB,EAAE;CAcxE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Bool, Provable, Struct } from "o1js";
|
|
2
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
3
|
+
import { Withdrawal } from "./Withdrawal";
|
|
4
|
+
export const OUTGOING_MESSAGE_BATCH_SIZE = 1;
|
|
5
|
+
export class OutgoingMessageArgument extends Struct({
|
|
6
|
+
witness: RollupMerkleTreeWitness,
|
|
7
|
+
value: Withdrawal,
|
|
8
|
+
}) {
|
|
9
|
+
static dummy() {
|
|
10
|
+
return new OutgoingMessageArgument({
|
|
11
|
+
witness: RollupMerkleTreeWitness.dummy(),
|
|
12
|
+
value: Withdrawal.dummy(),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class OutgoingMessageArgumentBatch extends Struct({
|
|
17
|
+
arguments: Provable.Array(OutgoingMessageArgument, OUTGOING_MESSAGE_BATCH_SIZE),
|
|
18
|
+
isDummys: Provable.Array(Bool, OUTGOING_MESSAGE_BATCH_SIZE),
|
|
19
|
+
}) {
|
|
20
|
+
static fromMessages(providedArguments) {
|
|
21
|
+
const batch = providedArguments.slice();
|
|
22
|
+
const isDummys = batch.map(() => Bool(false));
|
|
23
|
+
while (batch.length < OUTGOING_MESSAGE_BATCH_SIZE) {
|
|
24
|
+
batch.push(OutgoingMessageArgument.dummy());
|
|
25
|
+
isDummys.push(Bool(true));
|
|
26
|
+
}
|
|
27
|
+
return new OutgoingMessageArgumentBatch({
|
|
28
|
+
arguments: batch,
|
|
29
|
+
isDummys,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PublicKey, UInt64 } from "o1js";
|
|
2
|
+
declare const Withdrawal_base: (new (value: {
|
|
3
|
+
address: PublicKey;
|
|
4
|
+
amount: UInt64;
|
|
5
|
+
}) => {
|
|
6
|
+
address: PublicKey;
|
|
7
|
+
amount: UInt64;
|
|
8
|
+
}) & {
|
|
9
|
+
_isStruct: true;
|
|
10
|
+
} & import("o1js/dist/node/snarky").ProvablePure<{
|
|
11
|
+
address: PublicKey;
|
|
12
|
+
amount: UInt64;
|
|
13
|
+
}> & {
|
|
14
|
+
toInput: (x: {
|
|
15
|
+
address: PublicKey;
|
|
16
|
+
amount: UInt64;
|
|
17
|
+
}) => {
|
|
18
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
19
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
20
|
+
};
|
|
21
|
+
toJSON: (x: {
|
|
22
|
+
address: PublicKey;
|
|
23
|
+
amount: UInt64;
|
|
24
|
+
}) => {
|
|
25
|
+
address: string;
|
|
26
|
+
amount: string;
|
|
27
|
+
};
|
|
28
|
+
fromJSON: (x: {
|
|
29
|
+
address: string;
|
|
30
|
+
amount: string;
|
|
31
|
+
}) => {
|
|
32
|
+
address: PublicKey;
|
|
33
|
+
amount: UInt64;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare class Withdrawal extends Withdrawal_base {
|
|
37
|
+
static dummy(): Withdrawal;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=Withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Withdrawal.d.ts","sourceRoot":"","sources":["../../../src/settlement/messages/Withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGjD,qBAAa,UAAW,SAAQ,eAG9B;WACc,KAAK;CAMpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PublicKey, Struct, UInt64 } from "o1js";
|
|
2
|
+
import { EMPTY_PUBLICKEY } from "@proto-kit/common";
|
|
3
|
+
export class Withdrawal extends Struct({
|
|
4
|
+
address: PublicKey,
|
|
5
|
+
amount: UInt64,
|
|
6
|
+
}) {
|
|
7
|
+
static dummy() {
|
|
8
|
+
return new Withdrawal({
|
|
9
|
+
address: EMPTY_PUBLICKEY,
|
|
10
|
+
amount: UInt64.from(0),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Field, PublicKey, UInt32 } from "o1js";
|
|
2
|
+
import type { BlockProof } from "../../prover/block/BlockProver";
|
|
3
|
+
import { ProtocolModule } from "../../protocol/ProtocolModule";
|
|
4
|
+
import { NetworkState } from "../../model/network/NetworkState";
|
|
5
|
+
import type { SettlementSmartContract } from "../contracts/SettlementSmartContract";
|
|
6
|
+
export type SettlementStateRecord = {
|
|
7
|
+
sequencerKey: PublicKey;
|
|
8
|
+
lastSettlementL1Block: UInt32;
|
|
9
|
+
stateRoot: Field;
|
|
10
|
+
networkStateHash: Field;
|
|
11
|
+
blockHashRoot: Field;
|
|
12
|
+
};
|
|
13
|
+
export type SettlementHookInputs = {
|
|
14
|
+
blockProof: BlockProof;
|
|
15
|
+
fromNetworkState: NetworkState;
|
|
16
|
+
toNetworkState: NetworkState;
|
|
17
|
+
newPromisedMessagesHash: Field;
|
|
18
|
+
contractState: SettlementStateRecord;
|
|
19
|
+
currentL1Block: UInt32;
|
|
20
|
+
};
|
|
21
|
+
export declare abstract class ProvableSettlementHook<Config> extends ProtocolModule<Config> {
|
|
22
|
+
abstract beforeSettlement(smartContract: SettlementSmartContract, inputs: SettlementHookInputs): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ProvableSettlementHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProvableSettlementHook.d.ts","sourceRoot":"","sources":["../../../src/settlement/modularity/ProvableSettlementHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAEpF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,SAAS,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAE9B,SAAS,EAAE,KAAK,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;IACxB,aAAa,EAAE,KAAK,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,gBAAgB,EAAE,YAAY,CAAC;IAC/B,cAAc,EAAE,YAAY,CAAC;IAC7B,uBAAuB,EAAE,KAAK,CAAC;IAC/B,aAAa,EAAE,qBAAqB,CAAC;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,8BAAsB,sBAAsB,CAC1C,MAAM,CACN,SAAQ,cAAc,CAAC,MAAM,CAAC;aACd,gBAAgB,CAC9B,aAAa,EAAE,uBAAuB,EACtC,MAAM,EAAE,oBAAoB,GAC3B,IAAI;CACR"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UInt64 } from "o1js";
|
|
2
|
+
import { ProvableSettlementHook, SettlementHookInputs } from "../modularity/ProvableSettlementHook";
|
|
3
|
+
import { SettlementSmartContract } from "../contracts/SettlementSmartContract";
|
|
4
|
+
type NetworkStateSettlementModuleConfig = {
|
|
5
|
+
blocksPerL1Block: UInt64;
|
|
6
|
+
};
|
|
7
|
+
export declare class NetworkStateSettlementModule extends ProvableSettlementHook<NetworkStateSettlementModuleConfig> {
|
|
8
|
+
beforeSettlement(smartContract: SettlementSmartContract, { blockProof, fromNetworkState, toNetworkState, contractState, currentL1Block, }: SettlementHookInputs): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=NetworkStateSettlementModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkStateSettlementModule.d.ts","sourceRoot":"","sources":["../../../src/settlement/modules/NetworkStateSettlementModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,KAAK,kCAAkC,GAAG;IACxC,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,qBAAa,4BAA6B,SAAQ,sBAAsB,CAAC,kCAAkC,CAAC;IACnG,gBAAgB,CACrB,aAAa,EAAE,uBAAuB,EACtC,EACE,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,cAAc,GACf,EAAE,oBAAoB,GACtB,IAAI;CAgBR"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProvableSettlementHook, } from "../modularity/ProvableSettlementHook";
|
|
2
|
+
export class NetworkStateSettlementModule extends ProvableSettlementHook {
|
|
3
|
+
beforeSettlement(smartContract, { blockProof, fromNetworkState, toNetworkState, contractState, currentL1Block, }) {
|
|
4
|
+
const { lastSettlementL1Block } = contractState;
|
|
5
|
+
const blocksPerL1Block = this.config.blocksPerL1Block.toConstant();
|
|
6
|
+
const numL1Blocks = currentL1Block.sub(lastSettlementL1Block);
|
|
7
|
+
const expectedHeightDiff = numL1Blocks.toUInt64().mul(blocksPerL1Block);
|
|
8
|
+
const actualHeightDiff = toNetworkState.block.height.sub(fromNetworkState.block.height);
|
|
9
|
+
const acceptableDerivation = numL1Blocks.mul(1).div(10);
|
|
10
|
+
// TODO Check within bounds efficiently
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAwChB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;;;OAKG;IACI,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAc3B;;;;;;;;;;OAUG;IACI,GAAG,CAAC,KAAK,EAAE,KAAK;CAiBxB"}
|
package/dist/state/State.js
CHANGED
|
@@ -51,7 +51,8 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
51
51
|
.resolve(RuntimeMethodExecutionContext)
|
|
52
52
|
.current().result;
|
|
53
53
|
// First try to find a match inside already created stateTransitions
|
|
54
|
-
|
|
54
|
+
let previousMutatingTransitions = [];
|
|
55
|
+
previousMutatingTransitions = stateTransitions.filter((transition) => transition.path.equals(path).and(transition.to.isSome).toBoolean());
|
|
55
56
|
const pmtLength = previousMutatingTransitions.length;
|
|
56
57
|
let value = pmtLength > 0
|
|
57
58
|
? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/state/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/state/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,MAAM,MAAM,CAAC;AAMtC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,QAevD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Provable } from "o1js";
|
|
1
2
|
import { container } from "tsyringe";
|
|
2
3
|
import { log } from "@proto-kit/common";
|
|
3
4
|
import { RuntimeMethodExecutionContext } from "../context/RuntimeMethodExecutionContext";
|
|
@@ -14,11 +15,13 @@ export function assert(condition, message) {
|
|
|
14
15
|
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
15
16
|
const previousStatus = executionContext.current().result.status;
|
|
16
17
|
const status = condition.and(previousStatus);
|
|
17
|
-
|
|
18
|
-
if (!
|
|
19
|
-
|
|
18
|
+
Provable.asProver(() => {
|
|
19
|
+
if (!condition.toBoolean()) {
|
|
20
|
+
if (!executionContext.current().isSimulated) {
|
|
21
|
+
log.debug("Assertion failed: ", message);
|
|
22
|
+
}
|
|
23
|
+
executionContext.setStatusMessage(message);
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
}
|
|
25
|
+
});
|
|
23
26
|
executionContext.setStatus(status);
|
|
24
27
|
}
|