Reach out for an audit or to learn more about Macro
or Message on Telegram

Infinex A-6

Security Audit

August 28, 2024

Version 1.0.0

Presented by 0xMacro

Table of Contents

Introduction

This document includes the results of the security audit for Infinex's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from July 30 to August 1, 2024.

The purpose of this audit is to review the source code of certain Infinex Solidity contracts, and provide feedback on the design, architecture, and quality of the source code with an emphasis on validating the correctness and security of the software in its entirety.

Disclaimer: While Macro’s review is comprehensive and has surfaced some changes that should be made to the source code, this audit should not solely be relied upon for security, as no single audit is guaranteed to catch all possible bugs.

Overall Assessment

The following is an aggregation of issues found by the Macro Audit team:

Severity Count Acknowledged Won't Do Addressed
Low 2 - - 2
Code Quality 6 - 3 3

Infinex was quick to respond to these issues.

Specification

Our understanding of the specification was based on the following sources:

Trust Model, Assumptions, and Accepted Risks (TMAAR)

The changes audited rely on the following assumptions specifically.

Patron Purchase App:

Source Code

The following source code was reviewed during the audit:


Specifically, we audited the following contracts:

Source Code SHA256
./src/apps/patron-purchase/PatronPointOfPurchase.sol

4d202051b8c5bc30f2a747b92816bbb8d24a7743a003ac9fb35eacc341cf7d16

./src/apps/patron-purchase/PatronPointOfPurchaseStorage.sol

0c666349ad3ea09ff74b94c348e8739a31acef52ff69849de188732878d7212c

./src/apps/patron-purchase/PatronPurchaseVault.sol

efc7c8cd1cba4307120e22f05fa3b8b183546ace641bb1ae1882eb3bda577528

./src/apps/patron-purchase/PatronPurchaseVaultStorage.sol

147d94bc898589a6833a91dddf606a26de93cad3e56e94f622f74f6f3601c410

./src/apps/patron-purchase/PurchaseApp.sol

ac4ca74594ec0edd0056b824f1413755494a0ba6150fd904fd9315f5186e3359

./src/apps/patron-purchase/PurchaseAppBeacon.sol

90829b054aeb1a8af775720d31657dddac4ca94e53b01a5b7e4d91cee133bfb9

./src/apps/patron-purchase/PurchaseError.sol

979f3692fab02fb9ce441c3f0222ce2bdb48bd01161d0e850ee6b372fbf4a4a7

Note: Currently the referenced repository is private, but there are plans to make it public in the future.

Issue Descriptions and Recommendations

Click on an issue to jump to it, or scroll down to see them all.

Security Level Reference

We quantify issues in three parts:

  1. The high/medium/low/spec-breaking impact of the issue:
    • How bad things can get (for a vulnerability)
    • The significance of an improvement (for a code quality issue)
    • The amount of gas saved (for a gas optimization)
  2. The high/medium/low likelihood of the issue:
    • How likely is the issue to occur (for a vulnerability)
  3. The overall critical/high/medium/low severity of the issue.

This third part – the severity level – is a summary of how much consideration the client should give to fixing the issue. We assign severity according to the table of guidelines below:

Severity Description
(C-x)
Critical

We recommend the client must fix the issue, no matter what, because not fixing would mean significant funds/assets WILL be lost.

(H-x)
High

We recommend the client must address the issue, no matter what, because not fixing would be very bad, or some funds/assets will be lost, or the code’s behavior is against the provided spec.

(M-x)
Medium

We recommend the client to seriously consider fixing the issue, as the implications of not fixing the issue are severe enough to impact the project significantly, albiet not in an existential manner.

(L-x)
Low

The risk is small, unlikely, or may not relevant to the project in a meaningful way.

Whether or not the project wants to develop a fix is up to the goals and needs of the project.

(Q-x)
Code Quality

The issue identified does not pose any obvious risk, but fixing could improve overall code quality, on-chain composability, developer ergonomics, or even certain aspects of protocol design.

(I-x)
Informational

Warnings and things to keep in mind when operating the protocol. No immediate action required.

(G-x)
Gas Optimizations

The presented optimization suggestion would save an amount of gas significant enough, in our opinion, to be worth the development cost of implementing it.

Issue Details

L-1

Potential reentrancy in finalizePurchasePatronNFTEther

Topic
Reentrancy
Status
Impact
High
Likelihood
Low

In PatronPurchaseForwarder contract, the finalizePurchasePatronNFTEther() function, the logic order does not follow the Check-Effect-Interactions pattern, potentially allowing an external call to re-use a valid signature multiple times:

(bool success,) = _purchaseVault.call{ value: msg.value }(""); 
if (!success) revert PurchaseError.ETHTransferFailed();

PatronPurchaseForwarderStorage._setIdempotencyKeyUsed(_idempotencyKey, true);

Remediations to Consider:

Although the _purchaseVault is a known and approved entity, consider setting the idempotencyKey before making any external calls.

L-2

The purchase app doesn’t support EIP712

Topic
Protocol Design
Status
Impact
Medium
Likelihood
Low

In PatronPurchaseForwarder, finalizePurchasePatronNFTERC20 and finalizePurchasePatronNFTEther require a valid signature passed to the function. However, the current implementation uses a custom message format to calculate the hash rather then supporting EIP-712.

