@sig-net/midnight 0.24.0-rc.1 → 0.24.0-rc.3
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/README.md +19 -24
- package/dist/compact-descriptors.d.ts +22 -7
- package/dist/compact-descriptors.d.ts.map +1 -1
- package/dist/compact-descriptors.js +39 -28
- package/dist/compact-descriptors.js.map +1 -1
- package/dist/constants.d.ts +3 -22
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -25
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +43 -15
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +47 -17
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +1212 -13
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +282 -7
- package/dist/managed/contract/index.js +1072 -161
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/mpc-output-cache.d.ts +5 -29
- package/dist/mpc-output-cache.d.ts.map +1 -1
- package/dist/mpc-output-cache.js +8 -42
- package/dist/mpc-output-cache.js.map +1 -1
- package/dist/signature-requests-state-reader.js +3 -3
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signet-contract-events.d.ts +40 -10
- package/dist/signet-contract-events.d.ts.map +1 -1
- package/dist/signet-contract-events.js +79 -29
- package/dist/signet-contract-events.js.map +1 -1
- package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -1
- package/dist/signet-evtype2tx-record-decoding.js +6 -5
- package/dist/signet-evtype2tx-record-decoding.js.map +1 -1
- package/dist/signet-evtype2tx-requests.d.ts +17 -12
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +85 -16
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-id.d.ts +5 -2
- package/dist/signet-request-id.d.ts.map +1 -1
- package/dist/signet-request-id.js +21 -9
- package/dist/signet-request-id.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +2 -4
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +7 -11
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +48 -17
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +18 -6
- package/dist/signet-requests.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +3 -8
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +258 -80
- package/src/circuits.compact +68 -13
package/dist/testing.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { calculateSignetAttestationDigest, type EcdsaSignature, ecdsaSignatureToMpcSignature, secp256k1PublicKeyOf, signAttestationDigest, signatureToSignatureRespondedEvent, } from "./ecdsa-attestation.ts";
|
|
1
|
+
export { attestRespondBidirectional, calculateSignetAttestationDigest, type EcdsaSignature, ecdsaSignatureToMpcSignature, type RespondBidirectionalAttestation, secp256k1PublicKeyOf, signAttestationDigest, signatureToSignatureRespondedEvent, } from "./ecdsa-attestation.ts";
|
|
2
2
|
export { deriveMidnightResponseSecretKey } from "./epsilon-derivation.ts";
|
|
3
3
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,KAAK,cAAc,EACnB,4BAA4B,EAC5B,KAAK,+BAA+B,EACpC,oBAAoB,EACpB,qBAAqB,EACrB,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/testing.js
CHANGED
|
@@ -7,14 +7,9 @@
|
|
|
7
7
|
// MPC's test double, posts through these same helpers, which keeps its bytes
|
|
8
8
|
// pinned to this package's decoders.
|
|
9
9
|
//
|
|
10
|
-
// The canonical fixture
|
|
11
|
-
//
|
|
12
|
-
// signAttestationDigest(
|
|
13
|
-
// calculateSignetAttestationDigest(requestId, blockHeight, serializedOutput),
|
|
14
|
-
// secretKey,
|
|
15
|
-
// ),
|
|
16
|
-
// )
|
|
10
|
+
// The canonical fixture:
|
|
11
|
+
// attestRespondBidirectional({ requestId, blockHeight, outputKind, serializedOutput }, secretKey)
|
|
17
12
|
// verifies in-circuit against secp256k1PublicKeyOf(secretKey).
|
|
18
|
-
export { calculateSignetAttestationDigest, ecdsaSignatureToMpcSignature, secp256k1PublicKeyOf, signAttestationDigest, signatureToSignatureRespondedEvent, } from "./ecdsa-attestation.js";
|
|
13
|
+
export { attestRespondBidirectional, calculateSignetAttestationDigest, ecdsaSignatureToMpcSignature, secp256k1PublicKeyOf, signAttestationDigest, signatureToSignatureRespondedEvent, } from "./ecdsa-attestation.js";
|
|
19
14
|
export { deriveMidnightResponseSecretKey } from "./epsilon-derivation.js";
|
|
20
15
|
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AACzE,2EAA2E;AAC3E,4DAA4D;AAC5D,4EAA4E;AAC5E,6EAA6E;AAC7E,qCAAqC;AACrC,EAAE;AACF
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AACzE,2EAA2E;AAC3E,4DAA4D;AAC5D,4EAA4E;AAC5E,6EAA6E;AAC7E,qCAAqC;AACrC,EAAE;AACF,yBAAyB;AACzB,oGAAoG;AACpG,+DAA+D;AAE/D,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAEhC,4BAA4B,EAE5B,oBAAoB,EACpB,qBAAqB,EACrB,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sig-net/midnight",
|
|
3
|
-
"version": "0.24.0-rc.
|
|
3
|
+
"version": "0.24.0-rc.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sig-net/midnight-integration",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@midnight-ntwrk/compact-runtime": "0.18.0-rc.1",
|
|
50
50
|
"@midnight-ntwrk/midnight-js-types": "5.0.0-beta.6",
|
|
51
51
|
"@noble/curves": "^2.2.0",
|
|
52
|
-
"@sig-net/midnight-serde": "^0.24.0-rc.
|
|
52
|
+
"@sig-net/midnight-serde": "^0.24.0-rc.3",
|
|
53
53
|
"ethers": "^6.17.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
package/src/Signet.compact
CHANGED
|
@@ -18,16 +18,23 @@
|
|
|
18
18
|
// import "@sig-net/midnight/src/Signet";
|
|
19
19
|
//
|
|
20
20
|
// Key types at a glance (each declaration below carries the full contract):
|
|
21
|
-
// -
|
|
22
|
-
// - RequestId: 32-byte id of a request, the transientHash of
|
|
23
|
-
//
|
|
21
|
+
// - SignBidirectionalEventV1: a client contract's structured request for a signature on a transaction.
|
|
22
|
+
// - RequestId: 32-byte id of a request, the transientHash of its RequestIdPreimageV1 (the fields
|
|
23
|
+
// that name one execution: key, sender, path, a digest of the transaction and its destination).
|
|
24
|
+
// - SignBidirectionalEventMapV1: the RequestId -> SignBidirectionalEventV1 map a client contract
|
|
24
25
|
// declares in its own ledger for the MPC to read requests from.
|
|
25
26
|
// - SignetSigner: the contract interface client contracts call to notify the Signet singleton.
|
|
26
|
-
// - SignBidirectionalEventNotification: the
|
|
27
|
-
//
|
|
28
|
-
// -
|
|
27
|
+
// - SignBidirectionalEventNotification: the notification delivered through that call, versioned by
|
|
28
|
+
// the version byte it carries.
|
|
29
|
+
// - SignatureRespondedEventV1: the MPC's posted signature answering a request.
|
|
30
|
+
// - RespondBidirectionalEventV1: the MPC's posted attestation that the foreign chain executed the
|
|
29
31
|
// signed transaction.
|
|
30
32
|
//
|
|
33
|
+
// The V1 suffix marks the wire and hash-domain artefacts of protocol version 1 (the structs the
|
|
34
|
+
// ledger stores and the singleton emits, and the circuits that hash or verify them). Vocabulary
|
|
35
|
+
// shared across versions (RequestId, OutputKind, Signature, the enums, the transaction parameter
|
|
36
|
+
// structs, which TxParamType tags) and the version-tagged notification carry no suffix.
|
|
37
|
+
//
|
|
31
38
|
// These key types are best understood within the sign bidirectional flow that they enable:
|
|
32
39
|
// 1. Client contract stores a SignBidirectionalEvent in a SignBidirectionalEventMap in its own ledger
|
|
33
40
|
// (against the calculated RequestId) and requests a signature from the MPC via a cross contract call
|
|
@@ -42,8 +49,8 @@
|
|
|
42
49
|
// the requested signing key. Then it broadcasts the signed txn to the destination chain.
|
|
43
50
|
// 4. MPC observes txn execution on destination chain and posts a RespondBidirectionalEvent attestation
|
|
44
51
|
// through the Signet singleton, which emits it as a contract event beside the request id.
|
|
45
|
-
// The client polls its request's posts and takes the first one that verifies over the request id
|
|
46
|
-
// and output. The client obtains the execution output off chain (for EVM: the mined
|
|
52
|
+
// The client polls its request's posts and takes the first one that verifies over the request id,
|
|
53
|
+
// block height, output kind and output. The client obtains the execution output off chain (for EVM: the mined
|
|
47
54
|
// call's return data via debug_traceTransaction, or the exact attested bytes from the
|
|
48
55
|
// MPC's output cache) and hands output plus attestation to its verify circuit. See
|
|
49
56
|
// "Output Recovery" in the repository README.
|
|
@@ -66,37 +73,40 @@ module Signet {
|
|
|
66
73
|
//
|
|
67
74
|
// KEY: texual order of the fields in this structure must remain fixed as is as their order
|
|
68
75
|
// is relied upon for consistent hashing and decoding from ledger state.
|
|
69
|
-
export struct
|
|
70
|
-
//
|
|
71
|
-
// Set with kernel.self().
|
|
72
|
-
sender: ContractAddress;
|
|
76
|
+
export struct SignBidirectionalEventV1<TxParams, #LenOutputDeserialization, #LenRespondSerialization> {
|
|
77
|
+
// ---- RequestIdPreimageV1 fields: hashed into the request id, in this order ----
|
|
73
78
|
|
|
74
79
|
// MPC Key Derivation Parameters.
|
|
75
80
|
// Every key the MPC signs with is scoped by the requesting contract:
|
|
76
81
|
// derivedSigningKey = f(mpcRootKey[keyVersion], caip2ChainId, sender, hex::encode(path))
|
|
77
82
|
// where caip2ChainId is the CAIP-2 id of the ORIGINATING chain (the Midnight
|
|
78
83
|
// variant for requests made from Midnight contracts), not this record's target
|
|
79
|
-
//
|
|
84
|
+
// executionDest. The path is 32 opaque bytes of the client contract's choosing (e.g. a
|
|
80
85
|
// fixed literal for a contract-owned account or a hash of a caller's secret for
|
|
81
86
|
// per-user accounts): no format is enforced, any 32 bytes are valid.
|
|
82
87
|
// CRITICAL: the MPC renders the path as hex::encode(path) for key derivation (lowercase hex
|
|
83
88
|
// of the full 32 bytes, no trimming, no 0x prefix). The sender is always part
|
|
84
89
|
// of the derivation, so no contract can reach another contract's derived keys.
|
|
85
|
-
keyVersion: Uint<8>;
|
|
86
|
-
|
|
90
|
+
keyVersion: Uint<8>; // MPC root-key version to derive from. Currently 1.
|
|
91
|
+
sender: ContractAddress; // Address of the client contract that stores and notifies of this
|
|
92
|
+
// request. Set with kernel.self().
|
|
93
|
+
path: Bytes<32>; // Key derivation path: 32 opaque bytes, client contract's choice.
|
|
87
94
|
|
|
88
95
|
// MPC Parameters.
|
|
89
|
-
algo: MPCSignatureAlgorithm;
|
|
90
|
-
dest: MPCDestination; // Destination field reserved for future use. Set to unused.
|
|
91
|
-
params: Bytes<64>; // Extra MPC parameters reserved for future use. Zero-fill.
|
|
96
|
+
algo: MPCSignatureAlgorithm; // Signature algorithm scheme, e.g. ecdsa
|
|
92
97
|
|
|
93
98
|
// Specific destination chain Transaction parameters.
|
|
94
|
-
txParamType: TxParamType;
|
|
95
|
-
txParams: TxParams;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
txParamType: TxParamType; // Off-chain tag indicating what type txParams is set to.
|
|
100
|
+
txParams: TxParams; // The generic transaction-param payload
|
|
101
|
+
executionDest: Bytes<32>; // The MPC's routing key for the target chain, in CAIP-2 form
|
|
102
|
+
// (https://chainagnostic.org/CAIPs/caip-2). An Ethereum target
|
|
103
|
+
// (mainnet, Sepolia or a local anvil) uses ethereumCaip2Id():
|
|
104
|
+
// the network itself is txParams' chainId.
|
|
105
|
+
|
|
106
|
+
// ---- Protocol-only fields: outside the request id ----
|
|
107
|
+
|
|
108
|
+
signatureDest: MPCDestination; // Destination field reserved for future use. Set to unused.
|
|
109
|
+
params: Bytes<64>; // Extra MPC parameters reserved for future use. Zero-fill.
|
|
100
110
|
|
|
101
111
|
// Serialisation Schemas.
|
|
102
112
|
// outputDeserializationSchema tells the MPC how to deserialise the destination chain's
|
|
@@ -130,32 +140,37 @@ module Signet {
|
|
|
130
140
|
reserved, // Reserved for future use. Exists to keep enum >= 2 (proof server bug).
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
// Construction helper for the canonical Signet
|
|
134
|
-
export pure circuit
|
|
135
|
-
sender: ContractAddress,
|
|
143
|
+
// Construction helper for the canonical Signet SignBidirectionalEventV1.
|
|
144
|
+
export pure circuit constructSignBidirectionalEventV1<TxParams, #LenOutputDeserialization, #LenRespondSerialization>(
|
|
136
145
|
keyVersion: Uint<8>,
|
|
146
|
+
sender: ContractAddress,
|
|
137
147
|
path: Bytes<32>,
|
|
138
148
|
algo: MPCSignatureAlgorithm,
|
|
139
|
-
dest: MPCDestination,
|
|
140
|
-
params: Bytes<64>,
|
|
141
149
|
txParamType: TxParamType,
|
|
142
150
|
txParams: TxParams,
|
|
143
|
-
|
|
151
|
+
executionDest: Bytes<32>,
|
|
152
|
+
signatureDest: MPCDestination,
|
|
153
|
+
params: Bytes<64>,
|
|
144
154
|
outputDeserializationSchema: Bytes<LenOutputDeserialization>,
|
|
145
155
|
respondSerializationSchema: Bytes<LenRespondSerialization>,
|
|
146
|
-
):
|
|
156
|
+
): SignBidirectionalEventV1<TxParams, LenOutputDeserialization, LenRespondSerialization> {
|
|
147
157
|
assert(keyVersion >= 1, "keyVersion must be >= 1");
|
|
158
|
+
// The protocol reserves the "midnight response key" path for the MPC's
|
|
159
|
+
// attestation key of this contract (see RespondBidirectionalEventV1), and the
|
|
160
|
+
// MPC refuses a request that names it.
|
|
161
|
+
assert(path != pad(32, "midnight response key"), "path is reserved for the MPC response key");
|
|
148
162
|
|
|
149
|
-
|
|
150
|
-
|
|
163
|
+
// Shorthand struct fields bind positionally: this list follows the declaration order.
|
|
164
|
+
return SignBidirectionalEventV1<TxParams, LenOutputDeserialization, LenRespondSerialization> {
|
|
151
165
|
keyVersion,
|
|
166
|
+
sender,
|
|
152
167
|
path,
|
|
153
168
|
algo,
|
|
154
|
-
dest,
|
|
155
|
-
params,
|
|
156
169
|
txParamType,
|
|
157
170
|
txParams,
|
|
158
|
-
|
|
171
|
+
executionDest,
|
|
172
|
+
signatureDest,
|
|
173
|
+
params,
|
|
159
174
|
outputDeserializationSchema,
|
|
160
175
|
respondSerializationSchema,
|
|
161
176
|
};
|
|
@@ -163,26 +178,45 @@ module Signet {
|
|
|
163
178
|
|
|
164
179
|
// ---- SignBidirectionalEvent RequestId --------------------------------------------------------------
|
|
165
180
|
|
|
166
|
-
// 32 byte chain agnostic nominal id, calculated as the
|
|
167
|
-
//
|
|
181
|
+
// 32 byte chain agnostic nominal id of a SignBidirectionalEvent, calculated as the
|
|
182
|
+
// transientHash of its RequestIdPreimageV1 (see calculateRequestIdV1).
|
|
168
183
|
export new type RequestId = Bytes<32>;
|
|
169
184
|
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
185
|
+
// The fields of a SignBidirectionalEventV1 that name one execution: the signing key
|
|
186
|
+
// (keyVersion, path, algo), the requesting contract, the transaction and its execution
|
|
187
|
+
// destination. Fields the execution does not depend on (the serialisation schemas and
|
|
188
|
+
// the reserved MPC parameters signatureDest and params) stay out. The transaction
|
|
189
|
+
// enters as a digest computed per TxParamType over its USED entries only
|
|
190
|
+
// (calculateEvmType2TxParamsDigestV1 for evmType2), so one execution has one id
|
|
191
|
+
// whatever capacities the requester compiled with and whatever sits in unused slots.
|
|
192
|
+
//
|
|
193
|
+
// KEY: the field order follows SignBidirectionalEventV1's and is relied upon for consistent
|
|
194
|
+
// hashing. The TS twin (requestIdPreimageDescriptor in signet-requests.ts) mirrors it
|
|
195
|
+
// field by field.
|
|
196
|
+
export struct RequestIdPreimageV1 {
|
|
197
|
+
keyVersion: Uint<8>;
|
|
198
|
+
sender: ContractAddress;
|
|
199
|
+
path: Bytes<32>;
|
|
200
|
+
algo: MPCSignatureAlgorithm;
|
|
201
|
+
txParamType: TxParamType;
|
|
202
|
+
txParamsDigest: Bytes<32>;
|
|
203
|
+
executionDest: Bytes<32>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// transientHash (Poseidon over the preimage's field-aligned representation) upgraded
|
|
207
|
+
// to Bytes<32>: the id commits to every preimage field, including the sender, and
|
|
208
|
+
// carries no domain-separation tag. Off-chain twins must reproduce the field-aligned
|
|
209
|
+
// layout exactly.
|
|
174
210
|
//
|
|
175
211
|
// Two properties follow from the field-aligned representation and matter to anyone
|
|
176
212
|
// reasoning about these ids:
|
|
177
213
|
// - byte 31 is always zero. upgradeFromTransient writes the field element's 31
|
|
178
214
|
// little-endian bytes into bytes 0..30, so an id carries ~248 bits of entropy.
|
|
179
215
|
// - a Bytes<N> field packs into ceil(N/31) field elements, so trailing zero bytes
|
|
180
|
-
// within a chunk do not change the hash.
|
|
181
|
-
//
|
|
182
|
-
export pure circuit
|
|
183
|
-
|
|
184
|
-
): RequestId {
|
|
185
|
-
return upgradeFromTransient(transientHash<SignBidirectionalEvent<TxParams, LenOutputDeserialization, LenRespondSerialization>>(request)) as RequestId;
|
|
216
|
+
// within a chunk do not change the hash. Every id commits to its sender, so
|
|
217
|
+
// requests cannot collide in practice.
|
|
218
|
+
export pure circuit calculateRequestIdV1(preimage: RequestIdPreimageV1): RequestId {
|
|
219
|
+
return upgradeFromTransient(transientHash<RequestIdPreimageV1>(preimage)) as RequestId;
|
|
186
220
|
}
|
|
187
221
|
|
|
188
222
|
// ---- Client Contract: SignBidirectionalEvent Map ---------------------------------------------------
|
|
@@ -191,7 +225,7 @@ module Signet {
|
|
|
191
225
|
// in their ledger. Client contract tells MPC field location of this map when making a cross
|
|
192
226
|
// contract call, via SignetSigner, to the Signet singleton. The MPC looks here to find
|
|
193
227
|
// SignBidirectionalEvents.
|
|
194
|
-
export new type
|
|
228
|
+
export new type SignBidirectionalEventMapV1<TxParams, #LenOutputDeserialization, #LenRespondSerialization> = Map<RequestId, SignBidirectionalEventV1<TxParams, LenOutputDeserialization, LenRespondSerialization>>;
|
|
195
229
|
|
|
196
230
|
// ---- Cross Contract SignBidirectionalEventNotification ---------------------------------------------
|
|
197
231
|
|
|
@@ -200,7 +234,7 @@ module Signet {
|
|
|
200
234
|
export contract SignetSigner {
|
|
201
235
|
// Called by client contracts to notify the MPC of a SignBidirectionalEvent.
|
|
202
236
|
circuit signBidirectional(
|
|
203
|
-
// Canonical id of the SignBidirectionalEvent (
|
|
237
|
+
// Canonical id of the SignBidirectionalEvent (calculateEvmType2RequestIdV1 for evmType2).
|
|
204
238
|
// Disclosed in the emitted notification event: the MPC looks this id up in the
|
|
205
239
|
// caller's own request map.
|
|
206
240
|
requestId: RequestId,
|
|
@@ -223,7 +257,7 @@ module Signet {
|
|
|
223
257
|
// Construction helper for the V1 SignBidirectionalEventNotification.
|
|
224
258
|
//
|
|
225
259
|
// The payload is a pointer for the MPC: the contract that holds the
|
|
226
|
-
//
|
|
260
|
+
// SignBidirectionalEventMapV1 (callerAddress) and the position of that map in
|
|
227
261
|
// the contract's raw ledger state tree (requestsPathDepth + requestsPath).
|
|
228
262
|
//
|
|
229
263
|
// Read the path from your contract's compiled artifacts, never derive it by
|
|
@@ -239,7 +273,7 @@ module Signet {
|
|
|
239
273
|
// Number of meaningful entries in requestsPath: 1 for a flat (15 or fewer
|
|
240
274
|
// field) contract, one more per chunk level after that (max 4).
|
|
241
275
|
requestsPathDepth: Uint<8>,
|
|
242
|
-
// Resolved ledger-tree path of the caller's
|
|
276
|
+
// Resolved ledger-tree path of the caller's SignBidirectionalEventMapV1, from
|
|
243
277
|
// its contract-info.json "index". Entries at and beyond requestsPathDepth
|
|
244
278
|
// are zero.
|
|
245
279
|
requestsPath: Vector<4, Uint<8>>
|
|
@@ -276,7 +310,10 @@ module Signet {
|
|
|
276
310
|
// Counterpart to SignBidirectionalEvent: the MPC generated signature a request asked for.
|
|
277
311
|
// Posted by the MPC through the Signet singleton for clients to extract and build a
|
|
278
312
|
// signed transaction from.
|
|
279
|
-
export struct
|
|
313
|
+
export struct SignatureRespondedEventV1 {
|
|
314
|
+
// The request this signature answers. Routing data: the singleton emits it
|
|
315
|
+
// unverified, and a reader proves the signature against the request's own key.
|
|
316
|
+
requestId: RequestId;
|
|
280
317
|
// The requested signature over the transaction the request describes.
|
|
281
318
|
signature: Signature;
|
|
282
319
|
}
|
|
@@ -284,7 +321,7 @@ module Signet {
|
|
|
284
321
|
// RespondBidirectionalEvent: the MPC's attestation of a foreign execution, the
|
|
285
322
|
// final step of the sign bidirectional flow.
|
|
286
323
|
//
|
|
287
|
-
// attestationDigest = upgradeFromTransient(transientHash([requestId, blockHeight, serializedOutputLength, serializedOutput]))
|
|
324
|
+
// attestationDigest = upgradeFromTransient(transientHash([requestId, blockHeight, outputKind, serializedOutputLength, serializedOutput]))
|
|
288
325
|
// signature = signSECP256k1(mpcResponseKey, attestationDigest)
|
|
289
326
|
//
|
|
290
327
|
// mpcResponseKey is derived like request signing keys, with the path set to the
|
|
@@ -293,50 +330,83 @@ module Signet {
|
|
|
293
330
|
// mpcResponseKey = f(mpcRootKey[keyVersion], caip2ChainId, sender, "midnight response key")
|
|
294
331
|
//
|
|
295
332
|
// The output travels off chain and the digest is recomputed at verification
|
|
296
|
-
// time (
|
|
333
|
+
// time (verifyRespondBidirectionalEventV1). The signature is the ONLY thing that
|
|
297
334
|
// distinguishes a genuine post from garbage: the singleton emits every post
|
|
298
335
|
// unverified.
|
|
299
|
-
export struct
|
|
336
|
+
export struct RespondBidirectionalEventV1 {
|
|
337
|
+
// The request this attestation answers. Signed into the digest: a verified
|
|
338
|
+
// post settles exactly the request it names, so a client consumes this id
|
|
339
|
+
// and never one taken from elsewhere.
|
|
340
|
+
requestId: RequestId;
|
|
341
|
+
// Height of the finalised destination block holding the transaction the
|
|
342
|
+
// attestation describes, in the destination chain's own numbering (a slot
|
|
343
|
+
// on Solana). Signed into the digest.
|
|
344
|
+
blockHeight: Uint<64>;
|
|
345
|
+
// The MPC's verdict on the execution, signed into the digest.
|
|
346
|
+
outputKind: OutputKind;
|
|
347
|
+
// Byte width of the serialised output the digest commits to (0 for a failed
|
|
348
|
+
// or unviable execution), so a client holding no output yet knows which
|
|
349
|
+
// width to settle at.
|
|
350
|
+
serializedOutputLength: Uint<64>;
|
|
351
|
+
// The attestation digest the signature is over (calculateSignetAttestationDigestV1),
|
|
352
|
+
// so a reader holding no output can check the signature. The verifying
|
|
353
|
+
// circuit recomputes it from the output and never reads this copy.
|
|
354
|
+
digest: Bytes<32>;
|
|
300
355
|
// The MPC's ECDSA signature over the attestation digest.
|
|
301
356
|
signature: Signature;
|
|
302
357
|
}
|
|
303
358
|
|
|
304
|
-
//
|
|
305
|
-
//
|
|
306
|
-
//
|
|
359
|
+
// OutputKind is the MPC's verdict on a request's execution, the kind half of
|
|
360
|
+
// the protocol's outcome (kind, data). The block height the attestation
|
|
361
|
+
// commits to is the finalised destination block that settled the verdict.
|
|
362
|
+
export enum OutputKind {
|
|
363
|
+
executed, // finalised and succeeded: the attested output is the return data, serialised per the respond schema
|
|
364
|
+
failed, // finalised and reverted: the attested output is empty (Bytes<0>)
|
|
365
|
+
unviable, // a finalised transaction carrying other bytes took the nonce: the attested output is empty (Bytes<0>)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// The 32-byte attestation digest of a remote execution output:
|
|
369
|
+
// attestationDigest = upgradeFromTransient(transientHash([requestId, blockHeight, outputKind, serializedOutputLength, serializedOutput]))
|
|
370
|
+
// blockHeight is the height of the finalised destination block holding the
|
|
371
|
+
// transaction the attestation describes, in the destination chain's own
|
|
372
|
+
// numbering (a slot on Solana).
|
|
307
373
|
// Off-chain code uses the TypeScript twin:
|
|
308
|
-
// import { calculateSignetAttestationDigest } from "@sig-net/midnight";
|
|
309
|
-
export pure circuit
|
|
374
|
+
// import { calculateSignetAttestationDigest } from "@sig-net/midnight/testing";
|
|
375
|
+
export pure circuit calculateSignetAttestationDigestV1<#serializedOutputLength>(
|
|
310
376
|
requestId: RequestId,
|
|
311
377
|
blockHeight: Uint<64>,
|
|
378
|
+
outputKind: OutputKind,
|
|
312
379
|
serializedOutput: Bytes<serializedOutputLength>,
|
|
313
380
|
): Bytes<32> {
|
|
314
|
-
return upgradeFromTransient(transientHash<[RequestId, Uint<64>, Uint<64>, Bytes<serializedOutputLength>]>([requestId, blockHeight, serializedOutputLength, serializedOutput]));
|
|
381
|
+
return upgradeFromTransient(transientHash<[RequestId, Uint<64>, OutputKind, Uint<64>, Bytes<serializedOutputLength>]>([requestId, blockHeight, outputKind, serializedOutputLength, serializedOutput]));
|
|
315
382
|
}
|
|
316
383
|
|
|
317
384
|
// Verifies a RespondBidirectionalEvent against its execution output and MPC
|
|
318
|
-
// response key: recomputes the attestation digest
|
|
319
|
-
//
|
|
320
|
-
//
|
|
385
|
+
// response key: recomputes the attestation digest over the event's block
|
|
386
|
+
// height and output kind and checks the ECDSA signature over it. Client
|
|
387
|
+
// contracts run this before consuming outputs, as the singleton emits
|
|
388
|
+
// responses unverified. The caller supplies
|
|
321
389
|
// serializedOutput at its exact unpadded width, and the event record with
|
|
322
390
|
// signature.bigR.x and signature.s byte-reversed into LITTLE-endian: the
|
|
323
391
|
// scalar casts below read little-endian bytes, and the wire/ledger records
|
|
324
392
|
// are big-endian, so the reversal happens off-chain where it costs nothing
|
|
325
393
|
// (the TS SDK's respondBidirectionalEventToCircuitInput does it). A wrong
|
|
326
|
-
// byte order fails verification, never a false accept.
|
|
327
|
-
//
|
|
394
|
+
// byte order fails verification, never a false accept. Of the event, requestId,
|
|
395
|
+
// blockHeight, outputKind, signature.bigR.x and signature.s enter verification:
|
|
396
|
+
// serializedOutputLength and digest serve off-chain readers. The digest binds
|
|
397
|
+
// the event's requestId, so a client MUST consume that request and no other. An s
|
|
398
|
+
// that reduces to 0 mod the curve order aborts the
|
|
328
399
|
// circuit rather than returning false, so sift candidate posts off chain
|
|
329
400
|
// first (verifyRespondBidirectionalSignature).
|
|
330
|
-
export pure circuit
|
|
331
|
-
requestId: RequestId,
|
|
332
|
-
blockHeight: Uint<64>,
|
|
401
|
+
export pure circuit verifyRespondBidirectionalEventV1<#serializedOutputLength>(
|
|
333
402
|
serializedOutput: Bytes<serializedOutputLength>,
|
|
334
|
-
respondBidirectionalEvent:
|
|
403
|
+
respondBidirectionalEvent: RespondBidirectionalEventV1,
|
|
335
404
|
mpcResponseKey: Secp256k1Point
|
|
336
405
|
): Boolean {
|
|
337
|
-
const digest =
|
|
338
|
-
requestId,
|
|
339
|
-
blockHeight,
|
|
406
|
+
const digest = calculateSignetAttestationDigestV1<serializedOutputLength>(
|
|
407
|
+
respondBidirectionalEvent.requestId,
|
|
408
|
+
respondBidirectionalEvent.blockHeight,
|
|
409
|
+
respondBidirectionalEvent.outputKind,
|
|
340
410
|
serializedOutput,
|
|
341
411
|
);
|
|
342
412
|
|
|
@@ -370,10 +440,11 @@ module Signet {
|
|
|
370
440
|
//
|
|
371
441
|
// Every variable-length part is a compile-time CAPACITY (a generic size
|
|
372
442
|
// parameter the requesting contract fixes) plus a runtime count of how many
|
|
373
|
-
// leading slots are real. Unused capacity
|
|
374
|
-
//
|
|
375
|
-
// the
|
|
376
|
-
//
|
|
443
|
+
// leading slots are real. Unused capacity sits in the ledger record but
|
|
444
|
+
// reaches neither the request id (calculateEvmType2TxParamsDigestV1 walks
|
|
445
|
+
// the used slots only) nor the assembled transaction. Field order is the
|
|
446
|
+
// canonical EIP-1559 RLP order and the digest order: part of the wire
|
|
447
|
+
// contract, each count directly before the slot it bounds.
|
|
377
448
|
//
|
|
378
449
|
// KEY: texual order of the fields in this structure must remain fixed as is as their order
|
|
379
450
|
// is relied upon for consistent hashing and decoding from ledger state.
|
|
@@ -395,7 +466,7 @@ module Signet {
|
|
|
395
466
|
// raw 32-byte values, copied verbatim into the RLP encoding.
|
|
396
467
|
//
|
|
397
468
|
// KEY: texual order of the fields in this structure must remain fixed as is as their order
|
|
398
|
-
// is relied upon for consistent hashing and decoding from ledger state.
|
|
469
|
+
// is relied upon for consistent hashing and decoding from ledger state.
|
|
399
470
|
export struct EvmAccessListEntry<#maxStorageKeys> {
|
|
400
471
|
address: Bytes<20>;
|
|
401
472
|
storageKeyCount: Uint<8>; // how many leading storageKeys are real
|
|
@@ -410,13 +481,120 @@ module Signet {
|
|
|
410
481
|
// canonical ABI words for common types.
|
|
411
482
|
//
|
|
412
483
|
// KEY: texual order of the fields in this structure must remain fixed as is as their order
|
|
413
|
-
// is relied upon for consistent hashing and decoding from ledger state.
|
|
484
|
+
// is relied upon for consistent hashing and decoding from ledger state.
|
|
414
485
|
export struct EvmCalldata<#maxWords> {
|
|
415
486
|
selector: Bytes<4>; // the literal first 4 calldata bytes
|
|
416
487
|
noWords: Uint<16>; // No. of used words in the words list
|
|
417
488
|
words: Vector<maxWords, Bytes<32>>; // canonical ABI words (big-endian)
|
|
418
489
|
}
|
|
419
490
|
|
|
491
|
+
// Digest of an EvmType2TxParams over the bytes that reach the signed transaction:
|
|
492
|
+
// the scalar fields, then the calldata words, access-list entries and storage keys
|
|
493
|
+
// up to their declared counts, each count hashed beside its entries so the encoding
|
|
494
|
+
// commits to its length. Slots past a count are skipped, and an absent calldata
|
|
495
|
+
// contributes only its absence, so one transaction has one digest whatever
|
|
496
|
+
// capacities the requester compiled its struct with and whatever bytes sit in
|
|
497
|
+
// unused slots. The counts must fit their capacities. Off-chain code uses the
|
|
498
|
+
// TypeScript twin calculateEvmType2TxParamsDigest in @sig-net/midnight.
|
|
499
|
+
//
|
|
500
|
+
// The slot walks are folds carrying the slot index and a running hash: a `for`
|
|
501
|
+
// over `0..n` has no index type at n = 0, and a zero capacity is the common case.
|
|
502
|
+
export pure circuit calculateEvmType2TxParamsDigestV1<#maxCalldataWords, #maxAccessListEntries, #maxStorageKeysPerEntry>(
|
|
503
|
+
txParams: EvmType2TxParams<maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry>
|
|
504
|
+
): Bytes<32> {
|
|
505
|
+
// An absent calldata contributes is_some = false, a zero selector and a zero word count.
|
|
506
|
+
const calldata = txParams.calldata;
|
|
507
|
+
const noWords = calldata.is_some ? calldata.value.noWords : 0 as Uint<16>;
|
|
508
|
+
const selector = calldata.is_some ? calldata.value.selector : default<Bytes<4>>;
|
|
509
|
+
|
|
510
|
+
assert(noWords <= maxCalldataWords, "calldata noWords exceeds capacity");
|
|
511
|
+
assert(txParams.accessListEntryCount <= maxAccessListEntries, "accessListEntryCount exceeds capacity");
|
|
512
|
+
|
|
513
|
+
// For every used access-list entry, confirm its storageKeyCount fits
|
|
514
|
+
// maxStorageKeysPerEntry. A Compact loop needs a compile-time bound, so the walk
|
|
515
|
+
// is a fold over every slot carrying [slot index, all fit so far], and the index
|
|
516
|
+
// picks out the used entries.
|
|
517
|
+
const keyCountsFit = fold(
|
|
518
|
+
(acc: [Uint<8>, Boolean], entry: EvmAccessListEntry<maxStorageKeysPerEntry>): [Uint<8>, Boolean] =>
|
|
519
|
+
[(acc[0] + 1) as Uint<8>, acc[1] && (acc[0] >= txParams.accessListEntryCount || entry.storageKeyCount <= maxStorageKeysPerEntry)],
|
|
520
|
+
[0 as Uint<8>, true],
|
|
521
|
+
txParams.accessList
|
|
522
|
+
);
|
|
523
|
+
assert(keyCountsFit[1], "a used entry's storageKeyCount exceeds capacity");
|
|
524
|
+
|
|
525
|
+
// The scalar fields and the counts, hashed as one field-aligned tuple.
|
|
526
|
+
const head = transientHash<[Uint<64>, Uint<64>, Uint<128>, Uint<128>, Uint<64>, Bytes<20>, Uint<128>, Boolean, Bytes<4>, Uint<16>, Uint<8>]>([
|
|
527
|
+
txParams.chainId,
|
|
528
|
+
txParams.nonce,
|
|
529
|
+
txParams.maxPriorityFeePerGas,
|
|
530
|
+
txParams.maxFeePerGas,
|
|
531
|
+
txParams.gasLimit,
|
|
532
|
+
txParams.to,
|
|
533
|
+
txParams.value,
|
|
534
|
+
calldata.is_some,
|
|
535
|
+
selector,
|
|
536
|
+
noWords,
|
|
537
|
+
txParams.accessListEntryCount
|
|
538
|
+
]);
|
|
539
|
+
|
|
540
|
+
// The calldata words below noWords, chained onto the head one word at a time.
|
|
541
|
+
// calldata.value is read whether or not the calldata is present: with noWords
|
|
542
|
+
// at zero every step passes the head through.
|
|
543
|
+
const wordsScan = fold(
|
|
544
|
+
(acc: [Uint<16>, Field], word: Bytes<32>): [Uint<16>, Field] =>
|
|
545
|
+
[(acc[0] + 1) as Uint<16>, acc[0] < noWords ? transientHash<[Field, Bytes<32>]>([acc[1], word]) : acc[1]],
|
|
546
|
+
[0 as Uint<16>, head],
|
|
547
|
+
calldata.value.words
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
// The access-list entries below accessListEntryCount, each chained on as its
|
|
551
|
+
// address, its key count and a digest of its storage keys below that count
|
|
552
|
+
// (the inner fold, started from a zero Field).
|
|
553
|
+
const listScan = fold(
|
|
554
|
+
(acc: [Uint<8>, Field], entry: EvmAccessListEntry<maxStorageKeysPerEntry>): [Uint<8>, Field] =>
|
|
555
|
+
[
|
|
556
|
+
(acc[0] + 1) as Uint<8>,
|
|
557
|
+
acc[0] < txParams.accessListEntryCount
|
|
558
|
+
? transientHash<[Field, Bytes<20>, Uint<8>, Field]>([
|
|
559
|
+
acc[1],
|
|
560
|
+
entry.address,
|
|
561
|
+
entry.storageKeyCount,
|
|
562
|
+
fold(
|
|
563
|
+
(keyAcc: [Uint<8>, Field], key: Bytes<32>): [Uint<8>, Field] =>
|
|
564
|
+
[(keyAcc[0] + 1) as Uint<8>, keyAcc[0] < entry.storageKeyCount ? transientHash<[Field, Bytes<32>]>([keyAcc[1], key]) : keyAcc[1]],
|
|
565
|
+
[0 as Uint<8>, 0 as Field],
|
|
566
|
+
entry.storageKeys
|
|
567
|
+
)[1]
|
|
568
|
+
])
|
|
569
|
+
: acc[1]
|
|
570
|
+
],
|
|
571
|
+
[0 as Uint<8>, wordsScan[1]],
|
|
572
|
+
txParams.accessList
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
// The running hash is a Field. upgradeFromTransient writes it out as Bytes<32>.
|
|
576
|
+
return upgradeFromTransient(listScan[1]);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// The request id of an EVM type-2 request: its preimage with the transaction digested
|
|
580
|
+
// by calculateEvmType2TxParamsDigestV1. Off-chain code uses the TypeScript twin:
|
|
581
|
+
// import { calculateRequestId } from "@sig-net/midnight";
|
|
582
|
+
export pure circuit calculateEvmType2RequestIdV1<#maxCalldataWords, #maxAccessListEntries, #maxStorageKeysPerEntry, #LenOutputDeserialization, #LenRespondSerialization>(
|
|
583
|
+
request: SignBidirectionalEventV1<EvmType2TxParams<maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry>, LenOutputDeserialization, LenRespondSerialization>
|
|
584
|
+
): RequestId {
|
|
585
|
+
assert(request.txParamType == TxParamType.evmType2, "txParamType must tag txParams as evmType2");
|
|
586
|
+
const preimage = RequestIdPreimageV1 {
|
|
587
|
+
keyVersion: request.keyVersion,
|
|
588
|
+
sender: request.sender,
|
|
589
|
+
path: request.path,
|
|
590
|
+
algo: request.algo,
|
|
591
|
+
txParamType: request.txParamType,
|
|
592
|
+
txParamsDigest: calculateEvmType2TxParamsDigestV1<maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry>(request.txParams),
|
|
593
|
+
executionDest: request.executionDest,
|
|
594
|
+
};
|
|
595
|
+
return calculateRequestIdV1(preimage);
|
|
596
|
+
}
|
|
597
|
+
|
|
420
598
|
// ---- ABI Calldata Word Construction Utilities ------------------------------------------------------
|
|
421
599
|
// Canonical ABI word builders and readers. Words MUST be stored in canonical
|
|
422
600
|
// ABI form (big-endian, per the ABI spec). These utilities help construct
|