Security Audit
August 28, 2024
Version 1.0.0
Presented by 0xMacro
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.
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.
Our understanding of the specification was based on the following sources:
The changes audited rely on the following assumptions specifically.
nftQuantity
, recipient
, and vestingTier
) is signed.The following source code was reviewed during the audit:
7ab01b19d20e03ff991100d07414784e4f3a0ceb
ecaeef63f11cdf5a3639837eefd8abef223b5b73
Specifically, we audited the following contracts:
Source Code | SHA256 |
---|---|
./src/apps/patron-purchase/PatronPointOfPurchase.sol |
|
./src/apps/patron-purchase/PatronPointOfPurchaseStorage.sol |
|
./src/apps/patron-purchase/PatronPurchaseVault.sol |
|
./src/apps/patron-purchase/PatronPurchaseVaultStorage.sol |
|
./src/apps/patron-purchase/PurchaseApp.sol |
|
./src/apps/patron-purchase/PurchaseAppBeacon.sol |
|
./src/apps/patron-purchase/PurchaseError.sol |
|
Note: Currently the referenced repository is private, but there are plans to make it public in the future.
Click on an issue to jump to it, or scroll down to see them all.
finalizePurchasePatronNFTEther
msg.sender
to SuccessfulPatronNFTPurchase
event
reinitialize()
method
purchasePatronNFTEther
could be payable
We quantify issues in three parts:
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. |
finalizePurchasePatronNFTEther
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.
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.
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.
In PatronPointOfPurchase.initialize()
, consider using the local variable signer
instead of accessing the array element.
PatronPointOfPurchaseStorage._setAuthorizedSigner(**_authorizedSigners[i]**, true);
Reference: PatronPointOfPurchase.sol#L84
msg.sender
to SuccessfulPatronNFTPurchase
event
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.
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.
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.
reinitialize()
method
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.
We will not update it regularly. We would do a manual reinitialize for any new storage or functionality.
purchasePatronNFTEther
could be payable
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.
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 callpurchasePatronNFTEther
on the app account. It is not intended to be called directly.
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.