Skip to content

Commit

Permalink
Ignore requests with an invalid sponsor wallet (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcroote committed May 18, 2023
1 parent a379bc0 commit be1cb53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-cougars-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@api3/airnode-node': minor
---

Ignore requests with an invalid sponsor wallet
20 changes: 2 additions & 18 deletions packages/airnode-node/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -101,22 +101,6 @@ export function signWithTemplateId(templateId: string, timestamp: string, data:
);
}

export function verifySponsorWallet(payload: RegularApiCallPayload): LogsData<ApiCallErrorResponse> | 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<ApiCallErrorResponse> | null {
const { aggregatedApiCall } = payload;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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);
Expand Down

0 comments on commit be1cb53

Please sign in to comment.