@sig-net/midnight 0.0.9 → 0.11.0
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 +254 -112
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/ecdsa-attestation.d.ts +53 -1
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +96 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +8 -8
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +15 -17
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +3 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -13
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +76 -24
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +18 -10
- package/dist/managed/contract/index.js +218 -103
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +2 -2
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +32 -15
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.js +5 -5
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-state-reader.d.ts +49 -30
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +55 -35
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-evtype2tx-requests.d.ts +65 -43
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +77 -78
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +3 -3
- package/dist/signet-request-response-reader.js +9 -9
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +4 -4
- package/dist/signet-requests.js +3 -3
- package/dist/signet-requests.js.map +1 -1
- package/package.json +1 -1
- package/src/Signet.compact +122 -72
- package/src/circuits.compact +10 -27
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
12
12
|
import { readSignetContractLedgerFromState, signetMapEntryKey, } from "./signet-contract-state-reader.js";
|
|
13
13
|
import { recoverSignatureResponseSigner } from "./signature-response-verification.js";
|
|
14
|
-
import {
|
|
14
|
+
import { signBidirectionalEventToSignedEvmTransaction, signBidirectionalEventToUnsignedEvmTransaction, } from "./signet-evtype2tx-requests.js";
|
|
15
15
|
/**
|
|
16
16
|
* Reader over one requester contract / signet contract pair.
|
|
17
17
|
* Construct once per pair and reuse: fetched request records are cached (they
|
|
@@ -79,11 +79,11 @@ export class SignetRequestResponseReader {
|
|
|
79
79
|
*/
|
|
80
80
|
async getSignatureResponses(requestId) {
|
|
81
81
|
const raw = await this.queryRawState(this.config.signetContractAddress, "signet contract");
|
|
82
|
-
const {
|
|
83
|
-
const totalPosts =
|
|
82
|
+
const { respondCounterMap, respondMap } = readSignetContractLedgerFromState(raw);
|
|
83
|
+
const totalPosts = respondCounterMap.get(requestId) ?? 0n;
|
|
84
84
|
const responses = [];
|
|
85
85
|
for (let count = 0n; count < totalPosts; count++) {
|
|
86
|
-
const response =
|
|
86
|
+
const response = respondMap.get(signetMapEntryKey(requestId, count));
|
|
87
87
|
if (response === undefined) {
|
|
88
88
|
throw new Error(`response log has no entry ${count} for request ${requestId} ` +
|
|
89
89
|
`despite its counter reading ${totalPosts} — ledger state is inconsistent`);
|
|
@@ -94,7 +94,7 @@ export class SignetRequestResponseReader {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Fetch and verify the responses posted for `requestId`: each post's
|
|
97
|
-
*
|
|
97
|
+
* signature must recover to `expectedSigner`
|
|
98
98
|
* (compared case-insensitively) over the signing hash of the transaction
|
|
99
99
|
* the request record describes. The first valid post wins; every post gets
|
|
100
100
|
* a verdict so callers can report the noise.
|
|
@@ -149,8 +149,8 @@ export class SignetRequestResponseReader {
|
|
|
149
149
|
* @throws Error when the requester contract has no state or holds no
|
|
150
150
|
* request under `requestId`.
|
|
151
151
|
*/
|
|
152
|
-
async
|
|
153
|
-
return
|
|
152
|
+
async getUnsignedEvmTransaction(requestId) {
|
|
153
|
+
return signBidirectionalEventToUnsignedEvmTransaction(await this.getSignatureRequest(requestId));
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Assemble the broadcast-ready signed EIP-1559 transaction for `requestId`:
|
|
@@ -168,7 +168,7 @@ export class SignetRequestResponseReader {
|
|
|
168
168
|
* @throws Error when either contract has no state, the request is not on the
|
|
169
169
|
* requester's ledger, or the responses ledger is inconsistent.
|
|
170
170
|
*/
|
|
171
|
-
async
|
|
171
|
+
async getSignedEvmTransaction(requestId, expectedSigner) {
|
|
172
172
|
const { verified } = await this.getVerifiedSignatureRespondedEvent(requestId, expectedSigner);
|
|
173
173
|
if (verified === undefined) {
|
|
174
174
|
return undefined;
|
|
@@ -176,7 +176,7 @@ export class SignetRequestResponseReader {
|
|
|
176
176
|
// getSignatureRequest is cached — getVerifiedSignatureRespondedEvent already
|
|
177
177
|
// fetched it, so this is a free lookup, not a second query.
|
|
178
178
|
const request = await this.getSignatureRequest(requestId);
|
|
179
|
-
return
|
|
179
|
+
return signBidirectionalEventToSignedEvmTransaction(request, verified);
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Fetch every respond-bidirectional response posted for `requestId`, in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,uBAAuB;AACvB,yEAAyE;AACzE,4EAA4E;AAC5E,uEAAuE;AACvE,mEAAmE;AACnE,2EAA2E;AAC3E,6BAA6B;AAK7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F,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,6CAA6C;gBAC/D,2BAA2B,IAAI,CAAC,MAAM,CAAC,2BAA2B,uBAAuB,CAC5F,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,qBAAqB,CACzB,SAAuB;QAEvB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,CAClC,IAAI,CAAC,MAAM,CAAC,qBAAqB,EACjC,iBAAiB,CAClB,CAAC;QACF,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,uBAAuB;AACvB,yEAAyE;AACzE,4EAA4E;AAC5E,uEAAuE;AACvE,mEAAmE;AACnE,2EAA2E;AAC3E,6BAA6B;AAK7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EACL,iCAAiC,EACjC,iBAAiB,GAGlB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EACL,4CAA4C,EAC5C,8CAA8C,GAC/C,MAAM,gCAAgC,CAAC;AAoExC;;;;;GAKG;AACH,MAAM,OAAO,2BAA2B;IACrB,MAAM,CAAoC;IAE3D,qEAAqE;IACpD,YAAY,GAAG,IAAI,GAAG,EAGpC,CAAC;IAEJ;;OAEG;IACH,YAAY,MAAyC;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,aAAa,CACzB,eAAuB,EACvB,IAAY;QA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AAM,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,GAC/D,iCAAiC,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,8BAA8B,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACvE,MAAM,SAAS,GAAgC,EAAE,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,EAAE,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,GAAG,CAC1C,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,CACpC,CAAC;YACF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,0CAA0C,KAAK,gBAAgB,SAAS,GAAG;oBACzE,+BAA+B,UAAU,iCAAiC,CAC7E,CAAC;YACJ,CAAC;YACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
import type {
|
|
2
|
+
import type { EvmType2TxParams } from "./signet-evtype2tx-requests.ts";
|
|
3
3
|
/**
|
|
4
4
|
* 32-byte signet request id (Compact: `new type RequestId = Bytes<32>`).
|
|
5
5
|
* Chain-agnostic: downstream consumers treat it as an opaque key. Ids are
|
|
@@ -23,7 +23,7 @@ export interface ContractAddress {
|
|
|
23
23
|
* `enum`) so the values stay structurally `number`.
|
|
24
24
|
*/
|
|
25
25
|
export declare const TxParamType: {
|
|
26
|
-
/** `
|
|
26
|
+
/** `EvmType2TxParams` (signet-evtype2tx-requests.ts): an EIP-1559 EVM transaction. */
|
|
27
27
|
readonly evmType2: 0;
|
|
28
28
|
/**
|
|
29
29
|
* Never emitted — mirrors the Compact-side padding variant that keeps the
|
|
@@ -68,12 +68,12 @@ export interface Maybe<T> {
|
|
|
68
68
|
* contract's `SignBidirectionalEventMap` (at whichever ledger field the
|
|
69
69
|
* contract declares it — its notifications name the position). Generic over
|
|
70
70
|
* the tx-params decomposition, exactly like the Compact struct; the default
|
|
71
|
-
* instantiation is {@link
|
|
71
|
+
* instantiation is {@link EvmType2TxParams} — the only decomposition so far;
|
|
72
72
|
* new tx kinds supply their own type argument alongside their Compact struct.
|
|
73
73
|
* The schema fields carry their contract-declared byte widths in their array
|
|
74
74
|
* lengths.
|
|
75
75
|
*/
|
|
76
|
-
export interface SignBidirectionalEvent<TxParams =
|
|
76
|
+
export interface SignBidirectionalEvent<TxParams = EvmType2TxParams> {
|
|
77
77
|
/** Address of the client contract that stores this event (`kernel.self()`). */
|
|
78
78
|
sender: ContractAddress;
|
|
79
79
|
/** Contract-local nonce captured when the request was created. */
|
package/dist/signet-requests.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// so ledger reads assign to them without casts.
|
|
11
11
|
//
|
|
12
12
|
// The lockstep is enforced by each consuming contract's simulator tests: the
|
|
13
|
-
// "
|
|
13
|
+
// "test-caller-contract ledger shape" test in packages/test-caller-contract/tests/
|
|
14
14
|
// contract.test.ts assigns the generated `ledger().signBidirectionalEventMap`
|
|
15
15
|
// to the named SignBidirectionalEventLedgerMap type — the assignment itself is
|
|
16
16
|
// the assertion, so any structural drift between the generated managed types
|
|
@@ -26,7 +26,7 @@ import { CompactTypeBoolean, CompactTypeBytes, CompactTypeEnum, CompactTypeUnsig
|
|
|
26
26
|
* `enum`) so the values stay structurally `number`.
|
|
27
27
|
*/
|
|
28
28
|
export const TxParamType = {
|
|
29
|
-
/** `
|
|
29
|
+
/** `EvmType2TxParams` (signet-evtype2tx-requests.ts): an EIP-1559 EVM transaction. */
|
|
30
30
|
evmType2: 0,
|
|
31
31
|
/**
|
|
32
32
|
* Never emitted — mirrors the Compact-side padding variant that keeps the
|
|
@@ -72,7 +72,7 @@ export const MPCDestination = {
|
|
|
72
72
|
// `_calculateRequestId_0` in any consuming contract's
|
|
73
73
|
// managed/contract/index.js). What must stay in lockstep with Signet.compact
|
|
74
74
|
// is exactly what this file already keeps in lockstep — the struct shapes,
|
|
75
|
-
// field by field, in declaration order. Enforced by caller-contract's
|
|
75
|
+
// field by field, in declaration order. Enforced by test-caller-contract's
|
|
76
76
|
// "submitSignatureRequest round-trip" test, which asserts the id computed
|
|
77
77
|
// here equals the ledger map key minted by the REAL compiled contract.
|
|
78
78
|
// Runtime descriptors of the Compact base types the generic record fields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-requests.js","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,sEAAsE;AACtE,EAAE;AACF,iEAAiE;AACjE,2EAA2E;AAC3E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"signet-requests.js","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,sEAAsE;AACtE,EAAE;AACF,iEAAiE;AACjE,2EAA2E;AAC3E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,mEAAmE;AACnE,EAAE;AACF,wEAAwE;AACxE,yDAAyD;AAEzD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAsBzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,sFAAsF;IACtF,QAAQ,EAAE,CAAC;IACX;;;;OAIG;IACH,QAAQ,EAAE,CAAC;CACH,CAAC;AAEX;;;GAGG;AACH,MA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AAE7B;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CAC3C,WAA0D;IAE1D,MAAM,KAAK,GAAgC,IAAI,GAAG,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC;QAC/C,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/Signet.compact
CHANGED
|
@@ -97,7 +97,9 @@ module Signet {
|
|
|
97
97
|
// outputDeserializationSchema tells the MPC how to deserialise the destination chain's
|
|
98
98
|
// execution output (destination chain -> MPC). respondSerializationSchema tells the MPC
|
|
99
99
|
// how to serialise that output into the RespondBidirectionalEvent it posts back
|
|
100
|
-
// (MPC -> Midnight).
|
|
100
|
+
// (MPC -> Midnight).
|
|
101
|
+
// Both are ABI-style JSON schema strings, sized per client contract
|
|
102
|
+
// (see: https://docs.soliditylang.org/en/v0.8.30/abi-spec.html#json)
|
|
101
103
|
outputDeserializationSchema: Bytes<LenOutputDeserialization>;
|
|
102
104
|
respondSerializationSchema: Bytes<LenRespondSerialization>;
|
|
103
105
|
}
|
|
@@ -119,7 +121,7 @@ module Signet {
|
|
|
119
121
|
// TxParamType indicates which transaction-param decomposition a request
|
|
120
122
|
// contains so an off-chain consumer (e.g. the MPC) knows how to re-assemble it.
|
|
121
123
|
export enum TxParamType {
|
|
122
|
-
evmType2, //
|
|
124
|
+
evmType2, // EvmType2TxParams: an EIP-1559 EVM transaction (envelope + calldata)
|
|
123
125
|
reserved, // Reserved for future use. Exists to keep enum >= 2 (proof server bug).
|
|
124
126
|
}
|
|
125
127
|
|
|
@@ -164,14 +166,16 @@ module Signet {
|
|
|
164
166
|
// (see calculateRequestId).
|
|
165
167
|
export new type RequestId = Bytes<32>;
|
|
166
168
|
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
169
|
+
// keccak256 of the whole record, so the id commits to every field including sender
|
|
170
|
+
// (which scopes ids per contract). No domain-separation tag, deliberately.
|
|
171
|
+
//
|
|
172
|
+
// Hashes the field-aligned binary representation (each field re-padded to its declared
|
|
173
|
+
// width), NOT an ABI/EIP-712 field encoding, so off-chain consumers must reproduce that
|
|
174
|
+
// layout exactly. Type argument is the INPUT type; the return is always Bytes<32>.
|
|
171
175
|
export pure circuit calculateRequestId<TxParams, #LenOutputDeserialization, #LenRespondSerialization>(
|
|
172
176
|
request: SignBidirectionalEvent<TxParams, LenOutputDeserialization, LenRespondSerialization>
|
|
173
177
|
): RequestId {
|
|
174
|
-
return
|
|
178
|
+
return keccak256<SignBidirectionalEvent<TxParams, LenOutputDeserialization, LenRespondSerialization>>(request) as RequestId;
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
// ---- Client Contract: SignBidirectionalEvent Map ---------------------------------------------------
|
|
@@ -188,7 +192,7 @@ module Signet {
|
|
|
188
192
|
// Signet singleton to notify the MPC of a SignBidirectionalEvent.
|
|
189
193
|
export contract SignetSigner {
|
|
190
194
|
// Called by client contracts to notify the MPC of a SignBidirectionalEvent.
|
|
191
|
-
circuit
|
|
195
|
+
circuit signBidirectional(
|
|
192
196
|
// Canonical id of the SignBidirectionalEvent (calculate with calculateRequestId).
|
|
193
197
|
requestId: RequestId,
|
|
194
198
|
// Versioned notification of the SignBidirectionalEvent
|
|
@@ -219,13 +223,35 @@ module Signet {
|
|
|
219
223
|
};
|
|
220
224
|
}
|
|
221
225
|
|
|
226
|
+
// A curve point in affine coordinates, SEC1 big-endian. Field-for-field the
|
|
227
|
+
// AffinePoint of the sig-net EVM and Solana signer contracts.
|
|
228
|
+
export struct AffinePoint {
|
|
229
|
+
x: Bytes<32>;
|
|
230
|
+
y: Bytes<32>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// The MPC's canonical ECDSA signature: bigR the full nonce point (so consumers
|
|
234
|
+
// never decompress), s big-endian, recoveryId the parity of R.y (0 or 1).
|
|
235
|
+
// Deliberately identical to the Signature struct every other sig-net signer
|
|
236
|
+
// contract exposes (EVM ChainSignatures.sol, the Solana signet program) and to
|
|
237
|
+
// the MPC's own Signature { big_r, s, recovery_id } — one vocabulary across
|
|
238
|
+
// chains. No algorithm tag is stored: the scheme is fixed by the request's own
|
|
239
|
+
// MPCSignatureAlgorithm.
|
|
240
|
+
//
|
|
241
|
+
// Stored bytes are BIG-endian throughout, the canonical SEC1 order. The scalar
|
|
242
|
+
// casts read little-endian, so verifyRespondBidirectionalEvent reverses on the
|
|
243
|
+
// way in rather than making the stored record non-canonical.
|
|
244
|
+
export struct Signature {
|
|
245
|
+
bigR: AffinePoint;
|
|
246
|
+
s: Bytes<32>;
|
|
247
|
+
recoveryId: Uint<8>;
|
|
248
|
+
}
|
|
249
|
+
|
|
222
250
|
// Counterpart to SignBidirectionalEvent containing MPC generated signature requested by a SignBidirectionalEvent.
|
|
223
251
|
// Posted by MPC back to Signet singleton for clients to extract to build a signed transaction.
|
|
224
252
|
export struct SignatureRespondedEvent {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
s: Bytes<32>; // signature s
|
|
228
|
-
recoveryId: Uint<8>; // parity of R.y for public-key recovery
|
|
253
|
+
// The requested signature over the transaction the request describes.
|
|
254
|
+
signature: Signature;
|
|
229
255
|
}
|
|
230
256
|
|
|
231
257
|
// Structure containing the output of a transaction executed on a foreign blockchain,
|
|
@@ -238,7 +264,7 @@ module Signet {
|
|
|
238
264
|
// Posted by MPC back to Signet singleton for clients to extract, verify and deliver
|
|
239
265
|
// back to the client contract. The singleton stores posts UNVERIFIED: client contracts
|
|
240
266
|
// must verify the signature themselves against their MPC response key, via
|
|
241
|
-
// verifyRespondBidirectionalEvent
|
|
267
|
+
// verifyRespondBidirectionalEvent.
|
|
242
268
|
export struct RespondBidirectionalEvent {
|
|
243
269
|
// ABI-encoded return data of the remote call (canonical
|
|
244
270
|
// serialized_output), zero-padded. First 32-byte word == 1 signals
|
|
@@ -249,16 +275,9 @@ module Signet {
|
|
|
249
275
|
// Meaningful byte count of serializedOutput.
|
|
250
276
|
outputLen: Uint<8>;
|
|
251
277
|
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
|
|
255
|
-
// r is the MPC signature's big_r.x reduced mod the curve order.
|
|
256
|
-
r: Bytes<32>;
|
|
257
|
-
s: Bytes<32>;
|
|
258
|
-
|
|
259
|
-
// Recovery id (parity of R.y), for off-chain public key recovery only.
|
|
260
|
-
// Unused in-circuit: verification takes the public key as an explicit input.
|
|
261
|
-
recoveryId: Uint<8>;
|
|
278
|
+
// Signs signetAttestationDigest(requestId, serializedOutput) — outputLen above is
|
|
279
|
+
// NOT covered. The verify circuit's r is this signature's bigR.x mod the curve order.
|
|
280
|
+
signature: Signature;
|
|
262
281
|
}
|
|
263
282
|
|
|
264
283
|
// SignetMapKey used to locate SignBidirectionalEventNotifications, SignatureRespondedEvent and
|
|
@@ -268,45 +287,59 @@ module Signet {
|
|
|
268
287
|
requestId: RequestId;
|
|
269
288
|
};
|
|
270
289
|
|
|
271
|
-
// The 32-byte digest the MPC ECDSA-signs to attest a remote execution:
|
|
272
|
-
//
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
//
|
|
290
|
+
// The 32-byte digest the MPC ECDSA-signs to attest a remote execution: keccak256 over
|
|
291
|
+
// requestId (32) ++ serializedOutput (128). The output is hashed as the full zero-padded
|
|
292
|
+
// Bytes<128>, not at its meaningful length, because Compact cannot hash a runtime-length
|
|
293
|
+
// prefix — an off-chain signer must pad to exactly 128 before hashing.
|
|
294
|
+
//
|
|
295
|
+
// outputLen is NOT covered. A consumer that treats it as attested must pin it itself.
|
|
296
|
+
//
|
|
297
|
+
// secp256k1EcdsaVerify reads the digest as a BIG-ENDIAN integer mod the curve order
|
|
298
|
+
// (RFC 6979). ONE implementation for everyone: off-chain signers call the compiled copy
|
|
299
|
+
// via circuits.compact, never a TS re-implementation.
|
|
278
300
|
export pure circuit signetAttestationDigest(
|
|
279
301
|
requestId: RequestId,
|
|
280
|
-
serializedOutput: Bytes<128
|
|
281
|
-
outputLen: Uint<8>
|
|
302
|
+
serializedOutput: Bytes<128>
|
|
282
303
|
): Bytes<32> {
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
304
|
+
const requestIdBytes = requestId as Bytes<32>;
|
|
305
|
+
return keccak256<Bytes<160>>(Bytes[...requestIdBytes, ...serializedOutput]);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Same Bytes -> Vector<Uint<8>> idiom numericAbiWord uses. Pulls in a byte-decomposition
|
|
309
|
+
// lookup table, a fixed cost the calling circuit pays once and shares with any other
|
|
310
|
+
// byte-level work it does, so reverse at the boundary and never per element.
|
|
311
|
+
pure circuit reverseBytes32(b: Bytes<32>): Bytes<32> {
|
|
312
|
+
const v = b as Vector<32, Uint<8>>;
|
|
313
|
+
return Bytes[v[31], v[30], v[29], v[28], v[27], v[26], v[25], v[24],
|
|
314
|
+
v[23], v[22], v[21], v[20], v[19], v[18], v[17], v[16],
|
|
315
|
+
v[15], v[14], v[13], v[12], v[11], v[10], v[9], v[8],
|
|
316
|
+
v[7], v[6], v[5], v[4], v[3], v[2], v[1], v[0]];
|
|
288
317
|
}
|
|
289
318
|
|
|
290
|
-
// Verify a
|
|
319
|
+
// Verify a respond-bidirectional attestation against a secp256k1 public key: the
|
|
291
320
|
// ECDSA signature must sign the attestation digest of (requestId, output). This is
|
|
292
321
|
// the check client contracts run before accepting a response (the Signet singleton
|
|
293
322
|
// stores posts unverified); pass the contract's MPC RESPONSE key (derived off-chain
|
|
294
323
|
// from the contract's address + the fixed path "midnight response key", typically
|
|
295
324
|
// hash-pinned in the contract's ledger at deploy time).
|
|
325
|
+
//
|
|
326
|
+
// Takes the event as stored: the caller hands over the record it read, and the
|
|
327
|
+
// big-endian-to-little-endian re-encoding happens here instead of in every
|
|
328
|
+
// integrator.
|
|
329
|
+
//
|
|
330
|
+
// ECDSA's r is bigR.x reduced mod the curve order; bigR.x is taken as-is because it
|
|
331
|
+
// is already below the order for all but a ~2^-128 fraction of signatures, and one
|
|
332
|
+
// that is not simply fails to verify.
|
|
296
333
|
export pure circuit verifyRespondBidirectionalEvent(
|
|
297
334
|
requestId: RequestId,
|
|
298
335
|
respondBidirectionalEvent: RespondBidirectionalEvent,
|
|
299
336
|
mpcResponseKey: Secp256k1Point
|
|
300
337
|
): Boolean {
|
|
301
338
|
return secp256k1EcdsaVerify(
|
|
302
|
-
signetAttestationDigest(
|
|
303
|
-
requestId,
|
|
304
|
-
respondBidirectionalEvent.serializedOutput,
|
|
305
|
-
respondBidirectionalEvent.outputLen
|
|
306
|
-
),
|
|
339
|
+
signetAttestationDigest(requestId, respondBidirectionalEvent.serializedOutput),
|
|
307
340
|
Secp256k1EcdsaSignature {
|
|
308
|
-
r: respondBidirectionalEvent.
|
|
309
|
-
s: respondBidirectionalEvent.s as Secp256k1Scalar,
|
|
341
|
+
r: reverseBytes32(respondBidirectionalEvent.signature.bigR.x) as Secp256k1Scalar,
|
|
342
|
+
s: reverseBytes32(respondBidirectionalEvent.signature.s) as Secp256k1Scalar,
|
|
310
343
|
},
|
|
311
344
|
mpcResponseKey
|
|
312
345
|
);
|
|
@@ -335,57 +368,59 @@ module Signet {
|
|
|
335
368
|
// count that says how many leading slots are real. Off-chain consumers use
|
|
336
369
|
// the counts; unused capacity is hashed as part of the record (zero-fill by
|
|
337
370
|
// convention) but never reaches the assembled transaction.
|
|
338
|
-
|
|
339
|
-
|
|
371
|
+
// Canonical EIP-1559 payload order, which is the RLP order the MPC re-assembles into.
|
|
372
|
+
// Each count sits directly before the slot it bounds. This order is also the
|
|
373
|
+
// request-id hash order, so it is part of the wire contract.
|
|
374
|
+
export struct EvmType2TxParams<#maxCalldataWords, #maxAccessListEntries, #maxStorageKeysPerEntry> {
|
|
340
375
|
chainId: Uint<64>; // EVM chain id (also expressed in caip2Id)
|
|
341
376
|
nonce: Uint<64>; // account nonce of the derived sender
|
|
342
|
-
gasLimit: Uint<64>; // gas ceiling for the call
|
|
343
|
-
maxFeePerGas: Uint<128>; // wei
|
|
344
377
|
maxPriorityFeePerGas: Uint<128>; // wei
|
|
378
|
+
maxFeePerGas: Uint<128>; // wei
|
|
379
|
+
gasLimit: Uint<64>; // gas ceiling for the call
|
|
380
|
+
to: Bytes<20>; // call target (e.g. the ERC20 contract)
|
|
345
381
|
value: Uint<128>; // ETH sent with the call, in wei
|
|
382
|
+
calldata: Maybe<EvmCalldata<maxCalldataWords>>; // none = plain ETH transfer ("0x" data)
|
|
346
383
|
accessListEntryCount: Uint<8>; // how many leading accessList entries are real
|
|
347
|
-
accessList: Vector<maxAccessListEntries,
|
|
348
|
-
calldata: Maybe<EVMCalldata<maxCalldataWords>>; // none = plain ETH transfer ("0x" data)
|
|
384
|
+
accessList: Vector<maxAccessListEntries, EvmAccessListEntry<maxStorageKeysPerEntry>>;
|
|
349
385
|
}
|
|
350
386
|
|
|
351
387
|
// One EIP-2930 access-list entry (https://eips.ethereum.org/EIPS/eip-2930):
|
|
352
388
|
// an address plus the storage keys the transaction pre-declares. Keys are
|
|
353
389
|
// raw 32-byte values, copied verbatim into the RLP encoding.
|
|
354
|
-
export struct
|
|
390
|
+
export struct EvmAccessListEntry<#maxStorageKeys> {
|
|
355
391
|
address: Bytes<20>;
|
|
356
392
|
storageKeyCount: Uint<8>; // how many leading storageKeys are real
|
|
357
393
|
storageKeys: Vector<maxStorageKeys, Bytes<32>>;
|
|
358
394
|
}
|
|
359
395
|
|
|
360
396
|
// ABI calldata for the EVM call: 4-byte selector + 32-byte slots
|
|
361
|
-
// (https://docs.soliditylang.org/en/latest/abi-spec.html).
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
|
|
397
|
+
// (https://docs.soliditylang.org/en/latest/abi-spec.html).
|
|
398
|
+
// CRITICAL: every ABI word here must be stored in canonical ABI form, as
|
|
399
|
+
// the MPC signs a transaction composed of exactly these words. See the
|
|
400
|
+
// ABI Calldata Word Construction Utilities below for help constructing
|
|
401
|
+
// canonical ABI words for common types.
|
|
402
|
+
export struct EvmCalldata<#maxWords> {
|
|
403
|
+
selector: Bytes<4>; // the literal first 4 calldata bytes
|
|
366
404
|
noWords: Uint<16>; // No. of used words in the words list
|
|
367
|
-
words: Vector<maxWords, Bytes<32>>; // ABI
|
|
405
|
+
words: Vector<maxWords, Bytes<32>>; // canonical ABI words (big-endian)
|
|
368
406
|
}
|
|
369
407
|
|
|
370
|
-
// ---- ABI
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
// and are kept honest by lockstep tests against these compiled circuits.
|
|
378
|
-
|
|
379
|
-
// The ABI word for an EVM address: 12 zero bytes, then the 20 display-order
|
|
380
|
-
// address bytes, exactly as they appear in the broadcast calldata.
|
|
408
|
+
// ---- ABI Calldata Word Construction Utilities ------------------------------------------------------
|
|
409
|
+
// Canonical ABI word builders and readers. Words MUST be stored in canonical
|
|
410
|
+
// ABI form (big-endian, per the ABI spec). These utilities help construct
|
|
411
|
+
// canonical ABI words for common types.
|
|
412
|
+
|
|
413
|
+
// Construct the canonical ABI word for a 20-byte EVM address.
|
|
414
|
+
// Output format: 12 zero bytes, then the 20 display-order address bytes.
|
|
381
415
|
export pure circuit evmAddressAbiWord(addr: Bytes<20>): Bytes<32> {
|
|
382
416
|
return Bytes[...default<Bytes<12>>, ...addr];
|
|
383
417
|
}
|
|
384
418
|
|
|
385
|
-
//
|
|
386
|
-
// 32-byte big-endian integer.
|
|
387
|
-
// so cast to 16 LE bytes and emit them reversed into the low half.
|
|
419
|
+
// Construct the canonical ABI word for a Uint<128> value (e.g. an ERC20 amount).
|
|
420
|
+
// Output format: the value as a 32-byte big-endian integer.
|
|
388
421
|
export pure circuit numericAbiWord(value: Uint<128>): Bytes<32> {
|
|
422
|
+
// Compact's Uint->Bytes cast is little-endian,
|
|
423
|
+
// so cast to 16 LE bytes and emit them reversed into the low half.
|
|
389
424
|
const le = (value as Bytes<16>) as Vector<16, Uint<8>>;
|
|
390
425
|
return Bytes[
|
|
391
426
|
...default<Bytes<16>>,
|
|
@@ -394,6 +429,12 @@ module Signet {
|
|
|
394
429
|
];
|
|
395
430
|
}
|
|
396
431
|
|
|
432
|
+
// Construct the canonical ABI word for a Boolean.
|
|
433
|
+
// Output format: 31 zero bytes, then 0x01 (true) or 0x00 (false).
|
|
434
|
+
export pure circuit boolAbiWord(value: Boolean): Bytes<32> {
|
|
435
|
+
return Bytes[...default<Bytes<31>>, value as Uint<8>];
|
|
436
|
+
}
|
|
437
|
+
|
|
397
438
|
// Read a numeric ABI word back into a Uint<128>: the big-endian fold of
|
|
398
439
|
// bytes 16..31. The leading half must be zero (a canonical Uint<128> word);
|
|
399
440
|
// rejecting junk there keeps settle circuits from silently truncating a
|
|
@@ -418,4 +459,13 @@ module Signet {
|
|
|
418
459
|
const b15 = b14 * 256 + (slice<1>(word, 31) as Field);
|
|
419
460
|
return b15 as Uint<128>;
|
|
420
461
|
}
|
|
462
|
+
|
|
463
|
+
// Read a Boolean ABI word back into a Boolean. The first 31 bytes must be
|
|
464
|
+
// zero and the last byte 0 or 1: any non-canonical word is rejected.
|
|
465
|
+
export pure circuit abiWordToBool(word: Bytes<32>): Boolean {
|
|
466
|
+
assert(slice<31>(word, 0) as Field == 0 as Field, "ABI word is not a canonical Boolean");
|
|
467
|
+
const last = slice<1>(word, 31) as Field;
|
|
468
|
+
assert(last == 0 as Field || last == 1 as Field, "ABI word is not a canonical Boolean");
|
|
469
|
+
return last == 1 as Field;
|
|
470
|
+
}
|
|
421
471
|
}
|
package/src/circuits.compact
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
pragma language_version >= 0.25;
|
|
2
2
|
|
|
3
|
-
// Compiled export surface of the Signet module.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// exercise the REAL circuits, and off-chain code (the attestation digest,
|
|
11
|
-
// response verification, key-pin hashing, notification packing) reuses them
|
|
12
|
-
// instead of hand-porting the algorithms. Off-chain code only ever DECODES a
|
|
13
|
-
// SignBidirectionalEventNotification (fixed-offset byte reads), but tests
|
|
14
|
-
// build fixtures with the compiled packer to pin the pack<->decode lockstep.
|
|
15
|
-
//
|
|
16
|
-
// ONLY the non-generic circuits are exported here. The request circuits
|
|
17
|
-
// (calculateRequestId, constructSignBidirectionalEvent) are generic over the
|
|
18
|
-
// tx-params type and schema lengths, the compiler cannot export
|
|
19
|
-
// type-parameterized circuits from the top level, and this package is
|
|
20
|
-
// client-agnostic: a capacity instantiation is a CLIENT contract's choice and
|
|
21
|
-
// never belongs here. constructSignBidirectionalEvent is contract-only, so it
|
|
22
|
-
// needs no off-chain copy. calculateRequestId IS needed off-chain (clients
|
|
23
|
-
// recompute ledger map keys), so it alone has a documented-deviation TS twin
|
|
24
|
-
// in signet-requests.ts, kept honest by caller-contract's
|
|
25
|
-
// submitSignatureRequest round-trip test.
|
|
26
|
-
//
|
|
27
|
-
// Compile with --skip-zk only: pure circuits run in TS without proving keys.
|
|
28
|
-
// The secp256k1 types require the --feature-zkir-v3 compiler flag.
|
|
3
|
+
// Compiled export surface of the Signet module. Signet.compact is
|
|
4
|
+
// module-only and compiles to nothing on its own, so this contract-less
|
|
5
|
+
// program re-exports its pure circuits: the compiler emits them as
|
|
6
|
+
// pureCircuits for unit tests and off-chain code to reuse instead of
|
|
7
|
+
// re-porting the algorithms. Only non-generic circuits can be exported
|
|
8
|
+
// (the compiler cannot export type-parameterised circuits top-level).
|
|
9
|
+
// Compile with --skip-zk and --feature-zkir-v3.
|
|
29
10
|
|
|
30
11
|
import CompactStandardLibrary;
|
|
31
12
|
import "./Signet";
|
|
@@ -37,5 +18,7 @@ export {
|
|
|
37
18
|
constructSignBidirectionalEventNotificationV1,
|
|
38
19
|
evmAddressAbiWord,
|
|
39
20
|
numericAbiWord,
|
|
40
|
-
|
|
21
|
+
boolAbiWord,
|
|
22
|
+
abiWordToUint128,
|
|
23
|
+
abiWordToBool
|
|
41
24
|
};
|