Skip to content

Commit 61bf09e

Browse files
fix(abstract-eth): erc-7984 pa-rebuild approval verifies content-based
The wrapApprove PA-rebuild (the onchain-multisig server-leg approval) failed verification: verifyMultisigWrapApproveTransaction demanded txParams.wrapParams (tokenName + amount) — but the PA-rebuild path carries no caller wrapParams (the PA's buildParams store only the type; the intent's wrapParams live in the journey). The verify's own doc comment contemplates the skip for the pendingApproval re-sign paths; the rebuild's merged txParams accidentally triggered the full check. Restructure verifyMultisigWrapApproveTransaction to be self-sufficient on the PA-rebuild path: - the wrapParams cross-check demand: skipped when txParams.pendingApprovalId is present (the PA-rebuild) - the pair resolved from the tx's own calldata: the approve's spender decoded → the reverse lookup over the registered ERC-7984 pairs on the network (by the wrapper address → the pair's tokenName) - the bounded checks preserved: the inner target = the pair's underlying ERC-20, no native value inside sendMultiSig, the spender = the wrapper, the prebuild-recipients mirror - the wrapParams cross-check (the amount vs the intent) runs only on the direct-sign path where the caller carries the intent Validated in staging: the wrapApprove PA approval — the rebuild 200, the verify passed (isPaRebuild: true, hasWrapParams: false), the tx signed, the approval PUT reached WP and the policy resolved. Ticket: CHALO-2010
1 parent 682c160 commit 61bf09e

1 file changed

Lines changed: 49 additions & 25 deletions

File tree

‎modules/abstract-eth/src/abstractEthLikeNewCoins.ts‎

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,26 +4021,16 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem
40214021
if (!txPrebuild?.txHex) {
40224022
throw new Error('missing txHex in txPrebuild');
40234023
}
4024-
if (!wrapParams?.tokenName || !wrapParams.amount) {
4024+
// CHALO-2010: the PA-rebuild path — the server derived the tx from the pending approval's own
4025+
// intent data (the PA carries only the type and the pendingApprovalId; the intent's wrapParams
4026+
// live in the journey). The wrapParams cross-check has no caller data to check against on this
4027+
// path; the bounded checks below still run, and the pair is resolved from the tx's own calldata.
4028+
const pendingApprovalId = (txParams as { pendingApprovalId?: string }).pendingApprovalId;
4029+
const isPaRebuild = !!pendingApprovalId;
4030+
if (!isPaRebuild && (!wrapParams?.tokenName || !wrapParams.amount)) {
40254031
return throwRecipientMismatch('wrapApprove transaction requires wrapParams with tokenName and amount', []);
40264032
}
40274033

4028-
let wrapper: Erc7984Coin;
4029-
let underlyingErc20Address: string;
4030-
try {
4031-
const staticsCoin = coins.get(wrapParams.tokenName);
4032-
if (!(staticsCoin instanceof Erc7984Coin) || !staticsCoin.underlyingErc20Address) {
4033-
throw new Error('not an ERC-7984 pair');
4034-
}
4035-
wrapper = staticsCoin;
4036-
underlyingErc20Address = staticsCoin.underlyingErc20Address.toLowerCase();
4037-
} catch {
4038-
return throwRecipientMismatch(
4039-
`wrapApprove: '${wrapParams.tokenName}' is not a registered ERC-7984 shield pair`,
4040-
[]
4041-
);
4042-
}
4043-
40444034
const txBuilder = this.getTransactionBuilder();
40454035
txBuilder.from(txPrebuild.txHex);
40464036
const txJson = (await txBuilder.build()).toJson();
@@ -4071,13 +4061,6 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem
40714061
const mismatch = (message: string, address = innerTo, amount = innerAmount): Promise<never> =>
40724062
throwRecipientMismatch(message, [{ address: address || '', amount: amount || '' }]);
40734063

4074-
if (innerTo.toLowerCase() !== underlyingErc20Address) {
4075-
await mismatch('wrapApprove transaction must target the underlying ERC-20 of the wrapper');
4076-
}
4077-
if (innerAmount !== '0') {
4078-
await mismatch('wrapApprove transaction must not carry native value inside sendMultiSig');
4079-
}
4080-
40814064
let approve: { spender: string; amount: string };
40824065
try {
40834066
approve = decodeApproveCalldata(innerData || '');
@@ -4086,10 +4069,51 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem
40864069
`wrapApprove transaction must use ERC-20 approve(address,uint256) calldata — ${(e as Error).message}`
40874070
);
40884071
}
4072+
4073+
let wrapper: Erc7984Coin;
4074+
let underlyingErc20Address: string;
4075+
if (isPaRebuild) {
4076+
// CHALO-2010: no caller wrapParams — resolve the pair by the approve's spender (the reverse
4077+
// lookup over the registered ERC-7984 pairs on this network).
4078+
const network = this.getNetwork();
4079+
if (!network) {
4080+
throw new Error('missing network for ERC-7984 intent verification');
4081+
}
4082+
const { byTokenName } = getErc7984WrappersForNetwork(network);
4083+
const tokenName = [...byTokenName.entries()].find(([, addr]) => addr === approve.spender.toLowerCase())?.[0];
4084+
const staticsCoin = tokenName ? coins.get(tokenName) : undefined;
4085+
if (!(staticsCoin instanceof Erc7984Coin) || !staticsCoin.underlyingErc20Address) {
4086+
return await mismatch('wrapApprove transaction spender is not a registered ERC-7984 wrapper', approve.spender);
4087+
}
4088+
wrapper = staticsCoin;
4089+
underlyingErc20Address = staticsCoin.underlyingErc20Address.toLowerCase();
4090+
} else {
4091+
try {
4092+
const staticsCoin = coins.get(wrapParams?.tokenName ?? '');
4093+
if (!(staticsCoin instanceof Erc7984Coin) || !staticsCoin.underlyingErc20Address) {
4094+
throw new Error('not an ERC-7984 pair');
4095+
}
4096+
wrapper = staticsCoin;
4097+
underlyingErc20Address = staticsCoin.underlyingErc20Address.toLowerCase();
4098+
} catch {
4099+
return throwRecipientMismatch(
4100+
`wrapApprove: '${wrapParams?.tokenName}' is not a registered ERC-7984 shield pair`,
4101+
[]
4102+
);
4103+
}
4104+
}
4105+
4106+
if (innerTo.toLowerCase() !== underlyingErc20Address) {
4107+
await mismatch('wrapApprove transaction must target the underlying ERC-20 of the wrapper');
4108+
}
4109+
if (innerAmount !== '0') {
4110+
await mismatch('wrapApprove transaction must not carry native value inside sendMultiSig');
4111+
}
4112+
40894113
if (approve.spender.toLowerCase() !== wrapper.contractAddress.toLowerCase()) {
40904114
await mismatch('wrapApprove transaction spender does not match the wrapper contract', approve.spender);
40914115
}
4092-
if (approve.amount !== wrapParams.amount) {
4116+
if (!isPaRebuild && approve.amount !== wrapParams?.amount) {
40934117
await mismatch('wrapApprove transaction amount does not match the requested amount', innerTo, approve.amount);
40944118
}
40954119

0 commit comments

Comments
 (0)