feat: rejecting relays where feeCommitment value quote is different from withdrawn

This commit is contained in:
Francisco Bezzecchi
2025-12-27 21:05:22 -03:00
parent 7bc392dad5
commit 92e899fab2
2 changed files with 11 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ export enum ErrorCode {
CONTEXT_MISMATCH = "CONTEXT_MISMATCH",
RELAYER_COMMITMENT_REJECTED = "RELAYER_COMMITMENT_REJECTED",
INSUFFICIENT_WITHDRAWN_VALUE = "INSUFFICIENT_WITHDRAWN_VALUE",
MISMATCHING_WITHDRAWN_VALUE = "MISMATCHING_WITHDRAWN_VALUE",
ASSET_NOT_SUPPORTED = "ASSET_NOT_SUPPORTED",
// Config errors
@@ -252,6 +253,14 @@ export class WithdrawalValidationError extends RelayerError {
);
}
public static withdrawnValueMismatch(details: string) {
return new WithdrawalValidationError(
"Withdrawn value is too small",
ErrorCode.INSUFFICIENT_WITHDRAWN_VALUE,
details,
);
}
public static override assetNotSupported(details: string) {
return new WithdrawalValidationError(
"Asset not supported on this chain",

View File

@@ -236,9 +236,9 @@ export class PrivacyPoolRelayer {
const { feeRecipient, relayFeeBPS } = decodeWithdrawalData(withdrawalData);
const proofSignals = parseSignals(wp.proof.publicSignals);
if ((wp.feeCommitment !== undefined) && (wp.feeCommitment.amount > proofSignals.withdrawnValue)) {
if ((wp.feeCommitment !== undefined) && (wp.feeCommitment.amount !== proofSignals.withdrawnValue)) {
throw WithdrawalValidationError.withdrawnValueTooSmall(
`WithdrawnValue too small: expected "${wp.feeCommitment.amount}", got "${proofSignals.withdrawnValue}".`,
`WithdrawnValue mismatch: expected "${wp.feeCommitment.amount}", got "${proofSignals.withdrawnValue}".`,
);
}