Remediation to Consider

Consider supporting signature creation according to the EIP712 standard for better security and usability.

Q-1

Use consistent contract names for patron-purchase

Topic
Naming Convention
Status
Quality Impact
Low

All the patron related contracts reside under the patron-purchase folder. However, they don’t use consistent names. PurchaseApp and PurchaseAppBeacon are not prefixed with “Patron”, but the other contracts are, such as **Patron**PointOfPurchase.

Consider renaming PurchaseApp to PatronPurchaseApp and PurchaseAppBeacon to PatronPurchaseAppBeacon.

Q-2

Use local variable instead of accessing array element

Topic
Optimization
Status
Quality Impact
Low

In PatronPointOfPurchase.initialize(), consider using the local variable signer instead of accessing the array element.

PatronPointOfPurchaseStorage._setAuthorizedSigner(**_authorizedSigners[i]**, true);

Reference: PatronPointOfPurchase.sol#L84

Q-3

Add msg.sender to SuccessfulPatronNFTPurchase event

Topic
Events
Status
Wont Do
Quality Impact
Low

Reference: PatronPointOfPurchase.sol#L299, PatronPointOfPurchase.sol#L383

In PatronPointOfPurchase, finalizePurchasePatronNFTERC20 and finalizePurchasePatronNFTEther emit a SuccessfulPatronNFTPurchase event.

Remediation to Consider

Consider adding msg.sender to the event, allowing to track where the request is coming from.

Response by Infinex

The main intent is to call this from the app account, where the recipient is set as the main account in the purchase app which is the intended caller/recipient. In most cases the caller is should be agnostic.

Q-4

Authorized vaults can not be removed

Topic
Use Cases
Status
Quality Impact
Medium

In the PatronPointOfPurchase contract, the setAuthorizedPurchaseVault() function sets the authorized vaults where funds are forwarded. However, unlike setAuthorizedSigner() and setAuthorizedPurchaseToken() functions, this one doesn’t support removing authorized vaults.

function setAuthorizedPurchaseVault(uint8 _vaultId, address _vaultAddress) external onlyOwner {
    if (_vaultAddress == address(0)) revert PurchaseError.ZeroAddress();
    emit AuthorizedPurchaseVaultSet(_vaultId, _vaultAddress);
    PatronPointOfPurchaseStorage._setAuthorizedPurchaseVault(_vaultId, _vaultAddress);
}

Reference: PatronPointOfPurcharse.sol#L408-412

Consider allowing removing authorized vaults.

Q-5

No reinitialize() method

Topic
Upgrade Process
Status
Wont Do
Quality Impact
Medium

The PatronPointOfPurchase and PatronPurchaseVault upgradable contracts lack a reinitialize function. If future upgrades require a reinitialization procedure, the current logic will not allow it, and an additional upgrade step or manual reinitialization would be needed to achieve a complete upgrade. This could potentially leave the contracts in an undesired state. Consider adding the reinitialization logic calls to be implemented by future upgrades.

Response by Infinex

We will not update it regularly. We would do a manual reinitialize for any new storage or functionality.

Q-6

purchasePatronNFTEther could be payable

Topic
Use Cases
Status
Wont Do
Quality Impact
Low

The purchasPatronNFTEther() function in the PurchaseApp is currently not payable, requiring ETH to be sent before calling the function. Consider making this function payable to support making this call and providing the required _purchaseTotalAmount of native assets within one operation.

Response by Infinex

For the way the platform will call this function, we will first transfer eth to the app account using transferEthToApp on the main account (app module) and then call purchasePatronNFTEther on the app account. It is not intended to be called directly.

Disclaimer

Macro makes no warranties, either express, implied, statutory, or otherwise, with respect to the services or deliverables provided in this report, and Macro specifically disclaims all implied warranties of merchantability, fitness for a particular purpose, noninfringement and those arising from a course of dealing, usage or trade with respect thereto, and all such warranties are hereby excluded to the fullest extent permitted by law.

Macro will not be liable for any lost profits, business, contracts, revenue, goodwill, production, anticipated savings, loss of data, or costs of procurement of substitute goods or services or for any claim or demand by any other party. In no event will Macro be liable for consequential, incidental, special, indirect, or exemplary damages arising out of this agreement or any work statement, however caused and (to the fullest extent permitted by law) under any theory of liability (including negligence), even if Macro has been advised of the possibility of such damages.

The scope of this report and review is limited to a review of only the code presented by the Infinex team and only the source code Macro notes as being within the scope of Macro’s review within this report. This report does not include an audit of the deployment scripts used to deploy the Solidity contracts in the repository corresponding to this audit. Specifically, for the avoidance of doubt, this report does not constitute investment advice, is not intended to be relied upon as investment advice, is not an endorsement of this project or team, and it is not a guarantee as to the absolute security of the project. In this report you may through hypertext or other computer links, gain access to websites operated by persons other than Macro. Such hyperlinks are provided for your reference and convenience only, and are the exclusive responsibility of such websites’ owners. You agree that Macro is not responsible for the content or operation of such websites, and that Macro shall have no liability to your or any other person or entity for the use of third party websites. Macro assumes no responsibility for the use of third party software and shall have no liability whatsoever to any person or entity for the accuracy or completeness of any outcome generated by such software.