From 4831874ab714f0bf3ad027d5eee51e48cbe3ea1d Mon Sep 17 00:00:00 2001 From: Derek Croote Date: Thu, 4 May 2023 22:37:00 -0700 Subject: [PATCH] Ignore requests with an invalid sponsor wallet (#1758) --- .changeset/young-cougars-nail.md | 5 +++++ packages/airnode-node/src/api/index.ts | 20 ++----------------- .../src/evm/handlers/initialize-provider.ts | 8 +++++++- .../verification/request-verification.test.ts | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) create mode 100644 .changeset/young-cougars-nail.md diff --git a/.changeset/young-cougars-nail.md b/.changeset/young-cougars-nail.md new file mode 100644 index 0000000000..d1a5ad7b6a --- /dev/null +++ b/.changeset/young-cougars-nail.md @@ -0,0 +1,5 @@ +--- +'@api3/airnode-node': minor +--- + +Ignore requests with an invalid sponsor wallet diff --git a/packages/airnode-node/src/api/index.ts b/packages/airnode-node/src/api/index.ts index e71e5c85b2..434b93362f 100644 --- a/packages/airnode-node/src/api/index.ts +++ b/packages/airnode-node/src/api/index.ts @@ -7,7 +7,7 @@ import axios, { AxiosError } from 'axios'; import { ethers } from 'ethers'; import compact from 'lodash/compact'; import { postProcessApiSpecifications, preProcessApiSpecifications } from './processing'; -import { getAirnodeWalletFromPrivateKey, deriveSponsorWalletFromMnemonic } from '../evm'; +import { getAirnodeWalletFromPrivateKey } from '../evm'; import { getReservedParameters } from '../adapters/http/parameters'; import { FIRST_API_CALL_TIMEOUT, SECOND_API_CALL_TIMEOUT } from '../constants'; import { isValidRequestId } from '../evm/verification'; @@ -101,22 +101,6 @@ export function signWithTemplateId(templateId: string, timestamp: string, data: ); } -export function verifySponsorWallet(payload: RegularApiCallPayload): LogsData | null { - const { config, aggregatedApiCall } = payload; - - const { sponsorAddress, sponsorWalletAddress, id } = aggregatedApiCall; - const derivedSponsorWallet = deriveSponsorWalletFromMnemonic( - config.nodeSettings.airnodeWalletMnemonic, - sponsorAddress - ); - if (derivedSponsorWallet.address === sponsorWalletAddress) return null; - - // TODO: Abstract this to a logging utils file - const message = `${RequestErrorMessage.SponsorWalletInvalid}, Request ID:${id}`; - const log = logger.pend('ERROR', message); - return [[log], { success: false, errorMessage: message }]; -} - export function verifyRequestId(payload: RegularApiCallPayload): LogsData | null { const { aggregatedApiCall } = payload; @@ -165,7 +149,7 @@ export function verifyCallApi(payload: ApiCallPayload) { } export function verifyRegularCallApiParams(payload: RegularApiCallPayload) { - const verifications = [verifySponsorWallet, verifyRequestId, verifyTemplateId]; + const verifications = [verifyRequestId, verifyTemplateId]; return verifications.reduce((result, verifierFn) => { if (result) return result; diff --git a/packages/airnode-node/src/evm/handlers/initialize-provider.ts b/packages/airnode-node/src/evm/handlers/initialize-provider.ts index 17ccf3c5ae..9c9fe5c890 100644 --- a/packages/airnode-node/src/evm/handlers/initialize-provider.ts +++ b/packages/airnode-node/src/evm/handlers/initialize-provider.ts @@ -182,10 +182,16 @@ export async function initializeProvider( ); logger.logPending(verifyRrpTriggersLogs); + const [verifySponsorWalletsLogs, verifiedApiCallsForSponsorWallets] = verification.verifySponsorWallets( + verifiedApiCallsForRrpTriggers, + state4.masterHDNode + ); + logger.logPending(verifySponsorWalletsLogs); + const state5 = state.update(state4, { requests: { ...state4.requests, - apiCalls: verifiedApiCallsForRrpTriggers, + apiCalls: verifiedApiCallsForSponsorWallets, }, }); diff --git a/packages/airnode-node/src/evm/verification/request-verification.test.ts b/packages/airnode-node/src/evm/verification/request-verification.test.ts index b6d8bcaa86..71d10c2d03 100644 --- a/packages/airnode-node/src/evm/verification/request-verification.test.ts +++ b/packages/airnode-node/src/evm/verification/request-verification.test.ts @@ -17,7 +17,7 @@ describe('verifySponsorWallets', () => { }; const invalidApiCall = fixtures.requests.buildApiCall(invalidSponsorWallet); const doNotMatchApiCall = fixtures.requests.buildApiCall(sponsorWalletDoesNotBelongToSponsor); - const [apiCalllogs, verifiesdApiCalls] = verification.verifySponsorWallets( + const [apiCalllogs, verifiedApiCalls] = verification.verifySponsorWallets( [invalidApiCall, doNotMatchApiCall], masterHDNode ); @@ -31,7 +31,7 @@ describe('verifySponsorWallets', () => { message: `Invalid sponsor wallet:${doNotMatchApiCall.sponsorWalletAddress} for Request:${doNotMatchApiCall.id}. Expected:0xdBFe14C250643DEFE92C9AbC52103bf4978C7113`, }, ]); - expect(verifiesdApiCalls.length).toEqual(0); + expect(verifiedApiCalls.length).toEqual(0); const invalidWithdrawal = fixtures.requests.buildWithdrawal(invalidSponsorWallet); const doNotMatchWithdrawal = fixtures.requests.buildWithdrawal(sponsorWalletDoesNotBelongToSponsor);