@ocap/state 1.31.9 → 1.32.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/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/states/blacklist.mjs +3 -2
- package/esm/states/chain.d.mts +10 -4
- package/esm/states/chain.mjs +51 -3
- package/esm/states/evidence.d.mts +1 -1
- package/esm/states/evidence.mjs +6 -2
- package/esm/states/rollup-bridge.d.mts +9 -9
- package/esm/states/rollup-bridge.mjs +20 -5
- package/esm/states/rollup-v2.d.mts +42 -6
- package/esm/states/rollup-v2.mjs +176 -11
- package/esm/states/rollup.d.mts +3 -3
- package/esm/states/rollup.mjs +6 -3
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +2 -2
- package/lib/states/blacklist.cjs +3 -2
- package/lib/states/chain.cjs +51 -2
- package/lib/states/chain.d.cts +10 -4
- package/lib/states/evidence.cjs +5 -1
- package/lib/states/evidence.d.cts +1 -1
- package/lib/states/rollup-bridge.cjs +19 -4
- package/lib/states/rollup-bridge.d.cts +9 -9
- package/lib/states/rollup-v2.cjs +179 -11
- package/lib/states/rollup-v2.d.cts +42 -6
- package/lib/states/rollup.cjs +8 -2
- package/lib/states/rollup.d.cts +3 -3
- package/package.json +10 -9
package/esm/states/rollup-v2.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEthereumDid, isFromPublicKey } from "@arcblock/did";
|
|
2
2
|
import { toChecksumAddress } from "@arcblock/did/lib/type";
|
|
3
3
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
+
import { canonicalJson, computeEvmGovernanceConfigHash, parseDecimalBigInt, recoverBridgeEvmGovernanceSyncSigner, validateEvmGovernanceRosterConfig } from "@ocap/mcrypto";
|
|
4
5
|
|
|
5
6
|
//#region src/states/rollup-v2.ts
|
|
6
7
|
/**
|
|
@@ -43,7 +44,8 @@ const BRIDGE_CREATE_KEYS = [
|
|
|
43
44
|
"pausers",
|
|
44
45
|
"ethOwnerAttestation",
|
|
45
46
|
"consents",
|
|
46
|
-
"initialReserve"
|
|
47
|
+
"initialReserve",
|
|
48
|
+
"evmGovernance"
|
|
47
49
|
];
|
|
48
50
|
/** Keys `update_rollup` may patch. `proposeOwner` / `cancelOwnerProposal` / `cancelPendingEpoch` are actions. */
|
|
49
51
|
const BRIDGE_PATCH_VALUE_KEYS = [
|
|
@@ -54,13 +56,15 @@ const BRIDGE_PATCH_VALUE_KEYS = [
|
|
|
54
56
|
"refundDailyCap",
|
|
55
57
|
"releaseGrace",
|
|
56
58
|
"refundDelay",
|
|
57
|
-
"pausers"
|
|
59
|
+
"pausers",
|
|
60
|
+
"evmGovernance"
|
|
58
61
|
];
|
|
59
62
|
const BRIDGE_PATCH_ACTION_KEYS = [
|
|
60
63
|
"cancelPendingEpoch",
|
|
61
64
|
"proposeOwner",
|
|
62
65
|
"cancelOwnerProposal"
|
|
63
66
|
];
|
|
67
|
+
const BRIDGE_PATCH_PROOF_KEYS = ["evmGovernanceSync"];
|
|
64
68
|
const bad = (message) => {
|
|
65
69
|
throw new CustomError("INVALID_ROLLUP_PROPS", message);
|
|
66
70
|
};
|
|
@@ -85,8 +89,10 @@ const toSeconds = (iso) => {
|
|
|
85
89
|
return Math.floor(ms / 1e3);
|
|
86
90
|
};
|
|
87
91
|
const lc = (address) => String(address || "").toLowerCase();
|
|
92
|
+
/** Strip a case-insensitive `did:abt:` prefix and whitespace, returning a lowercase bare Ethereum address. */
|
|
93
|
+
const bareEthAddress = (a) => String(a ?? "").trim().replace(/^did:abt:/i, "").toLowerCase();
|
|
88
94
|
/** Ethereum addresses compare case-insensitively; OCAP addresses may carry a DID prefix. */
|
|
89
|
-
const sameAddress = (a, b) => typeof a === "string" && typeof b === "string" && !!a &&
|
|
95
|
+
const sameAddress = (a, b) => typeof a === "string" && typeof b === "string" && !!bareEthAddress(a) && bareEthAddress(a) === bareEthAddress(b);
|
|
90
96
|
const isDecimal = (s) => typeof s === "string" && /^(0|[1-9][0-9]*)$/.test(s);
|
|
91
97
|
const isUint = (n, max = Number.MAX_SAFE_INTEGER) => typeof n === "number" && Number.isInteger(n) && n >= 0 && n <= max;
|
|
92
98
|
const isEthAddr = (s) => typeof s === "string" && /^0x[0-9a-fA-F]{40}$/.test(s) && !/^0x0{40}$/.test(s);
|
|
@@ -244,11 +250,103 @@ function validatePausers(pausers) {
|
|
|
244
250
|
if (!Array.isArray(pausers) || pausers.length > BRIDGE_MAX_PAUSERS) bad(`pausers must be an array of at most ${BRIDGE_MAX_PAUSERS} addresses`);
|
|
245
251
|
const seen = /* @__PURE__ */ new Set();
|
|
246
252
|
for (const p of pausers) {
|
|
247
|
-
if (typeof p !== "string" || !p || p.length > 128 ||
|
|
253
|
+
if (typeof p !== "string" || !p || p.length > 128 || /^did:abt:/i.test(p)) bad("pausers must be address strings without a DID prefix");
|
|
248
254
|
if (seen.has(lc(p))) bad("pausers must be unique");
|
|
249
255
|
seen.add(lc(p));
|
|
250
256
|
}
|
|
251
257
|
}
|
|
258
|
+
function validateStrictEvmGovernance(raw, errorCode) {
|
|
259
|
+
const fail = (msg) => {
|
|
260
|
+
throw new CustomError(errorCode, msg);
|
|
261
|
+
};
|
|
262
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) fail("evmGovernance must be an object");
|
|
263
|
+
const checkStrictSet = (setRaw, label) => {
|
|
264
|
+
if (!setRaw || typeof setRaw !== "object" || Array.isArray(setRaw)) fail(`${label} must be an object`);
|
|
265
|
+
const s = setRaw;
|
|
266
|
+
if (typeof s.address !== "string" || !ETH_ADDRESS_FORMAT.test(s.address) || s.address !== toChecksumAddress(s.address)) fail(`${label}.address must be an EIP-55 checksummed non-zero ethereum address`);
|
|
267
|
+
for (const field of ["signers", "seeds"]) {
|
|
268
|
+
if (!Array.isArray(s[field]) || s[field].length === 0) fail(`${label}.${field} must be a non-empty array`);
|
|
269
|
+
let prevBig = -1n;
|
|
270
|
+
for (let i = 0; i < s[field].length; i++) {
|
|
271
|
+
const addr = s[field][i];
|
|
272
|
+
if (typeof addr !== "string" || !ETH_ADDRESS_FORMAT.test(addr) || addr !== toChecksumAddress(addr)) fail(`${label}.${field}[${i}] must be an EIP-55 checksummed non-zero ethereum address`);
|
|
273
|
+
const curBig = BigInt(addr);
|
|
274
|
+
if (curBig <= 0n || curBig <= prevBig) fail(`${label}.${field} must be strictly ascending unique non-zero EIP-55 addresses`);
|
|
275
|
+
prevBig = curBig;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const r = raw;
|
|
280
|
+
checkStrictSet(r.signerManager, "evmGovernance.signerManager");
|
|
281
|
+
if (r.vaultSignerManager !== null) checkStrictSet(r.vaultSignerManager, "evmGovernance.vaultSignerManager");
|
|
282
|
+
try {
|
|
283
|
+
return validateEvmGovernanceRosterConfig(raw);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
return fail(`invalid evmGovernance: ${err.message}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Verifies a `BridgeEvmGovernanceSync` EIP-712 proof signed by the OLD `prev` EVM governance roster (`signerManager`,
|
|
290
|
+
* and `vaultSignerManager` when distinct and modified), bound to `(ocapChainId, bridge, next.version, configHash(next))`
|
|
291
|
+
* and `txSec < expiresAt`.
|
|
292
|
+
*/
|
|
293
|
+
function verifyBridgeEvmGovernanceSync(o) {
|
|
294
|
+
const prev = o.prev;
|
|
295
|
+
if (!prev) throw new CustomError("INVALID_ROLLUP_UPDATE", "evmGovernanceSync requires an existing evmGovernance roster; bootstrap from null needs owner + quorum");
|
|
296
|
+
if (o.next.version !== prev.version + 1) badUpdate(`evmGovernance.version must equal ${prev.version + 1}, got ${o.next.version}`);
|
|
297
|
+
if (!o.proof || typeof o.proof !== "object" || Array.isArray(o.proof)) badUpdate("evmGovernanceSync must be { expiresAt, signatures }");
|
|
298
|
+
const p = o.proof;
|
|
299
|
+
for (const k of Object.keys(p)) if (k !== "expiresAt" && k !== "signatures") badUpdate(`unknown key in evmGovernanceSync: ${k}`);
|
|
300
|
+
let expiresAt;
|
|
301
|
+
try {
|
|
302
|
+
expiresAt = parseDecimalBigInt(typeof p.expiresAt === "number" && Number.isSafeInteger(p.expiresAt) ? String(p.expiresAt) : p.expiresAt, "evmGovernanceSync.expiresAt", 1n, (1n << 64n) - 1n);
|
|
303
|
+
} catch (err) {
|
|
304
|
+
badUpdate(err.message);
|
|
305
|
+
}
|
|
306
|
+
if (BigInt(o.txSec) >= expiresAt) badUpdate("evmGovernanceSync proof has expired");
|
|
307
|
+
if (!Array.isArray(p.signatures) || p.signatures.length === 0 || p.signatures.length > 64) badUpdate("evmGovernanceSync.signatures must contain 1..64 signatures");
|
|
308
|
+
const configHash = computeEvmGovernanceConfigHash(o.next);
|
|
309
|
+
const msg = {
|
|
310
|
+
bridge: o.bridge,
|
|
311
|
+
version: BigInt(o.next.version),
|
|
312
|
+
configHash,
|
|
313
|
+
expiresAt
|
|
314
|
+
};
|
|
315
|
+
const recoveredSigners = /* @__PURE__ */ new Set();
|
|
316
|
+
for (const sig of p.signatures) {
|
|
317
|
+
if (typeof sig !== "string") badUpdate("evmGovernanceSync signature must be a 0x hex string");
|
|
318
|
+
let signer;
|
|
319
|
+
try {
|
|
320
|
+
signer = recoverBridgeEvmGovernanceSyncSigner(o.ocapChainId, msg, sig).signer;
|
|
321
|
+
} catch (err) {
|
|
322
|
+
throw new CustomError("INVALID_SIGNATURE", `Invalid evmGovernanceSync signature: ${err.message}`);
|
|
323
|
+
}
|
|
324
|
+
if (recoveredSigners.has(signer)) throw new CustomError("INVALID_SIGNATURE", `Duplicate evmGovernanceSync signature from ${signer}`);
|
|
325
|
+
recoveredSigners.add(signer);
|
|
326
|
+
}
|
|
327
|
+
const smChanged = canonicalJson(prev.signerManager) !== canonicalJson(o.next.signerManager);
|
|
328
|
+
const vsmChanged = canonicalJson(prev.vaultSignerManager) !== canonicalJson(o.next.vaultSignerManager);
|
|
329
|
+
if (!smChanged && !vsmChanged) badUpdate("evmGovernanceSync must modify signerManager or vaultSignerManager");
|
|
330
|
+
if (prev.vaultSignerManager !== null && o.next.vaultSignerManager === null) badUpdate("evmGovernance.vaultSignerManager can not be set to null once configured");
|
|
331
|
+
const distinctPrevVsm = prev.vaultSignerManager !== null && prev.vaultSignerManager.address !== prev.signerManager.address;
|
|
332
|
+
const requiredSets = [{
|
|
333
|
+
label: "signerManager",
|
|
334
|
+
roster: prev.signerManager
|
|
335
|
+
}];
|
|
336
|
+
if (distinctPrevVsm && vsmChanged && prev.vaultSignerManager !== null) requiredSets.push({
|
|
337
|
+
label: "vaultSignerManager",
|
|
338
|
+
roster: prev.vaultSignerManager
|
|
339
|
+
});
|
|
340
|
+
const allowedAll = /* @__PURE__ */ new Set();
|
|
341
|
+
for (const { roster } of requiredSets) for (const s of roster.signers) allowedAll.add(s);
|
|
342
|
+
for (const signer of recoveredSigners) if (!allowedAll.has(signer)) throw new CustomError("INVALID_SIGNATURE", `evmGovernanceSync signer ${signer} is not in the previous EVM governance roster`);
|
|
343
|
+
for (const { label, roster } of requiredSets) {
|
|
344
|
+
const validCount = roster.signers.filter((s) => recoveredSigners.has(s)).length;
|
|
345
|
+
const seedCount = roster.seeds.filter((s) => recoveredSigners.has(s)).length;
|
|
346
|
+
if (validCount < roster.threshold) throw new CustomError("INVALID_SIGNATURE", `evmGovernanceSync requires at least ${roster.threshold} ${label} signatures, got ${validCount}`);
|
|
347
|
+
if (seedCount < roster.seedThreshold) throw new CustomError("INVALID_SIGNATURE", `evmGovernanceSync requires at least ${roster.seedThreshold} ${label} seed signatures, got ${seedCount}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
252
350
|
/** Full structural validation of a stored v2 body. */
|
|
253
351
|
function validateBridgeBody(body) {
|
|
254
352
|
if (!body || typeof body !== "object" || body.version !== BRIDGE_VERSION) bad("bridge body version must be 2");
|
|
@@ -287,6 +385,7 @@ function validateBridgeBody(body) {
|
|
|
287
385
|
if (body.depositCutoffEthBlock !== null && !isDecimal(body.depositCutoffEthBlock)) bad("depositCutoffEthBlock must be null or a decimal string");
|
|
288
386
|
if (body.migratedTo !== null && typeof body.migratedTo !== "string") bad("migratedTo must be null or an address");
|
|
289
387
|
if (body.migratedAmount !== void 0 && body.migratedAmount !== null && !isDecimal(body.migratedAmount)) bad("migratedAmount must be null or a decimal string");
|
|
388
|
+
if (body.evmGovernance !== void 0 && body.evmGovernance !== null) validateStrictEvmGovernance(body.evmGovernance, "INVALID_ROLLUP_PROPS");
|
|
290
389
|
const att = body.ethOwnerAttestation;
|
|
291
390
|
if (!att || !isEthAddr(att.address) || typeof att.signature !== "string" || !/^0x[0-9a-fA-F]{130}$/.test(att.signature)) bad("ethOwnerAttestation must be { address, signature }");
|
|
292
391
|
return body;
|
|
@@ -394,6 +493,34 @@ function assertBridgeTransition(prev, next, txSec) {
|
|
|
394
493
|
if (pa !== null && (na === null || BigInt(na) > BigInt(pa))) badUpdate("migratedAmount can only decrease");
|
|
395
494
|
if (p.closingAt !== null && (p.closingAt !== nb.closingAt || p.finalAt !== nb.finalAt)) badUpdate("closingAt and finalAt are written once");
|
|
396
495
|
if (p.closingAt !== null && (added > 0 || removed > 0)) badUpdate("epochs are frozen after closingAt");
|
|
496
|
+
if (JSON.stringify(prev.migrateHistory ?? []) !== JSON.stringify(next.migrateHistory ?? [])) badUpdate("migrateHistory is immutable in a v2 bridge");
|
|
497
|
+
const prevGov = p.evmGovernance ?? null;
|
|
498
|
+
const nextGov = nb.evmGovernance ?? null;
|
|
499
|
+
if (canonicalJson(prevGov) !== canonicalJson(nextGov)) {
|
|
500
|
+
if (p.closingAt !== null) badUpdate("evmGovernance is frozen after closingAt");
|
|
501
|
+
if (prevGov !== null && nextGov === null) badUpdate("evmGovernance can not be cleared once configured");
|
|
502
|
+
if (nextGov !== null) {
|
|
503
|
+
validateStrictEvmGovernance(nextGov, "INVALID_ROLLUP_UPDATE");
|
|
504
|
+
if (prevGov?.vaultSignerManager !== null && prevGov?.vaultSignerManager !== void 0 && nextGov.vaultSignerManager === null) badUpdate("evmGovernance.vaultSignerManager can not be set to null once configured");
|
|
505
|
+
const nextVault = bareEthAddress(next.vaultAddress);
|
|
506
|
+
if (nextVault && !/^0x0{40}$/.test(nextVault) && nextGov.vaultSignerManager === null) badUpdate("evmGovernance.vaultSignerManager is required when vaultAddress is configured");
|
|
507
|
+
const expectedVersion = prevGov ? prevGov.version + 1 : 1;
|
|
508
|
+
if (nextGov.version !== expectedVersion) badUpdate(`evmGovernance.version must equal ${expectedVersion}, got ${nextGov.version}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const prevHistory = Array.isArray(prev.vaultHistory) ? prev.vaultHistory : [];
|
|
512
|
+
const nextHistory = Array.isArray(next.vaultHistory) ? next.vaultHistory : [];
|
|
513
|
+
if (prev.vaultAddress === next.vaultAddress) {
|
|
514
|
+
if (JSON.stringify(prevHistory) !== JSON.stringify(nextHistory)) badUpdate("vaultHistory only changes when vaultAddress migrates");
|
|
515
|
+
} else {
|
|
516
|
+
if (p.closingAt !== null || prev.closed) badUpdate("vaultAddress is frozen after closingAt");
|
|
517
|
+
if (txSec !== null ? !isBridgePausedAt(prev, txSec) : !prev.paused) badUpdate("vaultAddress can only change while the bridge is paused");
|
|
518
|
+
if (typeof prev.vaultAddress !== "string" || !prev.vaultAddress) badUpdate("previous vaultAddress is missing");
|
|
519
|
+
if (typeof next.vaultAddress !== "string" || !next.vaultAddress || next.vaultAddress !== next.vaultAddress.trim()) badUpdate("vaultAddress must be a trimmed non-empty ethereum address");
|
|
520
|
+
if (sameAddress(prev.vaultAddress, next.vaultAddress)) badUpdate("can not migrate vault to self");
|
|
521
|
+
if (prevHistory.some((h) => sameAddress(h, next.vaultAddress))) badUpdate("can not migrate vault to history vaults");
|
|
522
|
+
if (JSON.stringify(nextHistory) !== JSON.stringify([...prevHistory, prev.vaultAddress])) badUpdate("vaultHistory must append the previous vaultAddress");
|
|
523
|
+
}
|
|
397
524
|
}
|
|
398
525
|
/** Parse and validate `itx.data.value` of a v2 `create_rollup` (pure shape checks; signatures are checked by the protocol). */
|
|
399
526
|
function parseBridgeCreateData(value) {
|
|
@@ -416,6 +543,11 @@ function parseBridgeCreateData(value) {
|
|
|
416
543
|
if (!isDecimal(initialReserve)) bad("initialReserve must be a decimal string");
|
|
417
544
|
const att = value.ethOwnerAttestation;
|
|
418
545
|
if (!att || !isEthAddr(att.address)) bad("ethOwnerAttestation.address is required");
|
|
546
|
+
let evmGovernance = null;
|
|
547
|
+
if (value.evmGovernance !== void 0 && value.evmGovernance !== null) {
|
|
548
|
+
evmGovernance = validateStrictEvmGovernance(value.evmGovernance, "INVALID_ROLLUP_PROPS");
|
|
549
|
+
if (evmGovernance.version !== 1) bad("initial evmGovernance.version must be 1");
|
|
550
|
+
}
|
|
419
551
|
const body = {
|
|
420
552
|
version: BRIDGE_VERSION,
|
|
421
553
|
ethChainId: value.ethChainId,
|
|
@@ -432,6 +564,7 @@ function parseBridgeCreateData(value) {
|
|
|
432
564
|
epochs: [epoch],
|
|
433
565
|
salt: typeof value.salt === "string" ? lc(value.salt) : value.salt,
|
|
434
566
|
pausers: value.pausers === void 0 ? [] : value.pausers,
|
|
567
|
+
evmGovernance,
|
|
435
568
|
ethOwnerAttestation: {
|
|
436
569
|
address: lc(att.address),
|
|
437
570
|
signature: att.signature
|
|
@@ -453,17 +586,26 @@ function parseBridgeCreateData(value) {
|
|
|
453
586
|
}
|
|
454
587
|
/**
|
|
455
588
|
* Validate an `update_rollup` patch (`itx.data.value`) against the allow-list and compute the resulting body.
|
|
456
|
-
* `proposeOwner` is its own transaction kind (2/3 quorum), `cancelOwnerProposal` needs the current owner alone,
|
|
589
|
+
* `proposeOwner` is its own transaction kind (2/3 quorum), `cancelOwnerProposal` needs the current owner alone,
|
|
590
|
+
* standalone `{ evmGovernance, evmGovernanceSync }` is verified against the previous EVM governance roster, and anything
|
|
457
591
|
* else needs owner + quorum. Frozen keys (version, epochs, reserve, gateway, ethChainId, token fields...) are rejected.
|
|
458
592
|
*/
|
|
459
|
-
function planBridgePatch(body, patch, txSec) {
|
|
593
|
+
function planBridgePatch(body, patch, txSec, syncCtx) {
|
|
460
594
|
if (!patch || typeof patch !== "object" || Array.isArray(patch)) badUpdate("update data must be a typed patch object");
|
|
461
595
|
const keys = Object.keys(patch);
|
|
462
596
|
if (keys.length === 0) badUpdate("update patch is empty");
|
|
463
|
-
const allowed = [
|
|
597
|
+
const allowed = [
|
|
598
|
+
...BRIDGE_PATCH_VALUE_KEYS,
|
|
599
|
+
...BRIDGE_PATCH_ACTION_KEYS,
|
|
600
|
+
...BRIDGE_PATCH_PROOF_KEYS
|
|
601
|
+
];
|
|
464
602
|
for (const k of keys) if (!allowed.includes(k)) badUpdate(`key ${k} can not be updated in a v2 bridge`);
|
|
465
603
|
const has = (k) => patch[k] !== void 0;
|
|
466
|
-
|
|
604
|
+
if (has("evmGovernanceSync") && !has("evmGovernance")) badUpdate("evmGovernanceSync requires evmGovernance in patch");
|
|
605
|
+
const next = {
|
|
606
|
+
...body,
|
|
607
|
+
evmGovernance: body.evmGovernance ?? null
|
|
608
|
+
};
|
|
467
609
|
const ownerOnly = has("proposeOwner") || has("cancelOwnerProposal");
|
|
468
610
|
if (body.closingAt !== null && (!ownerOnly || body.migratedTo !== null)) badUpdate(body.migratedTo !== null ? "the reserve has migrated: the bridge is frozen" : "a closed bridge is frozen");
|
|
469
611
|
if (has("proposeOwner") || has("cancelOwnerProposal")) {
|
|
@@ -525,6 +667,28 @@ function planBridgePatch(body, patch, txSec) {
|
|
|
525
667
|
cancelledEpoch = pending;
|
|
526
668
|
next.epochs = body.epochs.slice(0, -1);
|
|
527
669
|
}
|
|
670
|
+
if (has("evmGovernance")) {
|
|
671
|
+
if (patch.evmGovernance === null) badUpdate("evmGovernance can not be set to null via update_rollup");
|
|
672
|
+
const prevGov = body.evmGovernance ?? null;
|
|
673
|
+
const validatedGov = validateStrictEvmGovernance(patch.evmGovernance, "INVALID_ROLLUP_UPDATE");
|
|
674
|
+
if (prevGov?.vaultSignerManager !== null && prevGov?.vaultSignerManager !== void 0 && validatedGov.vaultSignerManager === null) badUpdate("evmGovernance.vaultSignerManager can not be set to null once configured");
|
|
675
|
+
const vaultAddr = syncCtx?.vaultAddress ? bareEthAddress(syncCtx.vaultAddress) : "";
|
|
676
|
+
if (vaultAddr && !/^0x0{40}$/.test(vaultAddr) && validatedGov.vaultSignerManager === null) badUpdate("evmGovernance.vaultSignerManager is required when vaultAddress is configured");
|
|
677
|
+
const expectedVersion = prevGov ? prevGov.version + 1 : 1;
|
|
678
|
+
if (validatedGov.version !== expectedVersion) badUpdate(`evmGovernance.version must equal ${expectedVersion}, got ${validatedGov.version}`);
|
|
679
|
+
if (has("evmGovernanceSync")) {
|
|
680
|
+
if (!syncCtx) throw new CustomError("INVALID_ROLLUP_UPDATE", "evmGovernanceSync verification requires chain and bridge context");
|
|
681
|
+
verifyBridgeEvmGovernanceSync({
|
|
682
|
+
ocapChainId: syncCtx.ocapChainId,
|
|
683
|
+
bridge: syncCtx.bridge,
|
|
684
|
+
prev: prevGov,
|
|
685
|
+
next: validatedGov,
|
|
686
|
+
proof: patch.evmGovernanceSync,
|
|
687
|
+
txSec
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
next.evmGovernance = validatedGov;
|
|
691
|
+
}
|
|
528
692
|
try {
|
|
529
693
|
validateAmounts(next);
|
|
530
694
|
validateDelays(next);
|
|
@@ -532,9 +696,10 @@ function planBridgePatch(body, patch, txSec) {
|
|
|
532
696
|
badUpdate(err.message);
|
|
533
697
|
}
|
|
534
698
|
return {
|
|
535
|
-
kind: "owner-quorum",
|
|
699
|
+
kind: has("evmGovernance") && has("evmGovernanceSync") && keys.every((k) => k === "evmGovernance" || k === "evmGovernanceSync") ? "evm-governance-sync" : "owner-quorum",
|
|
536
700
|
body: next,
|
|
537
|
-
cancelledEpoch
|
|
701
|
+
cancelledEpoch,
|
|
702
|
+
...has("evmGovernanceSync") ? { evmGovernanceSync: patch.evmGovernanceSync } : {}
|
|
538
703
|
};
|
|
539
704
|
}
|
|
540
705
|
/** Epoch rules of §v2.2: `epoch = last + 1`, lead window, `2*threshold > n`, `n >= 3`, at most one pending epoch. */
|
|
@@ -594,4 +759,4 @@ function applyLonePause(body, by, txSec) {
|
|
|
594
759
|
}
|
|
595
760
|
|
|
596
761
|
//#endregion
|
|
597
|
-
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody };
|
|
762
|
+
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody, verifyBridgeEvmGovernanceSync };
|
package/esm/states/rollup.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StateContextInput } from "../contexts/state.mjs";
|
|
2
|
-
import { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody } from "./rollup-v2.mjs";
|
|
2
|
+
import { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeEvmGovernance, BridgeEvmGovernanceSyncProof, BridgeEvmSignerSet, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody, verifyBridgeEvmGovernanceSync } from "./rollup-v2.mjs";
|
|
3
3
|
import { bridgeSchema, createBridge, updateBridge, validateBridge } from "./rollup-bridge.mjs";
|
|
4
4
|
import { v } from "@arcblock/validator";
|
|
5
5
|
import { IRollupState } from "@ocap/types";
|
|
6
6
|
|
|
7
7
|
//#region src/states/rollup.d.ts
|
|
8
8
|
declare namespace rollup_d_exports {
|
|
9
|
-
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody };
|
|
9
|
+
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeEvmGovernance, BridgeEvmGovernanceSyncProof, BridgeEvmSignerSet, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody, verifyBridgeEvmGovernanceSync };
|
|
10
10
|
}
|
|
11
11
|
type RollupTargetType = 'EVM' | 'OCAP_ISOMORPHIC';
|
|
12
12
|
interface RollupTokenReserve {
|
|
@@ -105,4 +105,4 @@ declare const recordRollupDeposit: (state: IRollupState & Record<string, any>, t
|
|
|
105
105
|
declare const recordRollupWithdraw: (state: IRollupState & Record<string, any>, tokenAddress: string, amount: string, context: StateContextInput) => IRollupState;
|
|
106
106
|
declare const validate: (state: IRollupState & Record<string, any>) => IRollupState;
|
|
107
107
|
//#endregion
|
|
108
|
-
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, rollup_d_exports, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody };
|
|
108
|
+
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeEvmGovernance, BridgeEvmGovernanceSyncProof, BridgeEvmSignerSet, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, rollup_d_exports, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody, verifyBridgeEvmGovernanceSync };
|
package/esm/states/rollup.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
|
|
2
2
|
import { create as create$1, update as update$1 } from "../contexts/state.mjs";
|
|
3
|
-
import { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody } from "./rollup-v2.mjs";
|
|
3
|
+
import { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody, verifyBridgeEvmGovernanceSync } from "./rollup-v2.mjs";
|
|
4
4
|
import { bridgeSchema, createBridge, updateBridge, validateBridge } from "./rollup-bridge.mjs";
|
|
5
5
|
import { BN, toAddress } from "@ocap/util";
|
|
6
6
|
import { CustomError } from "@ocap/util/lib/error";
|
|
@@ -21,6 +21,7 @@ var rollup_exports = /* @__PURE__ */ __exportAll({
|
|
|
21
21
|
BRIDGE_MIN_VALIDATORS: () => BRIDGE_MIN_VALIDATORS,
|
|
22
22
|
BRIDGE_OWNER_TIMELOCK: () => BRIDGE_OWNER_TIMELOCK,
|
|
23
23
|
BRIDGE_PATCH_ACTION_KEYS: () => BRIDGE_PATCH_ACTION_KEYS,
|
|
24
|
+
BRIDGE_PATCH_PROOF_KEYS: () => BRIDGE_PATCH_PROOF_KEYS,
|
|
24
25
|
BRIDGE_PATCH_VALUE_KEYS: () => BRIDGE_PATCH_VALUE_KEYS,
|
|
25
26
|
BRIDGE_RESERVE_MIGRATION_WINDOW: () => BRIDGE_RESERVE_MIGRATION_WINDOW,
|
|
26
27
|
BRIDGE_V1_ZERO_FIELDS: () => BRIDGE_V1_ZERO_FIELDS,
|
|
@@ -30,6 +31,7 @@ var rollup_exports = /* @__PURE__ */ __exportAll({
|
|
|
30
31
|
applyLonePause: () => applyLonePause,
|
|
31
32
|
assertBridgeTransition: () => assertBridgeTransition,
|
|
32
33
|
assertV1FieldsUnused: () => assertV1FieldsUnused,
|
|
34
|
+
bareEthAddress: () => bareEthAddress,
|
|
33
35
|
bridgeSchema: () => bridgeSchema,
|
|
34
36
|
close: () => close,
|
|
35
37
|
create: () => create,
|
|
@@ -75,7 +77,8 @@ var rollup_exports = /* @__PURE__ */ __exportAll({
|
|
|
75
77
|
updateBridge: () => updateBridge,
|
|
76
78
|
validate: () => validate,
|
|
77
79
|
validateBridge: () => validateBridge,
|
|
78
|
-
validateBridgeBody: () => validateBridgeBody
|
|
80
|
+
validateBridgeBody: () => validateBridgeBody,
|
|
81
|
+
verifyBridgeEvmGovernanceSync: () => verifyBridgeEvmGovernanceSync
|
|
79
82
|
});
|
|
80
83
|
const VALID_ROLLUP_TARGET_TYPES = ["EVM", "OCAP_ISOMORPHIC"];
|
|
81
84
|
const ethDidSchema = vDID({
|
|
@@ -458,4 +461,4 @@ const validate = (state) => {
|
|
|
458
461
|
};
|
|
459
462
|
|
|
460
463
|
//#endregion
|
|
461
|
-
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, rollup_exports, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody };
|
|
464
|
+
export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_PROOF_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bareEthAddress, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, rollup_exports, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody, verifyBridgeEvmGovernanceSync };
|
package/lib/index.cjs
CHANGED
|
@@ -139,6 +139,7 @@ Object.defineProperty(exports, 'tokenFactory', {
|
|
|
139
139
|
return require_states_token_factory.token_factory_exports;
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
|
+
exports.tryDeriveProtobufTokenAddress = require_states_chain.tryDeriveProtobufTokenAddress;
|
|
142
143
|
Object.defineProperty(exports, 'tx', {
|
|
143
144
|
enumerable: true,
|
|
144
145
|
get: function () {
|
package/lib/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { account_d_exports, parseNonceBn } from "./states/account.cjs";
|
|
2
2
|
import { asset_d_exports } from "./states/asset.cjs";
|
|
3
|
-
import { ChainState, chain_d_exports } from "./states/chain.cjs";
|
|
3
|
+
import { ChainState, chain_d_exports, tryDeriveProtobufTokenAddress } from "./states/chain.cjs";
|
|
4
4
|
import { delegation_d_exports } from "./states/delegation.cjs";
|
|
5
5
|
import { evidence_d_exports } from "./states/evidence.cjs";
|
|
6
6
|
import { factory_d_exports } from "./states/factory.cjs";
|
|
@@ -17,4 +17,4 @@ import Blacklist, { BlacklistOptions, TrustedAccountConfig } from "./states/blac
|
|
|
17
17
|
declare const indexes: readonly ["account", "asset", "delegation", "tx", "factory", "token", "stake", "rollup", "rollupBlock", "rollupValidator", "tokenDistribution", "tokenFactory"];
|
|
18
18
|
declare const tables: readonly ["chain", "account", "asset", "delegation", "tx", "factory", "token", "stake", "rollup", "rollupBlock", "evidence", "balance", "tokenFactory"];
|
|
19
19
|
//#endregion
|
|
20
|
-
export { Blacklist, type BlacklistOptions, type ChainState, type ItxJson, type Receipt, type ReceiptChange, type RollupTargetType, type RollupTokenReserve, TOKEN_CHARTER_KIND, type TokenCharterAssetPayload, type TokenInput, type TrustedAccountConfig, type TxContext, type TxData, type TxInput, type TxOutput, type TxResult, VALID_ROLLUP_TARGET_TYPES, account_d_exports as account, asset_d_exports as asset, buildTokenCharterAssetData, buildTokenCharterAssetState, chain_d_exports as chain, delegation_d_exports as delegation, evidence_d_exports as evidence, extractTokenUpdatesFromCharterAsset, factory_d_exports as factory, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, iconToNftDisplay, indexes, isProposerSponsoredDepositAllowed, isTokenCharterAsset, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, migrateTokensToCharterAssets, normalizeLegacyTokenStateForUpdate, parseNonceBn, recordRollupDeposit, recordRollupWithdraw, resolveCharterMoniker, rollup_d_exports as rollup, rollup_block_d_exports as rollupBlock, sanitizeTokenSvg, stake_d_exports as stake, syncCharterAssetWithToken, syncTokenCharterOwnership, tables, toTokenCharterAssetAddress, token_d_exports as token, token_factory_d_exports as tokenFactory, tx_d_exports as tx, websiteToNftEndpoint };
|
|
20
|
+
export { Blacklist, type BlacklistOptions, type ChainState, type ItxJson, type Receipt, type ReceiptChange, type RollupTargetType, type RollupTokenReserve, TOKEN_CHARTER_KIND, type TokenCharterAssetPayload, type TokenInput, type TrustedAccountConfig, type TxContext, type TxData, type TxInput, type TxOutput, type TxResult, VALID_ROLLUP_TARGET_TYPES, account_d_exports as account, asset_d_exports as asset, buildTokenCharterAssetData, buildTokenCharterAssetState, chain_d_exports as chain, delegation_d_exports as delegation, evidence_d_exports as evidence, extractTokenUpdatesFromCharterAsset, factory_d_exports as factory, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, iconToNftDisplay, indexes, isProposerSponsoredDepositAllowed, isTokenCharterAsset, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, migrateTokensToCharterAssets, normalizeLegacyTokenStateForUpdate, parseNonceBn, recordRollupDeposit, recordRollupWithdraw, resolveCharterMoniker, rollup_d_exports as rollup, rollup_block_d_exports as rollupBlock, sanitizeTokenSvg, stake_d_exports as stake, syncCharterAssetWithToken, syncTokenCharterOwnership, tables, toTokenCharterAssetAddress, token_d_exports as token, token_factory_d_exports as tokenFactory, tryDeriveProtobufTokenAddress, tx_d_exports as tx, websiteToNftEndpoint };
|
package/lib/states/blacklist.cjs
CHANGED
|
@@ -61,9 +61,10 @@ var Blacklist = class {
|
|
|
61
61
|
}
|
|
62
62
|
dump() {
|
|
63
63
|
try {
|
|
64
|
+
if (!this.dumpPath) return;
|
|
64
65
|
const exported = this.filter.saveAsJSON();
|
|
65
|
-
const tmpFile = `${this.dumpPath}
|
|
66
|
-
node_fs.default.writeFileSync(tmpFile, JSON.stringify(exported));
|
|
66
|
+
const tmpFile = `${this.dumpPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
67
|
+
node_fs.default.writeFileSync(tmpFile, JSON.stringify(exported), { mode: 384 });
|
|
67
68
|
node_fs.default.renameSync(tmpFile, this.dumpPath);
|
|
68
69
|
} catch (_err) {}
|
|
69
70
|
}
|
package/lib/states/chain.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_contexts_state = require('../contexts/state.cjs');
|
|
3
|
+
let _ocap_util = require("@ocap/util");
|
|
3
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
5
|
let lodash_pick = require("lodash/pick");
|
|
5
6
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
7
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
6
8
|
let lodash_get = require("lodash/get");
|
|
7
9
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
8
10
|
let lodash_isEqual = require("lodash/isEqual");
|
|
@@ -11,8 +13,35 @@ lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
|
11
13
|
//#region src/states/chain.ts
|
|
12
14
|
var chain_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
13
15
|
create: () => create,
|
|
16
|
+
tryDeriveProtobufTokenAddress: () => tryDeriveProtobufTokenAddress,
|
|
14
17
|
update: () => update
|
|
15
18
|
});
|
|
19
|
+
/**
|
|
20
|
+
* Pure helper mirroring `Config.genTokenItx` (`core/config/src/index.ts`) byte-for-byte (#1811).
|
|
21
|
+
* Returns `null` when `token` or `issuer` is incomplete (e.g., partial unit-test mocks).
|
|
22
|
+
*/
|
|
23
|
+
const tryDeriveProtobufTokenAddress = (token, issuer) => {
|
|
24
|
+
try {
|
|
25
|
+
if (!token || typeof token !== "object" || typeof issuer !== "string" || !issuer.trim()) return null;
|
|
26
|
+
if (typeof token.name !== "string" || typeof token.description !== "string" || typeof token.symbol !== "string" || typeof token.unit !== "string" || typeof token.decimal !== "number" || !Number.isFinite(token.decimal) || token.totalSupply === void 0 || token.totalSupply === null || token.totalSupply === "") return null;
|
|
27
|
+
const totalSupply = (0, _ocap_util.fromTokenToUnit)(token.totalSupply, token.decimal).toString();
|
|
28
|
+
const initialSupply = (0, _ocap_util.fromTokenToUnit)(token.initialSupply !== void 0 && token.initialSupply !== null && token.initialSupply !== "" ? token.initialSupply : token.totalSupply, token.decimal).toString();
|
|
29
|
+
const derived = (0, _arcblock_did_util.toTokenAddress)({
|
|
30
|
+
name: token.name,
|
|
31
|
+
description: token.description,
|
|
32
|
+
symbol: token.symbol,
|
|
33
|
+
unit: token.unit,
|
|
34
|
+
decimal: token.decimal,
|
|
35
|
+
totalSupply,
|
|
36
|
+
initialSupply,
|
|
37
|
+
issuer,
|
|
38
|
+
foreignToken: token.foreignToken ?? void 0
|
|
39
|
+
}, "protobuf");
|
|
40
|
+
return typeof derived === "string" && derived ? derived : null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
16
45
|
const create = (attrs, contextArg) => {
|
|
17
46
|
return {
|
|
18
47
|
context: require_contexts_state.create({
|
|
@@ -31,6 +60,17 @@ const create = (attrs, contextArg) => {
|
|
|
31
60
|
])
|
|
32
61
|
};
|
|
33
62
|
};
|
|
63
|
+
const normalizeForeignTokenForCompare = (value) => {
|
|
64
|
+
if (!value || typeof value !== "object") return value;
|
|
65
|
+
const ft = value;
|
|
66
|
+
const chainType = typeof ft.chainType === "string" ? ft.chainType.toLowerCase() : "";
|
|
67
|
+
const contractAddress = ft.contractAddress;
|
|
68
|
+
if (chainType !== "ocap" && chainType !== "abt" && typeof contractAddress === "string" && /^0x[0-9a-fA-F]{40}$/.test(contractAddress)) return {
|
|
69
|
+
...ft,
|
|
70
|
+
contractAddress: contractAddress.toLowerCase()
|
|
71
|
+
};
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
34
74
|
const update = (state, updates) => {
|
|
35
75
|
const immutableAttrs = [
|
|
36
76
|
"chainId",
|
|
@@ -38,8 +78,16 @@ const update = (state, updates) => {
|
|
|
38
78
|
"token.symbol",
|
|
39
79
|
"token.decimal"
|
|
40
80
|
];
|
|
41
|
-
if (
|
|
42
|
-
|
|
81
|
+
if (state.token?.address) immutableAttrs.push("token.address");
|
|
82
|
+
const moderatorAddr = state.moderator && typeof state.moderator === "object" ? state.moderator.address : void 0;
|
|
83
|
+
const derivedFromState = tryDeriveProtobufTokenAddress(state.token, moderatorAddr);
|
|
84
|
+
if (!(Boolean(process.env.CHAIN_TOKEN_ADDRESS) || Boolean(state.token?.address) && derivedFromState !== null && state.token.address !== derivedFromState)) immutableAttrs.push("token.name", "token.description", "token.unit", "token.totalSupply", "token.initialSupply", "token.foreignToken");
|
|
85
|
+
for (const attr of immutableAttrs) {
|
|
86
|
+
const updatedAttr = (0, lodash_get.default)(updates, attr);
|
|
87
|
+
if (attr === "token.address" ? updatedAttr === void 0 : !updatedAttr) continue;
|
|
88
|
+
const currentAttr = (0, lodash_get.default)(state, attr);
|
|
89
|
+
if (!(attr === "token.foreignToken" ? (0, lodash_isEqual.default)(normalizeForeignTokenForCompare(updatedAttr), normalizeForeignTokenForCompare(currentAttr)) : (0, lodash_isEqual.default)(updatedAttr, currentAttr))) throw new _ocap_util_lib_error.CustomError("FORBIDDEN", `Cannot update ${attr} field on chain state`);
|
|
90
|
+
}
|
|
43
91
|
const context = { txTime: updates?.context?.txTime || (/* @__PURE__ */ new Date()).toISOString() };
|
|
44
92
|
return {
|
|
45
93
|
...state,
|
|
@@ -62,4 +110,5 @@ Object.defineProperty(exports, 'chain_exports', {
|
|
|
62
110
|
}
|
|
63
111
|
});
|
|
64
112
|
exports.create = create;
|
|
113
|
+
exports.tryDeriveProtobufTokenAddress = tryDeriveProtobufTokenAddress;
|
|
65
114
|
exports.update = update;
|
package/lib/states/chain.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { StateContext } from "../contexts/state.cjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/states/chain.d.ts
|
|
4
4
|
declare namespace chain_d_exports {
|
|
5
|
-
export { ChainState, create, update };
|
|
5
|
+
export { ChainState, create, tryDeriveProtobufTokenAddress, update };
|
|
6
6
|
}
|
|
7
7
|
interface ChainState {
|
|
8
8
|
address?: string;
|
|
@@ -12,18 +12,24 @@ interface ChainState {
|
|
|
12
12
|
moderator?: unknown;
|
|
13
13
|
accounts?: unknown;
|
|
14
14
|
token?: {
|
|
15
|
+
address?: string;
|
|
15
16
|
symbol?: string;
|
|
16
17
|
decimal?: number;
|
|
17
18
|
name?: string;
|
|
18
19
|
description?: string;
|
|
19
20
|
unit?: string;
|
|
20
|
-
totalSupply?: string;
|
|
21
|
-
initialSupply?: string;
|
|
21
|
+
totalSupply?: string | number;
|
|
22
|
+
initialSupply?: string | number;
|
|
22
23
|
foreignToken?: unknown;
|
|
23
24
|
};
|
|
24
25
|
vaults?: unknown;
|
|
25
26
|
context: StateContext;
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Pure helper mirroring `Config.genTokenItx` (`core/config/src/index.ts`) byte-for-byte (#1811).
|
|
30
|
+
* Returns `null` when `token` or `issuer` is incomplete (e.g., partial unit-test mocks).
|
|
31
|
+
*/
|
|
32
|
+
declare const tryDeriveProtobufTokenAddress: (token: ChainState["token"] | undefined, issuer: string | undefined) => string | null;
|
|
27
33
|
declare const create: (attrs: Partial<ChainState> & {
|
|
28
34
|
context?: {
|
|
29
35
|
txTime?: string;
|
|
@@ -35,4 +41,4 @@ declare const create: (attrs: Partial<ChainState> & {
|
|
|
35
41
|
}) => ChainState;
|
|
36
42
|
declare const update: (state: ChainState, updates: Partial<ChainState>) => ChainState;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { ChainState, chain_d_exports, create, update };
|
|
44
|
+
export { ChainState, chain_d_exports, create, tryDeriveProtobufTokenAddress, update };
|
package/lib/states/evidence.cjs
CHANGED
|
@@ -13,7 +13,11 @@ var evidence_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
|
13
13
|
validate: () => validate
|
|
14
14
|
});
|
|
15
15
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
16
|
-
hash: _arcblock_validator.v.union([
|
|
16
|
+
hash: _arcblock_validator.v.union([
|
|
17
|
+
_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)),
|
|
18
|
+
_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_ocap_mcrypto.BRIDGE_RELEASE_KEY_PATTERN)),
|
|
19
|
+
_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_ocap_mcrypto.BRIDGE_GOV_KEY_PATTERN))
|
|
20
|
+
]),
|
|
17
21
|
context: _arcblock_validator.schemas.context,
|
|
18
22
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
19
23
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
@@ -7,7 +7,7 @@ declare namespace evidence_d_exports {
|
|
|
7
7
|
export { create, schema, validate };
|
|
8
8
|
}
|
|
9
9
|
declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
10
|
-
readonly hash: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>], undefined>;
|
|
10
|
+
readonly hash: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>], undefined>;
|
|
11
11
|
readonly context: v.ObjectSchema<{
|
|
12
12
|
readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
|
|
13
13
|
readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
|
|
@@ -12,11 +12,13 @@ let _arcblock_validator = require("@arcblock/validator");
|
|
|
12
12
|
* v2 bridge rows (bridge/docs/ocap-protocols.md §v2.1): create / update / validate of a `RollupState` whose
|
|
13
13
|
* `data.value.version == 2`. Kept apart from `rollup.ts` so the v1 code path stays byte-for-byte what it was.
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
15
|
+
const ZERO_ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
16
|
+
const noSurroundingWhitespace = _arcblock_validator.v.check((s) => s === s.trim(), "Must not have leading or trailing whitespace");
|
|
17
|
+
const ethDidSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.string(), noSurroundingWhitespace, (0, _arcblock_validator.vDID)({
|
|
16
18
|
prefix: true,
|
|
17
19
|
wallet: "ethereum"
|
|
18
|
-
});
|
|
19
|
-
const ethVaultDidSchema = (0, _arcblock_validator.vDID)({ wallet: "ethereum" });
|
|
20
|
+
}));
|
|
21
|
+
const ethVaultDidSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.string(), noSurroundingWhitespace, (0, _arcblock_validator.vDID)({ wallet: "ethereum" }));
|
|
20
22
|
const isHttpOrHttpsUrl = (s) => {
|
|
21
23
|
try {
|
|
22
24
|
return ["http:", "https:"].includes(new URL(s).protocol);
|
|
@@ -40,7 +42,7 @@ const bridgeSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
40
42
|
role: "ROLE_TOKEN"
|
|
41
43
|
}),
|
|
42
44
|
contractAddress: ethDidSchema,
|
|
43
|
-
vaultAddress:
|
|
45
|
+
vaultAddress: ethVaultDidSchema,
|
|
44
46
|
migrateHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array(ethDidSchema), []),
|
|
45
47
|
vaultHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array(ethVaultDidSchema), []),
|
|
46
48
|
paused: _arcblock_validator.v.optional(_arcblock_validator.v.boolean(), false),
|
|
@@ -155,6 +157,19 @@ const validateBridge = (state) => {
|
|
|
155
157
|
require_states_rollup_v2.assertV1FieldsUnused(value, "INVALID_ROLLUP_PROPS");
|
|
156
158
|
const body = require_states_rollup_v2.getBridgeBody(value);
|
|
157
159
|
require_states_rollup_v2.validateBridgeBody(body);
|
|
160
|
+
const ethToken = require_states_rollup_v2.bareEthAddress(value.contractAddress);
|
|
161
|
+
const ethVault = require_states_rollup_v2.bareEthAddress(value.vaultAddress);
|
|
162
|
+
const ethGateway = require_states_rollup_v2.bareEthAddress(body.gateway);
|
|
163
|
+
if (ethToken === ZERO_ETH_ADDRESS || ethToken === ethGateway) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "contractAddress must be a non-zero ethereum token address distinct from gateway");
|
|
164
|
+
if (ethVault === ZERO_ETH_ADDRESS || ethVault === ethToken || ethVault === ethGateway) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "vaultAddress must be a non-zero ethereum address distinct from contractAddress and gateway");
|
|
165
|
+
if (body.evmGovernance && body.evmGovernance.vaultSignerManager === null) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "evmGovernance.vaultSignerManager is required when vaultAddress is configured");
|
|
166
|
+
const seenVaults = new Set([ethVault]);
|
|
167
|
+
for (const h of value.vaultHistory || []) {
|
|
168
|
+
const eh = require_states_rollup_v2.bareEthAddress(h);
|
|
169
|
+
if (eh === ZERO_ETH_ADDRESS || eh === ethToken || eh === ethGateway) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "vaultHistory entries must be non-zero ethereum addresses distinct from contractAddress and gateway");
|
|
170
|
+
if (seenVaults.has(eh)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "vaultHistory must not repeat vaultAddress or prior history entries");
|
|
171
|
+
seenVaults.add(eh);
|
|
172
|
+
}
|
|
158
173
|
if (body.pendingOwner) validateBridge(require_states_rollup_v2.materializeBridgeAt(value, body.pendingOwner.effectiveAt));
|
|
159
174
|
if (value.seedValidators.length !== 1 || value.seedValidators[0].address.toLowerCase() !== body.owner.toLowerCase()) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "seed_validators must be the bridge owner alone");
|
|
160
175
|
if (value.paused === false && body.lonePause !== null) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "lonePause requires paused");
|