sigild 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -3
- package/THREAT_MODEL.md +2 -0
- package/dist/src/audit/index.d.ts +1 -1
- package/dist/src/audit/index.d.ts.map +1 -1
- package/dist/src/audit/index.js.map +1 -1
- package/dist/src/audit/log.d.ts +15 -0
- package/dist/src/audit/log.d.ts.map +1 -1
- package/dist/src/audit/log.js +2 -0
- package/dist/src/audit/log.js.map +1 -1
- package/dist/src/bin/sigil-mcp.js +68 -7
- package/dist/src/bin/sigil-mcp.js.map +1 -1
- package/dist/src/cli/paths.d.ts +2 -0
- package/dist/src/cli/paths.d.ts.map +1 -1
- package/dist/src/cli/paths.js +1 -0
- package/dist/src/cli/paths.js.map +1 -1
- package/dist/src/confirm/config.d.ts +19 -0
- package/dist/src/confirm/config.d.ts.map +1 -1
- package/dist/src/confirm/config.js +48 -0
- package/dist/src/confirm/config.js.map +1 -1
- package/dist/src/confirm/index.d.ts +1 -1
- package/dist/src/confirm/index.d.ts.map +1 -1
- package/dist/src/confirm/index.js.map +1 -1
- package/dist/src/daemon/handles.d.ts +6 -0
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +11 -0
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/index.d.ts +1 -1
- package/dist/src/daemon/index.d.ts.map +1 -1
- package/dist/src/daemon/index.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +21 -0
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +179 -27
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/eth/abi.d.ts +82 -0
- package/dist/src/eth/abi.d.ts.map +1 -0
- package/dist/src/eth/abi.js +328 -0
- package/dist/src/eth/abi.js.map +1 -0
- package/dist/src/eth/index.d.ts +1 -0
- package/dist/src/eth/index.d.ts.map +1 -1
- package/dist/src/eth/index.js +1 -0
- package/dist/src/eth/index.js.map +1 -1
- package/dist/src/mcp/parent-watchdog.d.ts +31 -0
- package/dist/src/mcp/parent-watchdog.d.ts.map +1 -0
- package/dist/src/mcp/parent-watchdog.js +35 -0
- package/dist/src/mcp/parent-watchdog.js.map +1 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +13 -2
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/mcp/tools.d.ts.map +1 -1
- package/dist/src/mcp/tools.js +21 -1
- package/dist/src/mcp/tools.js.map +1 -1
- package/dist/src/policy/ledger.d.ts +1 -0
- package/dist/src/policy/ledger.d.ts.map +1 -1
- package/dist/src/policy/ledger.js +70 -44
- package/dist/src/policy/ledger.js.map +1 -1
- package/dist/src/policy/loader.d.ts.map +1 -1
- package/dist/src/policy/loader.js +9 -0
- package/dist/src/policy/loader.js.map +1 -1
- package/dist/src/policy/template.d.ts +2 -2
- package/dist/src/policy/template.d.ts.map +1 -1
- package/dist/src/policy/template.js +20 -0
- package/dist/src/policy/template.js.map +1 -1
- package/dist/src/policy/types.d.ts +16 -0
- package/dist/src/policy/types.d.ts.map +1 -1
- package/dist/src/policy/types.js.map +1 -1
- package/dist/src/preview/abi-dir.d.ts +50 -0
- package/dist/src/preview/abi-dir.d.ts.map +1 -0
- package/dist/src/preview/abi-dir.js +175 -0
- package/dist/src/preview/abi-dir.js.map +1 -0
- package/dist/src/preview/decode.d.ts +26 -0
- package/dist/src/preview/decode.d.ts.map +1 -0
- package/dist/src/preview/decode.js +110 -0
- package/dist/src/preview/decode.js.map +1 -0
- package/dist/src/preview/format.d.ts +45 -0
- package/dist/src/preview/format.d.ts.map +1 -0
- package/dist/src/preview/format.js +222 -0
- package/dist/src/preview/format.js.map +1 -0
- package/dist/src/preview/index.d.ts +60 -0
- package/dist/src/preview/index.d.ts.map +1 -0
- package/dist/src/preview/index.js +163 -0
- package/dist/src/preview/index.js.map +1 -0
- package/dist/src/preview/known.d.ts +74 -0
- package/dist/src/preview/known.d.ts.map +1 -0
- package/dist/src/preview/known.js +425 -0
- package/dist/src/preview/known.js.map +1 -0
- package/dist/src/preview/simulate.d.ts +156 -0
- package/dist/src/preview/simulate.d.ts.map +1 -0
- package/dist/src/preview/simulate.js +768 -0
- package/dist/src/preview/simulate.js.map +1 -0
- package/dist/src/preview/simulators.d.ts +39 -0
- package/dist/src/preview/simulators.d.ts.map +1 -0
- package/dist/src/preview/simulators.js +71 -0
- package/dist/src/preview/simulators.js.map +1 -0
- package/dist/src/preview/trust.d.ts +49 -0
- package/dist/src/preview/trust.d.ts.map +1 -0
- package/dist/src/preview/trust.js +279 -0
- package/dist/src/preview/trust.js.map +1 -0
- package/dist/src/preview/types.d.ts +69 -0
- package/dist/src/preview/types.d.ts.map +1 -0
- package/dist/src/preview/types.js +11 -0
- package/dist/src/preview/types.js.map +1 -0
- package/dist/src/preview/units.d.ts +75 -0
- package/dist/src/preview/units.d.ts.map +1 -0
- package/dist/src/preview/units.js +228 -0
- package/dist/src/preview/units.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { decodeCalldata } from './decode.js';
|
|
2
|
+
import { renderHeadline, renderText, simulationSummary } from './format.js';
|
|
3
|
+
import { operatorWarning } from './known.js';
|
|
4
|
+
import { simulateTransaction } from './simulate.js';
|
|
5
|
+
import { NO_META } from './types.js';
|
|
6
|
+
import { assessTokens, checkBehaviour, rawCallText } from './trust.js';
|
|
7
|
+
import { clean, isUnlimited, shortAddr } from './units.js';
|
|
8
|
+
export async function buildTxPreview(input) {
|
|
9
|
+
const { tx, registry } = input;
|
|
10
|
+
const from = input.from.toLowerCase();
|
|
11
|
+
const to = tx.to === null ? null : tx.to.toLowerCase();
|
|
12
|
+
const value = BigInt(tx.value);
|
|
13
|
+
const chainId = BigInt(tx.chainId);
|
|
14
|
+
const data = typeof tx.data === 'string' ? Buffer.from(tx.data.slice(2), 'hex') : Buffer.from(tx.data);
|
|
15
|
+
const ctx = { to, value, from };
|
|
16
|
+
// First pass with no metadata: learns which tokens the call names, so the
|
|
17
|
+
// simulator can fetch their symbol/decimals alongside the ones it touches.
|
|
18
|
+
const pre = decodeCalldata(data, registry, NO_META, ctx);
|
|
19
|
+
let simulation;
|
|
20
|
+
if (input.simulator === undefined) {
|
|
21
|
+
simulation = {
|
|
22
|
+
status: 'skipped',
|
|
23
|
+
reason: input.skippedReason ?? `no simulation RPC configured for chain ${chainId}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
simulation = await simulateTransaction(tx, from, input.simulator, {
|
|
28
|
+
...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
|
|
29
|
+
extraTokens: pre.tokens ?? [],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Contract-reported symbols are vetted before anything renders them.
|
|
33
|
+
const trust = assessTokens(simulation.status === 'ok' || simulation.status === 'reverted' ? simulation.tokenMeta : {}, chainId);
|
|
34
|
+
const metaTable = trust.meta;
|
|
35
|
+
const meta = (addr) => Object.prototype.hasOwnProperty.call(metaTable, addr) ? metaTable[addr] : undefined;
|
|
36
|
+
let decoded = Object.keys(metaTable).length > 0 ? decodeCalldata(data, registry, meta, ctx) : pre;
|
|
37
|
+
// A friendly verb is only kept when the contract behaved like it.
|
|
38
|
+
const verdict = checkBehaviour(decoded, simulation, { from, to, chainId }, meta);
|
|
39
|
+
const trustWarnings = [];
|
|
40
|
+
if (verdict && !verdict.matches && verdict.rewrite !== false) {
|
|
41
|
+
const raw = rawCallText(decoded);
|
|
42
|
+
const { short: _dropped, ...rest } = decoded;
|
|
43
|
+
decoded = { ...rest, text: raw, short: `${raw} on ${shortAddr(to ?? '')}` };
|
|
44
|
+
}
|
|
45
|
+
if (verdict && !verdict.matches) {
|
|
46
|
+
if (verdict.warning)
|
|
47
|
+
trustWarnings.push(verdict.warning);
|
|
48
|
+
trustWarnings.push(...(verdict.more ?? []));
|
|
49
|
+
}
|
|
50
|
+
if (simulation.status === 'ok' && simulation.changes) {
|
|
51
|
+
const c = simulation.changes;
|
|
52
|
+
const debit = c.native < 0n ||
|
|
53
|
+
c.erc20.some((e) => e.delta < 0n) ||
|
|
54
|
+
c.nftOut.length > 0 ||
|
|
55
|
+
c.erc1155.some((e) => e.delta < 0n);
|
|
56
|
+
const shadyInflow = c.erc20.some((e) => e.delta > 0n && (trust.unverified.has(e.token) || !metaTable[e.token]?.symbol));
|
|
57
|
+
if (debit && shadyInflow)
|
|
58
|
+
trustWarnings.push('inflows from unverified tokens — check the debit');
|
|
59
|
+
}
|
|
60
|
+
// Most actionable first: behaviour mismatch and unverified inflows, then
|
|
61
|
+
// the per-token impersonation details.
|
|
62
|
+
trustWarnings.push(...trust.warnings);
|
|
63
|
+
const warnings = collectWarnings(decoded, simulation, { from, to, value }, trustWarnings);
|
|
64
|
+
const render = {
|
|
65
|
+
decoded,
|
|
66
|
+
simulation,
|
|
67
|
+
warnings,
|
|
68
|
+
from,
|
|
69
|
+
to,
|
|
70
|
+
value,
|
|
71
|
+
chainId,
|
|
72
|
+
meta,
|
|
73
|
+
footer: registry.loadWarnings,
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
decoded,
|
|
77
|
+
simulation,
|
|
78
|
+
warnings,
|
|
79
|
+
text: renderText(render),
|
|
80
|
+
headline: renderHeadline(render),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** The simulation ran without the signed fee fields (see simulate.ts). */
|
|
84
|
+
export const UNFAITHFUL_WARNING = 'simulated without fee fields (node refused: insufficient funds) — the contract saw tx.gasprice = 0';
|
|
85
|
+
function collectWarnings(decoded, sim, tx, trustWarnings) {
|
|
86
|
+
// Impersonation / behaviour warnings first: they explain everything else.
|
|
87
|
+
const out = [...trustWarnings, ...decoded.warnings];
|
|
88
|
+
if ((sim.status === 'ok' || sim.status === 'reverted') && !sim.faithful) {
|
|
89
|
+
out.push(UNFAITHFUL_WARNING);
|
|
90
|
+
}
|
|
91
|
+
if (sim.status === 'reverted')
|
|
92
|
+
out.push(`simulation reverted: ${sim.revertReason ?? 'unknown'}`);
|
|
93
|
+
if (sim.status === 'unavailable')
|
|
94
|
+
out.push(`simulation unavailable: ${sim.reason}`);
|
|
95
|
+
if (decoded.source === 'unknown' && tx.value > 0n) {
|
|
96
|
+
out.push('calldata to unknown function with ETH value');
|
|
97
|
+
}
|
|
98
|
+
if (tx.to !== null && tx.to === tx.from)
|
|
99
|
+
out.push("destination is the portal's own address");
|
|
100
|
+
if (sim.status === 'ok') {
|
|
101
|
+
for (const a of sim.approvals ?? []) {
|
|
102
|
+
if (a.standard === 'erc20' && a.amount !== undefined && isUnlimited(a.amount)) {
|
|
103
|
+
out.push('UNLIMITED approval');
|
|
104
|
+
}
|
|
105
|
+
if (a.standard === 'operator' && a.approved)
|
|
106
|
+
out.push(operatorWarning(a.spender, a.token));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [...new Set(out.map(clean))];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stand-in when building the preview itself failed (a bug, not a node
|
|
113
|
+
* problem — those are already 'unavailable'). Presentation fails open but
|
|
114
|
+
* loud: the sign path proceeds with this warning unless the policy demands
|
|
115
|
+
* a simulation, in which case the 'unavailable' status denies (fail closed).
|
|
116
|
+
*/
|
|
117
|
+
export function previewFailure(message) {
|
|
118
|
+
const reason = `preview failed: ${message}`;
|
|
119
|
+
const decoded = {
|
|
120
|
+
selector: null,
|
|
121
|
+
text: reason,
|
|
122
|
+
warnings: [reason],
|
|
123
|
+
source: 'unknown',
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
decoded,
|
|
127
|
+
simulation: { status: 'unavailable', reason },
|
|
128
|
+
warnings: [reason],
|
|
129
|
+
text: `call: ${reason}\nwarnings:\n - ${reason}`,
|
|
130
|
+
headline: `⚠ ${reason}`.slice(0, 220),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** The compact form written into the audit entry. */
|
|
134
|
+
export function auditPreview(p) {
|
|
135
|
+
return {
|
|
136
|
+
text: p.text,
|
|
137
|
+
decoded: clean(p.decoded.text),
|
|
138
|
+
simulation: clean(simulationSummary(p.simulation)),
|
|
139
|
+
warnings: p.warnings,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Deep-convert bigints to decimal strings so the value can be JSON-serialized. */
|
|
143
|
+
export function jsonSafe(v) {
|
|
144
|
+
if (typeof v === 'bigint')
|
|
145
|
+
return v.toString();
|
|
146
|
+
if (Array.isArray(v))
|
|
147
|
+
return v.map(jsonSafe);
|
|
148
|
+
if (typeof v === 'object' && v !== null) {
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const [k, x] of Object.entries(v))
|
|
151
|
+
out[k] = jsonSafe(x);
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
return v;
|
|
155
|
+
}
|
|
156
|
+
export { AbiRegistry } from './abi-dir.js';
|
|
157
|
+
export { SimulatorResolver } from './simulators.js';
|
|
158
|
+
export { decodeCalldata } from './decode.js';
|
|
159
|
+
export { simulateTransaction, analyzeLogs, decodeRevert, fetchTokenMeta, parseSymbol, parseDecimals, DEFAULT_SIM_TIMEOUT_MS, } from './simulate.js';
|
|
160
|
+
export { renderText, renderHeadline, simulationSummary, HEADLINE_MAX, } from './format.js';
|
|
161
|
+
export { KNOWN_FUNCTIONS, EVENT_TOPICS, decodeV3Path } from './known.js';
|
|
162
|
+
export { formatUnits, shortAddr, sanitizeSymbol } from './units.js';
|
|
163
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/preview/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAA0B,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,EAA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GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC7D,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,OAAO,EAAE,WAAW,EAAmC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAA8B,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,sBAAsB,GAOvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAsB,MAAM,YAAY,CAAC;AAE7F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type AbiType } from '../eth/abi.js';
|
|
2
|
+
import type { DecodedCall, SwapOut, TokenMetaLookup } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Built-in registry of the function calls an agent is most likely to be
|
|
5
|
+
* asked to sign, each with a `describe` that turns decoded arguments into an
|
|
6
|
+
* English sentence plus warnings. These are the calls where the 4-byte
|
|
7
|
+
* selector alone hides what matters: an `approve` with value 0 looks inert
|
|
8
|
+
* on a value-only summary but can hand over a whole balance.
|
|
9
|
+
*
|
|
10
|
+
* Selector collisions are deliberate where the standards share an ABI:
|
|
11
|
+
* ERC-20 and ERC-721 `approve(address,uint256)` / `transferFrom(...)`, and
|
|
12
|
+
* ERC-721 / ERC-1155 `setApprovalForAll(address,bool)`, are one entry each.
|
|
13
|
+
* The descriptions read amounts with token decimals when known and fall
|
|
14
|
+
* back to raw integers (which is also how a token id renders).
|
|
15
|
+
*/
|
|
16
|
+
export interface DescribeCtx {
|
|
17
|
+
/** The contract being called (lowercase), or null for a deploy. */
|
|
18
|
+
to: string | null;
|
|
19
|
+
/** Native value sent with the call, wei. */
|
|
20
|
+
value: bigint;
|
|
21
|
+
/** The signing portal's address (lowercase), when known. */
|
|
22
|
+
from?: string;
|
|
23
|
+
meta: TokenMetaLookup;
|
|
24
|
+
/**
|
|
25
|
+
* Decode nested calldata (multicall members) one level deep. Absent at
|
|
26
|
+
* depth ≥ 1, which is what stops recursion.
|
|
27
|
+
*/
|
|
28
|
+
decodeInner?: (data: Uint8Array) => DecodedCall;
|
|
29
|
+
}
|
|
30
|
+
export interface Description {
|
|
31
|
+
text: string;
|
|
32
|
+
short?: string;
|
|
33
|
+
warnings: string[];
|
|
34
|
+
/** Token addresses whose metadata would sharpen the rendering. */
|
|
35
|
+
tokens?: string[];
|
|
36
|
+
swapOut?: SwapOut;
|
|
37
|
+
innerSwaps?: {
|
|
38
|
+
index: number;
|
|
39
|
+
out: SwapOut;
|
|
40
|
+
}[];
|
|
41
|
+
}
|
|
42
|
+
export interface KnownFunction {
|
|
43
|
+
selector: string;
|
|
44
|
+
signature: string;
|
|
45
|
+
name: string;
|
|
46
|
+
inputs: {
|
|
47
|
+
name: string;
|
|
48
|
+
type: string;
|
|
49
|
+
abiType: AbiType;
|
|
50
|
+
}[];
|
|
51
|
+
describe: (args: unknown[], ctx: DescribeCtx) => Description;
|
|
52
|
+
}
|
|
53
|
+
/** Shared with the simulator so a decoded grant and a simulated one dedupe. */
|
|
54
|
+
export declare function operatorWarning(operator: string, collection: string): string;
|
|
55
|
+
/** Decode a V3 packed path: token(20) [fee(3) token(20)]*. Null if malformed. */
|
|
56
|
+
export declare function decodeV3Path(hex: string): string[] | null;
|
|
57
|
+
/** selector → built-in entry. */
|
|
58
|
+
export declare const KNOWN_FUNCTIONS: ReadonlyMap<string, KnownFunction>;
|
|
59
|
+
/** Selectors whose `to` is an ERC-20 (metadata for `to` improves the text). */
|
|
60
|
+
export declare const ERC20_SELECTORS: ReadonlySet<string>;
|
|
61
|
+
/** topic0 of the events the simulator understands. */
|
|
62
|
+
export declare const EVENT_TOPICS: Readonly<{
|
|
63
|
+
/** ERC-20 (3 topics + amount) and ERC-721 (4 topics, tokenId indexed). */
|
|
64
|
+
Transfer: string;
|
|
65
|
+
/** ERC-20 (3 topics + amount) and ERC-721 (4 topics). */
|
|
66
|
+
Approval: string;
|
|
67
|
+
ApprovalForAll: string;
|
|
68
|
+
TransferSingle: string;
|
|
69
|
+
TransferBatch: string;
|
|
70
|
+
/** WETH9 wrap/unwrap: no Transfer is emitted, so these move the balance. */
|
|
71
|
+
Deposit: string;
|
|
72
|
+
Withdrawal: string;
|
|
73
|
+
}>;
|
|
74
|
+
//# sourceMappingURL=known.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known.d.ts","sourceRoot":"","sources":["../../../src/preview/known.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAKb,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAaxE;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAC1B,mEAAmE;IACnE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,WAAW,CAAC;CACjD;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAA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