@ocap/tx-protocols 1.31.1 → 1.31.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/esm/bridge-release-crypto.d.mts +39 -0
- package/esm/bridge-release-crypto.mjs +88 -0
- package/esm/bridge-release-window.d.mts +47 -0
- package/esm/bridge-release-window.mjs +62 -0
- package/esm/bridge-reserve.d.mts +24 -0
- package/esm/bridge-reserve.mjs +41 -0
- package/esm/execute.d.mts +1 -1
- package/esm/execute.mjs +58 -5
- package/esm/gas-security-guard.d.mts +6 -2
- package/esm/gas-security-guard.mjs +16 -9
- package/esm/index.d.mts +37 -18
- package/esm/index.mjs +6 -2
- package/esm/pipes/ensure-cost.mjs +7 -1
- package/esm/pipes/write-ledger.d.mts +2 -2
- package/esm/pipes/write-ledger.mjs +6 -3
- package/esm/protocols/account/delegate.mjs +6 -4
- package/esm/protocols/account/migrate.mjs +5 -3
- package/esm/protocols/account/revoke-delegate.mjs +5 -3
- package/esm/protocols/asset/acquire-v2.mjs +3 -1
- package/esm/protocols/asset/acquire-v3.mjs +4 -2
- package/esm/protocols/asset/consume.mjs +3 -1
- package/esm/protocols/asset/create.mjs +4 -2
- package/esm/protocols/asset/mint.mjs +4 -2
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +1 -1
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +1 -1
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +1 -1
- package/esm/protocols/asset/update.mjs +4 -2
- package/esm/protocols/bridge/release.d.mts +34 -0
- package/esm/protocols/bridge/release.mjs +385 -0
- package/esm/protocols/factory/create.mjs +4 -2
- package/esm/protocols/governance/claim-stake.mjs +4 -2
- package/esm/protocols/governance/return-stake.mjs +4 -2
- package/esm/protocols/governance/revoke-ledger.mjs +1 -1
- package/esm/protocols/governance/revoke-stake.d.mts +7 -2
- package/esm/protocols/governance/revoke-stake.mjs +49 -28
- package/esm/protocols/governance/slash-stake.mjs +5 -3
- package/esm/protocols/governance/stake.mjs +6 -4
- package/esm/protocols/rollup/bridge-create.d.mts +13 -0
- package/esm/protocols/rollup/bridge-create.mjs +206 -0
- package/esm/protocols/rollup/bridge-membership.d.mts +10 -0
- package/esm/protocols/rollup/bridge-membership.mjs +154 -0
- package/esm/protocols/rollup/bridge-migrate.d.mts +10 -0
- package/esm/protocols/rollup/bridge-migrate.mjs +208 -0
- package/esm/protocols/rollup/bridge-v2.d.mts +113 -0
- package/esm/protocols/rollup/bridge-v2.mjs +219 -0
- package/esm/protocols/rollup/claim-reward.mjs +4 -2
- package/esm/protocols/rollup/close.d.mts +2 -1
- package/esm/protocols/rollup/close.mjs +59 -6
- package/esm/protocols/rollup/create-block.mjs +4 -2
- package/esm/protocols/rollup/create.d.mts +3 -0
- package/esm/protocols/rollup/create.mjs +45 -6
- package/esm/protocols/rollup/join.d.mts +2 -1
- package/esm/protocols/rollup/join.mjs +31 -23
- package/esm/protocols/rollup/leave.d.mts +2 -1
- package/esm/protocols/rollup/leave.mjs +32 -24
- package/esm/protocols/rollup/migrate.d.mts +2 -1
- package/esm/protocols/rollup/migrate.mjs +19 -10
- package/esm/protocols/rollup/pause.d.mts +4 -1
- package/esm/protocols/rollup/pause.mjs +50 -6
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +2 -2
- package/esm/protocols/rollup/resume.d.mts +2 -1
- package/esm/protocols/rollup/resume.mjs +26 -6
- package/esm/protocols/rollup/update.d.mts +5 -1
- package/esm/protocols/rollup/update.mjs +56 -9
- package/esm/protocols/token/create.mjs +4 -2
- package/esm/protocols/token/deposit-v2.mjs +5 -3
- package/esm/protocols/token/withdraw-v2.mjs +5 -3
- package/esm/protocols/token-factory/burn.mjs +4 -2
- package/esm/protocols/token-factory/create.mjs +8 -4
- package/esm/protocols/token-factory/mint.mjs +4 -2
- package/esm/protocols/token-factory/update.mjs +20 -5
- package/esm/protocols/trade/exchange-v2.d.mts +5 -1
- package/esm/protocols/trade/exchange-v2.mjs +89 -4
- package/esm/protocols/trade/transfer-v2.mjs +15 -4
- package/esm/protocols/trade/transfer-v3.mjs +5 -3
- package/esm/stateless-prefix.d.mts +16 -0
- package/esm/stateless-prefix.mjs +82 -0
- package/esm/tx-timer.d.mts +1 -1
- package/esm/tx-timer.mjs +1 -1
- package/esm/util.mjs +2 -2
- package/lib/bridge-release-crypto.cjs +93 -0
- package/lib/bridge-release-crypto.d.cts +39 -0
- package/lib/bridge-release-window.cjs +69 -0
- package/lib/bridge-release-window.d.cts +47 -0
- package/lib/bridge-reserve.cjs +45 -0
- package/lib/bridge-reserve.d.cts +24 -0
- package/lib/execute.cjs +58 -5
- package/lib/gas-security-guard.cjs +16 -9
- package/lib/gas-security-guard.d.cts +6 -2
- package/lib/index.cjs +8 -1
- package/lib/index.d.cts +36 -17
- package/lib/pipes/ensure-cost.cjs +7 -1
- package/lib/pipes/write-ledger.cjs +6 -3
- package/lib/pipes/write-ledger.d.cts +2 -2
- package/lib/protocols/account/delegate.cjs +6 -4
- package/lib/protocols/account/migrate.cjs +5 -3
- package/lib/protocols/account/revoke-delegate.cjs +5 -3
- package/lib/protocols/asset/acquire-v2.cjs +3 -1
- package/lib/protocols/asset/acquire-v3.cjs +4 -2
- package/lib/protocols/asset/consume.cjs +3 -1
- package/lib/protocols/asset/create.cjs +4 -2
- package/lib/protocols/asset/mint.cjs +4 -2
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +1 -1
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +1 -1
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +1 -1
- package/lib/protocols/asset/update.cjs +4 -2
- package/lib/protocols/bridge/release.cjs +390 -0
- package/lib/protocols/bridge/release.d.cts +34 -0
- package/lib/protocols/factory/create.cjs +4 -2
- package/lib/protocols/governance/claim-stake.cjs +4 -2
- package/lib/protocols/governance/return-stake.cjs +4 -2
- package/lib/protocols/governance/revoke-ledger.cjs +1 -1
- package/lib/protocols/governance/revoke-stake.cjs +49 -28
- package/lib/protocols/governance/revoke-stake.d.cts +7 -2
- package/lib/protocols/governance/slash-stake.cjs +5 -3
- package/lib/protocols/governance/stake.cjs +6 -4
- package/lib/protocols/rollup/bridge-create.cjs +209 -0
- package/lib/protocols/rollup/bridge-create.d.cts +13 -0
- package/lib/protocols/rollup/bridge-membership.cjs +157 -0
- package/lib/protocols/rollup/bridge-membership.d.cts +10 -0
- package/lib/protocols/rollup/bridge-migrate.cjs +212 -0
- package/lib/protocols/rollup/bridge-migrate.d.cts +10 -0
- package/lib/protocols/rollup/bridge-v2.cjs +244 -0
- package/lib/protocols/rollup/bridge-v2.d.cts +113 -0
- package/lib/protocols/rollup/claim-reward.cjs +4 -2
- package/lib/protocols/rollup/close.cjs +59 -6
- package/lib/protocols/rollup/close.d.cts +2 -1
- package/lib/protocols/rollup/create-block.cjs +4 -2
- package/lib/protocols/rollup/create.cjs +45 -6
- package/lib/protocols/rollup/create.d.cts +3 -0
- package/lib/protocols/rollup/join.cjs +31 -23
- package/lib/protocols/rollup/join.d.cts +2 -1
- package/lib/protocols/rollup/leave.cjs +32 -24
- package/lib/protocols/rollup/leave.d.cts +2 -1
- package/lib/protocols/rollup/migrate.cjs +19 -10
- package/lib/protocols/rollup/migrate.d.cts +2 -1
- package/lib/protocols/rollup/pause.cjs +50 -6
- package/lib/protocols/rollup/pause.d.cts +4 -1
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +2 -2
- package/lib/protocols/rollup/resume.cjs +26 -6
- package/lib/protocols/rollup/resume.d.cts +2 -1
- package/lib/protocols/rollup/update.cjs +56 -9
- package/lib/protocols/rollup/update.d.cts +5 -1
- package/lib/protocols/token/create.cjs +4 -2
- package/lib/protocols/token/deposit-v2.cjs +5 -3
- package/lib/protocols/token/withdraw-v2.cjs +5 -3
- package/lib/protocols/token-factory/burn.cjs +4 -2
- package/lib/protocols/token-factory/create.cjs +8 -4
- package/lib/protocols/token-factory/mint.cjs +4 -2
- package/lib/protocols/token-factory/update.cjs +20 -5
- package/lib/protocols/trade/exchange-v2.cjs +90 -3
- package/lib/protocols/trade/exchange-v2.d.cts +5 -1
- package/lib/protocols/trade/transfer-v2.cjs +15 -4
- package/lib/protocols/trade/transfer-v3.cjs +5 -3
- package/lib/stateless-prefix.cjs +88 -0
- package/lib/stateless-prefix.d.cts +16 -0
- package/lib/tx-timer.cjs +1 -1
- package/lib/tx-timer.d.cts +1 -1
- package/lib/util.cjs +2 -2
- package/package.json +16 -16
- package/tools/fixtures.ts +9 -4
package/esm/tx-timer.d.mts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* - FAILED txs without persistence stop after the protocol error.
|
|
20
20
|
* - PERSISTED_FAILED txs go through gas-charge runAsLambda and produce a second set.
|
|
21
21
|
*/
|
|
22
|
-
declare const STAGE_LABELS: readonly ["queueWait", "decode", "verify", "lockWait", "
|
|
22
|
+
declare const STAGE_LABELS: readonly ["queueWait", "decode", "verify", "lockWait", "protocolRead", "protocolWrite", "protocolDiff", "ledger", "txstate", "commit", "indexdb"];
|
|
23
23
|
type StageLabel = (typeof STAGE_LABELS)[number];
|
|
24
24
|
declare const COUNTER_NAMES: readonly ["stateReads", "stateWrites", "tokenWrites", "indexEvents"];
|
|
25
25
|
type CounterName = (typeof COUNTER_NAMES)[number];
|
package/esm/tx-timer.mjs
CHANGED
package/esm/util.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { toStakeAddress } from "@arcblock/did-util";
|
|
2
|
-
import { BN, fromTokenToUnit } from "@ocap/util";
|
|
3
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
2
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
3
|
+
import { toStakeAddress } from "@arcblock/did-util";
|
|
4
|
+
import { BN, fromTokenToUnit } from "@ocap/util";
|
|
5
5
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
6
6
|
import { decodeAny } from "@ocap/message";
|
|
7
7
|
import flattenDeep from "lodash/flattenDeep.js";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
3
|
+
|
|
4
|
+
//#region src/bridge-release-crypto.ts
|
|
5
|
+
/**
|
|
6
|
+
* EIP-712 digests and signature recovery for `release_bridge_token` (#1466, bridge/docs/ocap-protocols.md §3).
|
|
7
|
+
*
|
|
8
|
+
* The structs mirror `@arcblock/bridge-types` (`OcapRelease`, `DepositClaim`; domain `ArcBridge` v1). The chain can
|
|
9
|
+
* not depend on that package (it is private and pulls in viem), so the encoding is re-implemented here and pinned to
|
|
10
|
+
* the shared test vectors (`bridge/types/vectors/eip712.json`) by `tests/bridge-release-crypto.spec.ts`.
|
|
11
|
+
*/
|
|
12
|
+
const DOMAIN_NAME = "ArcBridge";
|
|
13
|
+
const DOMAIN_VERSION = "1";
|
|
14
|
+
const keccak = (data) => Buffer.from(_ocap_mcrypto.Hasher.Keccak.hash256(data, 1, "Uint8Array"));
|
|
15
|
+
const keccakText = (text) => keccak(Buffer.from(text, "utf8"));
|
|
16
|
+
const TYPEHASH_DOMAIN = keccakText("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
|
|
17
|
+
const TYPEHASH_RELEASE = keccakText("OcapRelease(uint8 kind,bytes32 evidence,uint32 ordinal,string ocapChainId,string bridge,string to,uint256 amount,uint64 epoch,address ethSender)");
|
|
18
|
+
const TYPEHASH_CLAIM = keccakText("DepositClaim(bytes32 ethTxHash,string ocapChainId,string recipient,uint256 amount)");
|
|
19
|
+
const UINT256_MAX = (1n << 256n) - 1n;
|
|
20
|
+
const word = (value) => {
|
|
21
|
+
if (value < 0n || value > UINT256_MAX) throw new Error("uint256 out of range");
|
|
22
|
+
return Buffer.from(value.toString(16).padStart(64, "0"), "hex");
|
|
23
|
+
};
|
|
24
|
+
const addressWord = (address) => {
|
|
25
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) throw new Error("invalid address");
|
|
26
|
+
return Buffer.concat([Buffer.alloc(12), Buffer.from(address.slice(2), "hex")]);
|
|
27
|
+
};
|
|
28
|
+
const bytes32 = (hex) => {
|
|
29
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(hex)) throw new Error("invalid bytes32");
|
|
30
|
+
return Buffer.from(hex.slice(2), "hex");
|
|
31
|
+
};
|
|
32
|
+
const domainSeparator = ({ ethChainId, gateway }) => keccak(Buffer.concat([
|
|
33
|
+
TYPEHASH_DOMAIN,
|
|
34
|
+
keccakText(DOMAIN_NAME),
|
|
35
|
+
keccakText(DOMAIN_VERSION),
|
|
36
|
+
word(BigInt(ethChainId)),
|
|
37
|
+
addressWord(gateway)
|
|
38
|
+
]));
|
|
39
|
+
const toDigest = (domain, structHash) => `0x${keccak(Buffer.concat([
|
|
40
|
+
Buffer.from([25, 1]),
|
|
41
|
+
domainSeparator(domain),
|
|
42
|
+
structHash
|
|
43
|
+
])).toString("hex")}`;
|
|
44
|
+
const ZERO_ETH_ADDRESS = `0x${"0".repeat(40)}`;
|
|
45
|
+
/** EIP-712 digest validators sign for a release. */
|
|
46
|
+
function getOcapReleaseDigest(domain, m) {
|
|
47
|
+
return toDigest(domain, keccak(Buffer.concat([
|
|
48
|
+
TYPEHASH_RELEASE,
|
|
49
|
+
word(BigInt(m.kind)),
|
|
50
|
+
bytes32(m.evidence),
|
|
51
|
+
word(BigInt(m.ordinal)),
|
|
52
|
+
keccakText(m.ocapChainId),
|
|
53
|
+
keccakText(m.bridge),
|
|
54
|
+
keccakText(m.to),
|
|
55
|
+
word(BigInt(m.amount)),
|
|
56
|
+
word(BigInt(m.epoch)),
|
|
57
|
+
addressWord(m.ethSender)
|
|
58
|
+
])));
|
|
59
|
+
}
|
|
60
|
+
/** EIP-712 digest the depositor signs to claim a mode-B deposit. */
|
|
61
|
+
function getDepositClaimDigest(domain, m) {
|
|
62
|
+
return toDigest(domain, keccak(Buffer.concat([
|
|
63
|
+
TYPEHASH_CLAIM,
|
|
64
|
+
bytes32(m.ethTxHash),
|
|
65
|
+
keccakText(m.ocapChainId),
|
|
66
|
+
keccakText(m.recipient),
|
|
67
|
+
word(BigInt(m.amount))
|
|
68
|
+
])));
|
|
69
|
+
}
|
|
70
|
+
const SIGNATURE_PATTERN = /^0x[0-9a-fA-F]{130}$/;
|
|
71
|
+
/**
|
|
72
|
+
* Lowercase signer address of a 65-byte `r || s || v` signature over `digest`, or `null` when it is not a canonical
|
|
73
|
+
* signature: wrong length or encoding, `v` other than 27 / 28, high `s`, or no recoverable key.
|
|
74
|
+
*/
|
|
75
|
+
function recoverEthSigner(digest, signature) {
|
|
76
|
+
if (typeof signature !== "string" || !SIGNATURE_PATTERN.test(signature)) return null;
|
|
77
|
+
const v = Number.parseInt(signature.slice(130, 132), 16);
|
|
78
|
+
if (v !== 27 && v !== 28) return null;
|
|
79
|
+
try {
|
|
80
|
+
return _ocap_mcrypto.Signer.Ethereum.ethRecover(digest, signature).toLowerCase();
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Strict `0x` + 40 hex, any case. */
|
|
86
|
+
const isEthAddress = (value) => typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.ZERO_ETH_ADDRESS = ZERO_ETH_ADDRESS;
|
|
90
|
+
exports.getDepositClaimDigest = getDepositClaimDigest;
|
|
91
|
+
exports.getOcapReleaseDigest = getOcapReleaseDigest;
|
|
92
|
+
exports.isEthAddress = isEthAddress;
|
|
93
|
+
exports.recoverEthSigner = recoverEthSigner;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/bridge-release-crypto.d.ts
|
|
2
|
+
interface BridgeDomainInput {
|
|
3
|
+
/** EVM chain id, decimal string */
|
|
4
|
+
ethChainId: string;
|
|
5
|
+
/** BridgeGateway address */
|
|
6
|
+
gateway: string;
|
|
7
|
+
}
|
|
8
|
+
interface OcapReleaseMessage {
|
|
9
|
+
kind: number;
|
|
10
|
+
evidence: string;
|
|
11
|
+
ordinal: number;
|
|
12
|
+
ocapChainId: string;
|
|
13
|
+
/** OCAP bridge (RollupState) address */
|
|
14
|
+
bridge: string;
|
|
15
|
+
to: string;
|
|
16
|
+
amount: string;
|
|
17
|
+
epoch: number;
|
|
18
|
+
ethSender: string;
|
|
19
|
+
}
|
|
20
|
+
declare const ZERO_ETH_ADDRESS: string;
|
|
21
|
+
/** EIP-712 digest validators sign for a release. */
|
|
22
|
+
declare function getOcapReleaseDigest(domain: BridgeDomainInput, m: OcapReleaseMessage): string;
|
|
23
|
+
interface DepositClaimMessage {
|
|
24
|
+
ethTxHash: string;
|
|
25
|
+
ocapChainId: string;
|
|
26
|
+
recipient: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
}
|
|
29
|
+
/** EIP-712 digest the depositor signs to claim a mode-B deposit. */
|
|
30
|
+
declare function getDepositClaimDigest(domain: BridgeDomainInput, m: DepositClaimMessage): string;
|
|
31
|
+
/**
|
|
32
|
+
* Lowercase signer address of a 65-byte `r || s || v` signature over `digest`, or `null` when it is not a canonical
|
|
33
|
+
* signature: wrong length or encoding, `v` other than 27 / 28, high `s`, or no recoverable key.
|
|
34
|
+
*/
|
|
35
|
+
declare function recoverEthSigner(digest: string, signature: string): string | null;
|
|
36
|
+
/** Strict `0x` + 40 hex, any case. */
|
|
37
|
+
declare const isEthAddress: (value: unknown) => value is string;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { BridgeDomainInput, DepositClaimMessage, OcapReleaseMessage, ZERO_ETH_ADDRESS, getDepositClaimDigest, getOcapReleaseDigest, isEthAddress, recoverEthSigner };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/bridge-release-window.ts
|
|
3
|
+
/**
|
|
4
|
+
* Rolling 24 h release window (#1466, bridge/docs/ocap-protocols.md §3 check 7).
|
|
5
|
+
*
|
|
6
|
+
* One ring is 24 hourly slots. Slot `s = hour mod 24` holds `"<hourIndex>:<amountInBaseUnits>"`. The clock is the tx
|
|
7
|
+
* time, never wall time, and it never runs backwards inside a ring: `h = max(hour(txTime), max stored hourIndex)`.
|
|
8
|
+
* Pure functions, no state access, so the arithmetic is testable on its own.
|
|
9
|
+
*/
|
|
10
|
+
const HOUR_MS = 36e5;
|
|
11
|
+
const WINDOW_HOURS = 24;
|
|
12
|
+
/**
|
|
13
|
+
* How far (hours) a stored slot may be ahead of the tx hour before the release is refused. The clock of a ring never
|
|
14
|
+
* moves backwards, so a slot stamped in the far future (a node clock that ran ahead once) would otherwise be adopted
|
|
15
|
+
* for good: every later release would be judged at that hour and the window would stop following real time. Small skews
|
|
16
|
+
* (a few seconds of drift across an hour boundary, two nodes' clocks) are tolerated; beyond this the release fails
|
|
17
|
+
* closed until the tx time catches up.
|
|
18
|
+
*/
|
|
19
|
+
const MAX_RING_SKEW_HOURS = 2;
|
|
20
|
+
const SLOT_DATA_PATTERN = /^(0|[1-9]\d{0,14}):(0|[1-9]\d{0,77})$/;
|
|
21
|
+
/** Parses a stored slot. Anything but the exact canonical form is corruption and throws (the release fails closed). */
|
|
22
|
+
function parseRingSlot(data) {
|
|
23
|
+
if (typeof data !== "string") throw new Error("release window slot is not a string");
|
|
24
|
+
const match = SLOT_DATA_PATTERN.exec(data);
|
|
25
|
+
if (!match) throw new Error(`release window slot is malformed: ${String(data).slice(0, 80)}`);
|
|
26
|
+
return {
|
|
27
|
+
hourIndex: Number(match[1]),
|
|
28
|
+
amount: BigInt(match[2])
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const formatRingSlot = (slot) => `${slot.hourIndex}:${slot.amount.toString(10)}`;
|
|
32
|
+
const hourOf = (timeMs) => Math.floor(timeMs / HOUR_MS);
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates one release against a ring. `slots[i]` is the stored slot `i` (or `null` when it was never written).
|
|
35
|
+
* Does not check `allowed`: the caller rejects when it is false.
|
|
36
|
+
*/
|
|
37
|
+
function evaluateRing(slots, txTimeMs, amount, cap) {
|
|
38
|
+
const txHour = hourOf(txTimeMs);
|
|
39
|
+
let hour = txHour;
|
|
40
|
+
for (const slot of slots) if (slot && slot.hourIndex > hour) hour = slot.hourIndex;
|
|
41
|
+
let used = 0n;
|
|
42
|
+
for (const slot of slots) if (slot && hour - WINDOW_HOURS < slot.hourIndex && slot.hourIndex <= hour) used += slot.amount;
|
|
43
|
+
const index = hour % WINDOW_HOURS;
|
|
44
|
+
const current = slots[index] ?? null;
|
|
45
|
+
const next = current && current.hourIndex === hour ? {
|
|
46
|
+
hourIndex: hour,
|
|
47
|
+
amount: current.amount + amount
|
|
48
|
+
} : {
|
|
49
|
+
hourIndex: hour,
|
|
50
|
+
amount
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
hour,
|
|
54
|
+
slot: index,
|
|
55
|
+
skew: hour - txHour,
|
|
56
|
+
used,
|
|
57
|
+
allowed: used + amount <= cap,
|
|
58
|
+
next
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.HOUR_MS = HOUR_MS;
|
|
64
|
+
exports.MAX_RING_SKEW_HOURS = MAX_RING_SKEW_HOURS;
|
|
65
|
+
exports.WINDOW_HOURS = WINDOW_HOURS;
|
|
66
|
+
exports.evaluateRing = evaluateRing;
|
|
67
|
+
exports.formatRingSlot = formatRingSlot;
|
|
68
|
+
exports.hourOf = hourOf;
|
|
69
|
+
exports.parseRingSlot = parseRingSlot;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/bridge-release-window.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rolling 24 h release window (#1466, bridge/docs/ocap-protocols.md §3 check 7).
|
|
4
|
+
*
|
|
5
|
+
* One ring is 24 hourly slots. Slot `s = hour mod 24` holds `"<hourIndex>:<amountInBaseUnits>"`. The clock is the tx
|
|
6
|
+
* time, never wall time, and it never runs backwards inside a ring: `h = max(hour(txTime), max stored hourIndex)`.
|
|
7
|
+
* Pure functions, no state access, so the arithmetic is testable on its own.
|
|
8
|
+
*/
|
|
9
|
+
declare const HOUR_MS = 3600000;
|
|
10
|
+
declare const WINDOW_HOURS = 24;
|
|
11
|
+
/**
|
|
12
|
+
* How far (hours) a stored slot may be ahead of the tx hour before the release is refused. The clock of a ring never
|
|
13
|
+
* moves backwards, so a slot stamped in the far future (a node clock that ran ahead once) would otherwise be adopted
|
|
14
|
+
* for good: every later release would be judged at that hour and the window would stop following real time. Small skews
|
|
15
|
+
* (a few seconds of drift across an hour boundary, two nodes' clocks) are tolerated; beyond this the release fails
|
|
16
|
+
* closed until the tx time catches up.
|
|
17
|
+
*/
|
|
18
|
+
declare const MAX_RING_SKEW_HOURS = 2;
|
|
19
|
+
interface RingSlot {
|
|
20
|
+
hourIndex: number;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
}
|
|
23
|
+
/** Parses a stored slot. Anything but the exact canonical form is corruption and throws (the release fails closed). */
|
|
24
|
+
declare function parseRingSlot(data: unknown): RingSlot;
|
|
25
|
+
declare const formatRingSlot: (slot: RingSlot) => string;
|
|
26
|
+
declare const hourOf: (timeMs: number) => number;
|
|
27
|
+
interface RingEvaluation {
|
|
28
|
+
/** the clock after this release: `max(hour(txTime), max stored hourIndex)` */
|
|
29
|
+
hour: number;
|
|
30
|
+
/** slot to write: `hour mod 24` */
|
|
31
|
+
slot: number;
|
|
32
|
+
/** sum of the slots inside the window `hour - 24 < hourIndex <= hour`, before this release */
|
|
33
|
+
used: bigint;
|
|
34
|
+
/** hours the newest stored slot is ahead of the tx hour (0 when it is not) */
|
|
35
|
+
skew: number;
|
|
36
|
+
/** whether `used + amount <= cap` */
|
|
37
|
+
allowed: boolean;
|
|
38
|
+
/** what the slot must hold after this release */
|
|
39
|
+
next: RingSlot;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Evaluates one release against a ring. `slots[i]` is the stored slot `i` (or `null` when it was never written).
|
|
43
|
+
* Does not check `allowed`: the caller rejects when it is false.
|
|
44
|
+
*/
|
|
45
|
+
declare function evaluateRing(slots: ReadonlyArray<RingSlot | null>, txTimeMs: number, amount: bigint, cap: bigint): RingEvaluation;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { HOUR_MS, MAX_RING_SKEW_HOURS, RingEvaluation, RingSlot, WINDOW_HOURS, evaluateRing, formatRingSlot, hourOf, parseRingSlot };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
|
+
|
|
6
|
+
//#region src/bridge-reserve.ts
|
|
7
|
+
/**
|
|
8
|
+
* Early rejection (R5) of a bridge reserve as an acting party (#1464, #1505, bridge/docs/ocap-protocols.md §1, §v2.3).
|
|
9
|
+
*
|
|
10
|
+
* A reserve is every account with the `ROLE_BRIDGE_RESERVE` DID role (one per bridge, derived, keyless). The role is
|
|
11
|
+
* read from the address itself, so no config and no state lookup is needed, and a crafted role-25 address that maps to
|
|
12
|
+
* no bridge is refused as well. The reserve must never be sender, delegator, multisig signer or gas sponsor.
|
|
13
|
+
* The checks are defence in depth for the paths that spend an account's balance before the post-execution invariant
|
|
14
|
+
* gate is installed (gas, paymaster), and for any future signature scheme.
|
|
15
|
+
* Pure function of the tx: no state, no counters.
|
|
16
|
+
*/
|
|
17
|
+
const BRIDGE_RESERVE_ACTOR_FORBIDDEN = "BRIDGE_RESERVE_ACTOR_FORBIDDEN";
|
|
18
|
+
/** Whether `address` is a bridge reserve address (syntactic: the DID role). */
|
|
19
|
+
const isBridgeReserve = (address) => (0, _ocap_tx_pipeline.isBridgeReserveRole)(address);
|
|
20
|
+
const forbidden = (role) => new _ocap_util_lib_error.CustomError(BRIDGE_RESERVE_ACTOR_FORBIDDEN, `A bridge reserve can not act as ${role}`, { persist: false });
|
|
21
|
+
function assertBridgeReserveNotActor(context) {
|
|
22
|
+
const { tx } = context;
|
|
23
|
+
if (!tx) return;
|
|
24
|
+
if (isBridgeReserve(tx.from)) throw forbidden("transaction sender");
|
|
25
|
+
if (isBridgeReserve(tx.delegator)) throw forbidden("delegator");
|
|
26
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures") || [];
|
|
27
|
+
for (const sig of signatures) {
|
|
28
|
+
if (isBridgeReserve(sig?.signer)) throw forbidden("multisig signer");
|
|
29
|
+
if (isBridgeReserve(sig?.delegator)) throw forbidden("multisig delegator");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Paymaster / gas sponsor. The sponsor header is not covered by the tx signature, so the failure strikes nobody. */
|
|
33
|
+
function assertBridgeReserveNotSponsor(sponsorAddress) {
|
|
34
|
+
if (isBridgeReserve(sponsorAddress)) {
|
|
35
|
+
const err = forbidden("gas sponsor");
|
|
36
|
+
err._unauthenticatedExtraFailure = true;
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.BRIDGE_RESERVE_ACTOR_FORBIDDEN = BRIDGE_RESERVE_ACTOR_FORBIDDEN;
|
|
43
|
+
exports.assertBridgeReserveNotActor = assertBridgeReserveNotActor;
|
|
44
|
+
exports.assertBridgeReserveNotSponsor = assertBridgeReserveNotSponsor;
|
|
45
|
+
exports.isBridgeReserve = isBridgeReserve;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/bridge-reserve.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Early rejection (R5) of a bridge reserve as an acting party (#1464, #1505, bridge/docs/ocap-protocols.md §1, §v2.3).
|
|
4
|
+
*
|
|
5
|
+
* A reserve is every account with the `ROLE_BRIDGE_RESERVE` DID role (one per bridge, derived, keyless). The role is
|
|
6
|
+
* read from the address itself, so no config and no state lookup is needed, and a crafted role-25 address that maps to
|
|
7
|
+
* no bridge is refused as well. The reserve must never be sender, delegator, multisig signer or gas sponsor.
|
|
8
|
+
* The checks are defence in depth for the paths that spend an account's balance before the post-execution invariant
|
|
9
|
+
* gate is installed (gas, paymaster), and for any future signature scheme.
|
|
10
|
+
* Pure function of the tx: no state, no counters.
|
|
11
|
+
*/
|
|
12
|
+
declare const BRIDGE_RESERVE_ACTOR_FORBIDDEN = "BRIDGE_RESERVE_ACTOR_FORBIDDEN";
|
|
13
|
+
/** Whether `address` is a bridge reserve address (syntactic: the DID role). */
|
|
14
|
+
declare const isBridgeReserve: (address: unknown) => boolean;
|
|
15
|
+
declare function assertBridgeReserveNotActor(context: {
|
|
16
|
+
tx?: {
|
|
17
|
+
from?: string;
|
|
18
|
+
delegator?: string;
|
|
19
|
+
} | null;
|
|
20
|
+
}): void;
|
|
21
|
+
/** Paymaster / gas sponsor. The sponsor header is not covered by the tx signature, so the failure strikes nobody. */
|
|
22
|
+
declare function assertBridgeReserveNotSponsor(sponsorAddress: string): void;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { BRIDGE_RESERVE_ACTOR_FORBIDDEN, assertBridgeReserveNotActor, assertBridgeReserveNotSponsor, isBridgeReserve };
|
package/lib/execute.cjs
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_bridge_reserve = require('./bridge-reserve.cjs');
|
|
3
4
|
const require_gas_security_guard = require('./gas-security-guard.cjs');
|
|
4
5
|
const require_util = require('./util.cjs');
|
|
5
6
|
const require_pipes_ensure_cost = require('./pipes/ensure-cost.cjs');
|
|
6
7
|
const require_pipes_ensure_gas = require('./pipes/ensure-gas.cjs');
|
|
7
8
|
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
9
|
+
const require_stateless_prefix = require('./stateless-prefix.cjs');
|
|
8
10
|
const require_tx_timer = require('./tx-timer.cjs');
|
|
11
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
12
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
13
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
14
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
9
15
|
let _arcblock_did = require("@arcblock/did");
|
|
10
16
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
17
|
let _arcblock_jwt = require("@arcblock/jwt");
|
|
12
18
|
_arcblock_jwt = require_rolldown_runtime.__toESM(_arcblock_jwt);
|
|
13
|
-
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
14
19
|
let _ocap_state = require("@ocap/state");
|
|
15
|
-
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
16
20
|
let _ocap_util = require("@ocap/util");
|
|
17
|
-
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
18
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
19
21
|
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
20
22
|
let lodash_camelCase = require("lodash/camelCase");
|
|
21
23
|
lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
|
|
@@ -168,6 +170,20 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
168
170
|
resolve();
|
|
169
171
|
})).catch(reject);
|
|
170
172
|
});
|
|
173
|
+
/**
|
|
174
|
+
* Append the tx to the verifiable ledger at the point where its tx state is written (#1419).
|
|
175
|
+
*
|
|
176
|
+
* Invariant: a ledger row exists only for a tx that also gets a `statedb.tx` row, i.e. a successful tx or a
|
|
177
|
+
* failed tx that went through the failed-tx gas charge (`ensureGasFeePaid`). The append used to run in the
|
|
178
|
+
* pre-execute pipeline, ahead of the protocol runner, so every protocol-phase rejection that is not persisted
|
|
179
|
+
* (itx schema errors, `VerifyInfo` defaults, every `VerifyDelegation` rejection, multisig signature failures,
|
|
180
|
+
* a failed-tx gas charge nobody can pay) left an uncharged row in the append-only ledger.
|
|
181
|
+
*
|
|
182
|
+
* The append still precedes `statedb.tx.create` and the statedb commit, so the ledger stays write-ahead of the
|
|
183
|
+
* committed state, and `WriteLedger` is idempotent per context (`ledgerSequence`), so `runAsLambda` retries
|
|
184
|
+
* reuse the sequence allocated by the first attempt (#973).
|
|
185
|
+
*/
|
|
186
|
+
const appendLedgerEntry = (context) => runSinglePipe(require_pipes_write_ledger.WriteLedger, context);
|
|
171
187
|
const hasCommittedUnsignedTx = async (context) => {
|
|
172
188
|
if (!context.unsignedTxHash || !hasEvidenceStore(context.statedb)) return false;
|
|
173
189
|
const unsignedKey = toUnsignedEvidenceKey(context.unsignedTxHash);
|
|
@@ -489,6 +505,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
489
505
|
hdrErr._unauthenticatedExtraFailure = true;
|
|
490
506
|
throw hdrErr;
|
|
491
507
|
}
|
|
508
|
+
require_bridge_reserve.assertBridgeReserveNotSponsor(sponsorAddress);
|
|
492
509
|
let jwtVerified = false;
|
|
493
510
|
try {
|
|
494
511
|
jwtVerified = Boolean(await _arcblock_jwt.verify(token, pk, {
|
|
@@ -726,6 +743,22 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
726
743
|
if (protocolsMap && context.txType && !protocolsMap[getTxName(context.txType)]) return next(new _ocap_util_lib_error.CustomError("UNSUPPORTED_TX", `Unsupported tx type ${context.txType}`, { persist: false }));
|
|
727
744
|
return next();
|
|
728
745
|
});
|
|
746
|
+
pre.use((context, next) => {
|
|
747
|
+
try {
|
|
748
|
+
require_bridge_reserve.assertBridgeReserveNotActor(context);
|
|
749
|
+
return next();
|
|
750
|
+
} catch (err) {
|
|
751
|
+
return next(err);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
pre.use(async (context, next) => {
|
|
755
|
+
try {
|
|
756
|
+
await require_stateless_prefix.assertStatelessTxRules(context, context._protocols);
|
|
757
|
+
return next();
|
|
758
|
+
} catch (err) {
|
|
759
|
+
return next(err);
|
|
760
|
+
}
|
|
761
|
+
});
|
|
729
762
|
pre.use((context, next) => {
|
|
730
763
|
if (context._preFlightSnapshotApplied) return next();
|
|
731
764
|
return _ocap_tx_pipeline.pipes.VerifyServiceFee(context, next);
|
|
@@ -784,7 +817,6 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
784
817
|
if (!senderState) await assertNonExistentSenderAdmissible(context);
|
|
785
818
|
if (context.txHash) syncState.inFlightTxHashes.set(context.txHash, execId);
|
|
786
819
|
if (context.unsignedTxHash) syncState.inFlightUnsignedTxHashes.set(context.unsignedTxHash, execId);
|
|
787
|
-
await runSinglePipe(require_pipes_write_ledger.WriteLedger, context);
|
|
788
820
|
});
|
|
789
821
|
return next();
|
|
790
822
|
} catch (err) {
|
|
@@ -896,6 +928,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
896
928
|
let error = rawError;
|
|
897
929
|
context.timer?.mark("protocol");
|
|
898
930
|
if (!error) try {
|
|
931
|
+
await (0, _ocap_tx_pipeline.prepareBridgeReserveGate)(context);
|
|
899
932
|
(0, _ocap_tx_pipeline.inspectPostExecutionInvariants)(context);
|
|
900
933
|
} catch (invariantErr) {
|
|
901
934
|
error = invariantErr;
|
|
@@ -917,6 +950,20 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
917
950
|
await ensureGasFeePaid(context);
|
|
918
951
|
txState = states.tx.create(context, txStatus);
|
|
919
952
|
}
|
|
953
|
+
try {
|
|
954
|
+
await appendLedgerEntry(context);
|
|
955
|
+
} catch (ledgerErr) {
|
|
956
|
+
if (!error) {
|
|
957
|
+
await (0, _ocap_tx_pipeline.rollbackTrackedStateWrites)(context);
|
|
958
|
+
context.events = [];
|
|
959
|
+
}
|
|
960
|
+
context.logger?.error("Failed to append transaction to ledger", {
|
|
961
|
+
error: ledgerErr,
|
|
962
|
+
txError: error,
|
|
963
|
+
txHash: context.txHash
|
|
964
|
+
});
|
|
965
|
+
return reject(error || ledgerErr);
|
|
966
|
+
}
|
|
920
967
|
await context.statedb.tx.create(txState.hash, txState, context);
|
|
921
968
|
await recordUnsignedTxInStateDb(context, txState.hash);
|
|
922
969
|
context.timer?.mark("txstate");
|
|
@@ -985,6 +1032,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
985
1032
|
ctx.timer?.mark("lockWait");
|
|
986
1033
|
try {
|
|
987
1034
|
await execute(ctx, protocols, true);
|
|
1035
|
+
await appendLedgerEntry(ctx);
|
|
988
1036
|
} finally {
|
|
989
1037
|
if (ctx.ledgerSequence && !savedLedgerSequence) {
|
|
990
1038
|
savedLedgerSequence = ctx.ledgerSequence;
|
|
@@ -1071,6 +1119,11 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
1071
1119
|
try {
|
|
1072
1120
|
await ensureGasFeePaid(ctx);
|
|
1073
1121
|
await attachSecurityStrikeToError(err, ctx);
|
|
1122
|
+
await appendLedgerEntry(ctx);
|
|
1123
|
+
if (ctx.ledgerSequence && !savedLedgerSequence) {
|
|
1124
|
+
savedLedgerSequence = ctx.ledgerSequence;
|
|
1125
|
+
context.ledgerSequence = ctx.ledgerSequence;
|
|
1126
|
+
}
|
|
1074
1127
|
const state = getStates(context).tx.create(ctx, txStatus);
|
|
1075
1128
|
await ctx.statedb.tx.create(state.hash, state, ctx);
|
|
1076
1129
|
await recordUnsignedTxInStateDb(ctx, state.hash);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let _arcblock_did = require("@arcblock/did");
|
|
3
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
4
2
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
5
|
-
let _ocap_state = require("@ocap/state");
|
|
6
3
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
-
let _ocap_util = require("@ocap/util");
|
|
8
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
5
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
8
|
+
let _ocap_state = require("@ocap/state");
|
|
9
|
+
let _ocap_util = require("@ocap/util");
|
|
10
10
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
11
11
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
12
12
|
let node_crypto = require("node:crypto");
|
|
@@ -34,7 +34,7 @@ const MAX_FREE_VARIANTS = 2;
|
|
|
34
34
|
/**
|
|
35
35
|
* High-overhead creator, factory, token-issuance, rollup, and batch transaction types
|
|
36
36
|
* that ALWAYS require direct gas payment (`requiresDirectGas: true`) and cannot waive
|
|
37
|
-
* gas via self-staked `Stake-for-Gas
|
|
37
|
+
* gas via self-staked `Stake-for-Gas`, Unlinkable Gas Pass or a third-party sponsor's stake (#1420).
|
|
38
38
|
*/
|
|
39
39
|
const DIRECT_GAS_REQUIRED_TX_TYPES = new Set([
|
|
40
40
|
"create_token",
|
|
@@ -191,7 +191,11 @@ function getOrCreateActorRecord(reg, rawActor, nowMs, cfg) {
|
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* 3D `Stake-for-Gas` Eligibility Gate:
|
|
194
|
-
*
|
|
194
|
+
* 0. `txType` must not be in `DIRECT_GAS_REQUIRED_TX_TYPES`. This holds for every stake-based waiver: self
|
|
195
|
+
* stake, gas pass and third-party sponsor stake (#1420). Only an operator-configured
|
|
196
|
+
* `txGas.freeGasAllowedTxTypes` entry can lift it.
|
|
197
|
+
* 1. `txType` must be in `FREE_GAS_ELIGIBLE_TX_TYPES` (everyday user actions only). Third-party sponsors are
|
|
198
|
+
* exempt from this allowlist unless `enforceSponsor3DEligibility` is on.
|
|
195
199
|
* 2. `txSize` must be <= `maxFreeGasTxSize` (default 4096 bytes).
|
|
196
200
|
* 3. `stateOps` (`estimate.create + estimate.update`) must be <= `maxFreeGasStateOps` (default 6).
|
|
197
201
|
* 4. Failed transactions (`isFailedTxGasCharge === true`) NEVER waive gas.
|
|
@@ -204,13 +208,15 @@ function evaluateStakeForGasEligibility(params) {
|
|
|
204
208
|
};
|
|
205
209
|
const shortType = normalizeShortTxType(params.txType);
|
|
206
210
|
const customAllowlist = (params.config?.transaction?.txGas)?.freeGasAllowedTxTypes;
|
|
207
|
-
|
|
211
|
+
const enforceAllowlist = !params.isThirdPartySponsor || params.enforceSponsor3DEligibility === true;
|
|
212
|
+
if (shortType) {
|
|
213
|
+
const requiresDirectGas = DIRECT_GAS_REQUIRED_TX_TYPES.has(shortType);
|
|
208
214
|
if (Array.isArray(customAllowlist) && customAllowlist.length > 0) {
|
|
209
|
-
if (!customAllowlist.some((t) => normalizeShortTxType(t) === shortType || t === params.txType)) return {
|
|
215
|
+
if (!customAllowlist.some((t) => normalizeShortTxType(t) === shortType || t === params.txType) && (enforceAllowlist || requiresDirectGas)) return {
|
|
210
216
|
eligible: false,
|
|
211
217
|
reason: "TX_TYPE_REQUIRES_DIRECT_GAS"
|
|
212
218
|
};
|
|
213
|
-
} else if (
|
|
219
|
+
} else if (requiresDirectGas || enforceAllowlist && typeof params.txType === "string" && params.txType.startsWith("fg:t:") && !FREE_GAS_ELIGIBLE_TX_TYPES.has(shortType)) return {
|
|
214
220
|
eligible: false,
|
|
215
221
|
reason: "TX_TYPE_REQUIRES_DIRECT_GAS"
|
|
216
222
|
};
|
|
@@ -567,6 +573,7 @@ const BENIGN_REJECT_CODES = new Set([
|
|
|
567
573
|
"INVALID_TX_TIME",
|
|
568
574
|
"EXPIRED",
|
|
569
575
|
"TX_EXPIRED",
|
|
576
|
+
"EXPIRED_TX",
|
|
570
577
|
"NOT_FOUND",
|
|
571
578
|
"STAKE_NOT_FOUND",
|
|
572
579
|
"INVALID_LOCK_STATUS",
|
|
@@ -18,7 +18,7 @@ declare const DEFAULT_FISHERMAN_BOUNTY_BPS = 1000;
|
|
|
18
18
|
/**
|
|
19
19
|
* High-overhead creator, factory, token-issuance, rollup, and batch transaction types
|
|
20
20
|
* that ALWAYS require direct gas payment (`requiresDirectGas: true`) and cannot waive
|
|
21
|
-
* gas via self-staked `Stake-for-Gas
|
|
21
|
+
* gas via self-staked `Stake-for-Gas`, Unlinkable Gas Pass or a third-party sponsor's stake (#1420).
|
|
22
22
|
*/
|
|
23
23
|
declare const DIRECT_GAS_REQUIRED_TX_TYPES: ReadonlySet<string>;
|
|
24
24
|
/**
|
|
@@ -150,7 +150,11 @@ interface IStakeForGasEligibilityResult {
|
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* 3D `Stake-for-Gas` Eligibility Gate:
|
|
153
|
-
*
|
|
153
|
+
* 0. `txType` must not be in `DIRECT_GAS_REQUIRED_TX_TYPES`. This holds for every stake-based waiver: self
|
|
154
|
+
* stake, gas pass and third-party sponsor stake (#1420). Only an operator-configured
|
|
155
|
+
* `txGas.freeGasAllowedTxTypes` entry can lift it.
|
|
156
|
+
* 1. `txType` must be in `FREE_GAS_ELIGIBLE_TX_TYPES` (everyday user actions only). Third-party sponsors are
|
|
157
|
+
* exempt from this allowlist unless `enforceSponsor3DEligibility` is on.
|
|
154
158
|
* 2. `txSize` must be <= `maxFreeGasTxSize` (default 4096 bytes).
|
|
155
159
|
* 3. `stateOps` (`estimate.create + estimate.update`) must be <= `maxFreeGasStateOps` (default 6).
|
|
156
160
|
* 4. Failed transactions (`isFailedTxGasCharge === true`) NEVER waive gas.
|
package/lib/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_gas_security_guard = require('./gas-security-guard.cjs');
|
|
4
4
|
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
5
|
+
const require_stateless_prefix = require('./stateless-prefix.cjs');
|
|
5
6
|
const require_tx_timer = require('./tx-timer.cjs');
|
|
6
7
|
const require_execute = require('./execute.cjs');
|
|
7
8
|
const require_protocols_account_delegate = require('./protocols/account/delegate.cjs');
|
|
@@ -13,6 +14,7 @@ const require_protocols_asset_consume = require('./protocols/asset/consume.cjs')
|
|
|
13
14
|
const require_protocols_asset_create = require('./protocols/asset/create.cjs');
|
|
14
15
|
const require_protocols_asset_mint = require('./protocols/asset/mint.cjs');
|
|
15
16
|
const require_protocols_asset_update = require('./protocols/asset/update.cjs');
|
|
17
|
+
const require_protocols_bridge_release = require('./protocols/bridge/release.cjs');
|
|
16
18
|
const require_protocols_factory_create = require('./protocols/factory/create.cjs');
|
|
17
19
|
const require_protocols_governance_claim_stake = require('./protocols/governance/claim-stake.cjs');
|
|
18
20
|
const require_protocols_governance_return_stake = require('./protocols/governance/return-stake.cjs');
|
|
@@ -39,9 +41,9 @@ const require_protocols_token_withdraw_v2 = require('./protocols/token/withdraw-
|
|
|
39
41
|
const require_protocols_trade_exchange_v2 = require('./protocols/trade/exchange-v2.cjs');
|
|
40
42
|
const require_protocols_trade_transfer_v2 = require('./protocols/trade/transfer-v2.cjs');
|
|
41
43
|
const require_protocols_trade_transfer_v3 = require('./protocols/trade/transfer-v3.cjs');
|
|
44
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
42
45
|
let _ocap_state = require("@ocap/state");
|
|
43
46
|
_ocap_state = require_rolldown_runtime.__toESM(_ocap_state);
|
|
44
|
-
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
45
47
|
|
|
46
48
|
//#region src/index.ts
|
|
47
49
|
const createExecutor = ({ filter, runAsLambda }) => {
|
|
@@ -67,6 +69,7 @@ const createExecutor = ({ filter, runAsLambda }) => {
|
|
|
67
69
|
updateTokenFactory: require_protocols_token_factory_update.default,
|
|
68
70
|
mintToken: require_protocols_token_factory_mint.default,
|
|
69
71
|
burnToken: require_protocols_token_factory_burn.default,
|
|
72
|
+
releaseBridgeToken: require_protocols_bridge_release.default,
|
|
70
73
|
stake: require_protocols_governance_stake.default,
|
|
71
74
|
revokeStake: require_protocols_governance_revoke_stake.default,
|
|
72
75
|
claimStake: require_protocols_governance_claim_stake.default,
|
|
@@ -83,6 +86,7 @@ const createExecutor = ({ filter, runAsLambda }) => {
|
|
|
83
86
|
claimBlockReward: require_protocols_rollup_claim_reward.default,
|
|
84
87
|
migrateRollup: require_protocols_rollup_migrate.default
|
|
85
88
|
};
|
|
89
|
+
require_stateless_prefix.setDefaultStatelessProtocols(protocols);
|
|
86
90
|
const execute$1 = require_execute.default({
|
|
87
91
|
filter,
|
|
88
92
|
runAsLambda
|
|
@@ -172,6 +176,7 @@ Object.defineProperty(exports, 'assertRawWireEnvelope', {
|
|
|
172
176
|
return _ocap_tx_pipeline.assertRawWireEnvelope;
|
|
173
177
|
}
|
|
174
178
|
});
|
|
179
|
+
exports.assertStatelessTxRules = require_stateless_prefix.assertStatelessTxRules;
|
|
175
180
|
exports.assertTxAdmission = require_gas_security_guard.assertTxAdmission;
|
|
176
181
|
exports.classifyErrorStrikeCategory = require_gas_security_guard.classifyErrorStrikeCategory;
|
|
177
182
|
exports.computeActorTier = require_gas_security_guard.computeActorTier;
|
|
@@ -186,6 +191,7 @@ exports.executeAutoGasStakeSlash = require_gas_security_guard.executeAutoGasStak
|
|
|
186
191
|
exports.extractTransactionTargets = require_gas_security_guard.extractTransactionTargets;
|
|
187
192
|
exports.getActorSecurityStatus = require_gas_security_guard.getActorSecurityStatus;
|
|
188
193
|
exports.getGasSecurityRegistry = require_gas_security_guard.getGasSecurityRegistry;
|
|
194
|
+
exports.getStatelessPrefixLength = require_stateless_prefix.getStatelessPrefixLength;
|
|
189
195
|
exports.getTxSecurityWarningByHash = require_gas_security_guard.getTxSecurityWarningByHash;
|
|
190
196
|
Object.defineProperty(exports, 'inspectPostExecutionInvariants', {
|
|
191
197
|
enumerable: true,
|
|
@@ -205,6 +211,7 @@ Object.defineProperty(exports, 'installStateWriteInterceptor', {
|
|
|
205
211
|
return _ocap_tx_pipeline.installStateWriteInterceptor;
|
|
206
212
|
}
|
|
207
213
|
});
|
|
214
|
+
exports.markStatelessPrefix = require_stateless_prefix.markStatelessPrefix;
|
|
208
215
|
exports.normalizeActorAddress = require_gas_security_guard.normalizeActorAddress;
|
|
209
216
|
Object.defineProperty(exports, 'normalizeEntityKey', {
|
|
210
217
|
enumerable: true,
|