Platform: Code4rena
Start Date: 13/02/2024
Pot Size: $24,500 USDC
Total HM: 5
Participants: 84
Period: 6 days
Judge: 0xA5DF
Id: 331
League: ETH
Rank: 47/84
Findings: 1
Award: $38.68
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xAadi
Also found by: 0xbrett8571, DarkTower, JcFichtner, JrNet, MrPotatoMagic, PoeAudits, TheSavageTeddy, ZanyBonzy, clara
38.6789 USDC - $38.68
Summary:
Section | Summary |
---|---|
Protocol Description | Tokenization and investment in real-world assets on Althea-L1 blockchain. |
Comments for the Judge | Thorough documentation; contracts analyzed for security and functionality. |
Approach Taken | Detailed review of codebase for adherence to best practices and security considerations. |
Architecture Recommendations | Optimize gas efficiency, enhance access control, and improve interoperability. |
Codebase Quality Analysis | Structured implementation with potential improvements in gas usage and access control. |
Centralization Risks | Owner's control over contract poses centralization risks. Multisig wallet recommended. |
Mechanism Review | Innovative revenue distribution with potential gas limit issues. |
Systemic Risks | Identified vulnerabilities require comprehensive testing and auditing. |
The Liquid Infrastructure protocol aims to revolutionize the tokenization and investment landscape by facilitating the representation and investment in real-world assets on the Althea-L1 blockchain. It introduces a novel approach to tokenizing tangible assets, allowing users to invest in assets that accrue revenue on-chain. Key components of the protocol include the LiquidInfrastructureNFT contracts, which serve as representations of tokenized real-world assets, and the LiquidInfrastructureERC20 token, which acts as a mechanism for aggregating and distributing revenue to token holders.
The protocol's primary focus is on tokenizing physical assets such as routers, vending machines, renewable energy infrastructure, and electric car chargers. However, it also aims to support ERC20 stablecoins for revenue distribution, thereby expanding its utility and adoption potential. Leveraging the Althea-L1 blockchain, which features an EVM compatibility layer, the protocol enables seamless interaction between on-chain assets and the broader blockchain ecosystem.
The documentation provided offers comprehensive insights into the Liquid Infrastructure protocol, covering its objectives, functionality, and potential security considerations. Furthermore, the analyzed contracts exhibit innovative features and security measures, showcasing a robust foundation for the protocol's implementation and deployment.
Our evaluation of the codebase involved a meticulous and systematic approach, focusing on security, functionality, and adherence to industry best practices. Each contract underwent thorough scrutiny, with particular attention to potential vulnerabilities and optimization opportunities. We leveraged a combination of manual inspection and automated analysis tools to ensure a comprehensive assessment of the protocol's codebase.
To enhance the protocol's architecture, several recommendations are proposed. Firstly, optimizing gas efficiency in contracts such as LiquidInfrastructureERC20 can mitigate concerns regarding gas limit issues during transactions. Secondly, enhancing access control mechanisms, particularly in contracts with centralized control, can reduce centralization risks and enhance protocol decentralization. Additionally, efforts should be made to improve interoperability with other blockchain networks to broaden the protocol's utility and adoption.
Gas Efficiency Optimization: Implement gas-efficient algorithms and data structures to minimize transaction costs.
Access Control Enhancement: Introduce role-based permission systems to distribute decision-making authority and mitigate centralization risks.
Interoperability Improvement: Enhance compatibility with external systems and blockchain networks to facilitate seamless asset transfer and interaction.
The codebase demonstrates structured implementation, with potential enhancements in gas usage and access control. Refinement in these areas, along with thorough testing and auditing, is essential to ensure correct handling of edge cases and address potential vulnerabilities.
LiquidInfrastructureERC20.sol
: The provided Solidity code defines a smart contract named LiquidInfrastructureERC20
which is an ERC20 token with additional features to manage revenue distribution from associated NFTs representing real-world infrastructure assets. The contract inherits from OpenZeppelin's ERC20, ERC20Burnable, Ownable, ERC721Holder, and ReentrancyGuard contracts.
Key features and potential security considerations:
Revenue Distribution: The contract is designed to collect revenue from managed LiquidInfrastructureNFTs and distribute it to token holders. The distribution is based on the number of tokens each holder owns.
Locking Mechanism: The contract can be locked during distributions to prevent transfers, minting, and burning of tokens. This is to ensure that the distribution process is not disrupted by changes in token ownership or supply.
Allowlist: There is a whitelist (HolderAllowlist
) of addresses that are allowed to hold the ERC20 tokens. This restricts who can receive and hold the tokens.
Minimum Distribution Period: The contract enforces a minimum number of blocks (MinDistributionPeriod
) that must elapse before a new distribution can begin. This prevents continuous locking and unlocking of the token.
Managed NFTs: The contract keeps track of ManagedNFTs
which are NFTs representing infrastructure assets. These NFTs generate revenue that is distributed to token holders.
Withdrawal from NFTs: The contract can withdraw balances from the managed NFTs to itself, which are then used for distribution to token holders.
Minting and Burning: The contract owner can mint new tokens and token holders can burn their tokens. However, these actions are restricted during distributions and must comply with the minimum distribution period.
Events: The contract emits various events for key actions such as distributions, withdrawals, and changes in managed NFTs, which aids in transparency and tracking of contract activities.
Potential security flaws and considerations:
Gas Limit: The distributeToAllHolders
function attempts to distribute to all holders in a single transaction, which could exceed the block gas limit if there are too many holders. This could make the function fail and lock the contract in a state where distributions cannot be completed.
Centralization Risk: The contract owner has significant control over the contract, including the ability to mint tokens, approve or disapprove holders, and manage NFTs. This centralization could be a risk if the owner's address is compromised.
Reentrancy Protection: The contract uses ReentrancyGuard
to prevent reentrancy attacks, which is a good security practice.
Division Before Multiplication: In the _beginDistribution
function, the entitlement is calculated by dividing the balance by the total supply before multiplying by the holder's balance. This could lead to rounding errors and loss of precision, potentially disadvantaging token holders.
Removal from ManagedNFTs: The releaseManagedNFT
function contains a require(true, "unable to find released NFT in ManagedNFTs");
statement which will always pass. This seems to be a mistake and should be corrected to ensure that the NFT is actually found and removed from the ManagedNFTs
array.
Approval Checks: The contract checks whether the recipient is on the allowlist in _beforeTokenTransfer
, which is good practice. However, it does not check if the sender is approved before transferring, which could be an issue if the sender's approval is revoked after receiving tokens.
Overall, the contract introduces an innovative way to distribute revenue from NFTs to token holders. However, it is crucial to address the potential gas limit issue during distributions and ensure that the centralization risks are mitigated, possibly by introducing a multisig wallet for the owner's address. Additionally, the code should be thoroughly tested, especially the distribution logic, to ensure that all edge cases are handled correctly.
LiquidInfrastructureNFT.sol
: The Solidity code provided defines a smart contract named LiquidInfrastructureNFT
that inherits from ERC721 and a custom contract OwnableApprovableERC721
. This contract is designed to interact with a Cosmos-based blockchain through Althea's x/microtx
module, which enables microtransactions within Althea networks. The contract is intended to represent a Liquid Infrastructure Account on the Cosmos network, which is associated with automated services like providing internet access.
Here's a breakdown of the contract's functionality and potential security considerations:
Versioning and Token ID: The contract defines a constant Version
to track the contract's version and a constant AccountId
with a value of 1, which represents the single NFT token ID that this contract will manage.
Constructor: The constructor takes an accountName
as a parameter, which is used to construct the token URI and symbol for the ERC721 token. It mints the single NFT to the msg.sender
.
Thresholds: The contract maintains arrays of ERC20 addresses (thresholdErc20s
) and corresponding balance thresholds (thresholdAmounts
). These are used by the x/microtx
module to determine how much of each token should be left in the Cosmos bank account associated with the NFT. Excess tokens are transferred to this contract.
Setting Thresholds: The setThresholds
function allows the owner or an approved address to update the threshold values. It requires that the arrays of new ERC20 addresses and amounts have the same length. The function clears the existing thresholds before setting the new ones.
Withdrawal Functions: The contract includes functions to withdraw ERC20 token balances (withdrawBalances
and withdrawBalancesTo
) to the owner's address or a specified destination. These functions are access-controlled and can only be called by the owner or an approved address.
Recovery Process: The recoverAccount
function is used to initiate a recovery process in case the device or wallet associated with the NFT is lost. It emits a TryRecover
event, which should be detected by
the x/microtx
module, triggering the transfer of all tokens from the Cosmos bank account to this contract.
Security Considerations:
Access Control: The contract uses a custom OwnableApprovableERC721
for access control, which should be audited to ensure it correctly restricts access to sensitive functions.
Event Reliance: The contract relies on events (TryRecover
) to trigger off-chain actions. It's important to ensure that the off-chain infrastructure monitoring these events is secure and reliable.
Array Length Checks: The setThresholds
function correctly checks that the lengths of the input arrays match, which is a good security practice to prevent mismatches in related data.
ERC20 Transfer Checks: The contract checks the return value of ERC20 transfer calls, which is important to ensure that transfers are successful.
Delete Before Update: The setThresholds
function deletes the existing thresholds before setting new ones, which prevents any stale or unwanted data from persisting.
Overall, the contract appears to be well-structured with appropriate security checks in place. However, a full security audit would require examining the entire codebase, including the imported contracts and the custom OwnableApprovableERC721
contract, as well as understanding the off-chain components that interact with this contract. Additionally, it's important to consider the gas costs associated with operations, especially those involving loops and array manipulations, to prevent potential denial-of-service attacks due to out-of-gas errors.
OwnableApprovableERC721.sol
: The provided Solidity code defines an abstract contract named OwnableApprovableERC721
that extends the functionality of an ERC721 token by adding two access control modifiers: onlyOwner
and onlyOwnerOrApproved
. This contract is designed to be used as a base for other contracts that require these specific access control mechanisms.
Here's a breakdown of the code:
The contract inherits from Context
and ERC721
, both of which are imported from the OpenZeppelin contracts library. Context
provides information about the current execution context, including the sender of the transaction (_msgSender()
). ERC721
is the standard implementation of the ERC721 token interface.
The onlyOwner
modifier is used to restrict the execution of functions to the owner of a specific token ID. It uses the ownerOf
function from the ERC721 standard to check if the message sender is the owner of the token. If not, it reverts with an error message.
The onlyOwnerOrApproved
modifier extends the access control to not only the owner of the token but also to an address that has been approved by the owner. It uses the _isApprovedOrOwner
internal function from the ERC721 standard to check if the message sender is either the owner or an approved operator for the token. If not, it reverts with an error message.
Potential Security Flaws:
The contract itself does not have any glaring security flaws in the code provided. However, it is important to note that the security of this contract also depends on the correct implementation of the ERC721 functions it relies on (ownerOf
and _isApprovedOrOwner
). If the ERC721 contract has vulnerabilities, they could be inherited by this contract.
The contract assumes that the ERC721 token has correctly implemented the ownership and approval checks. If there are bugs in those implementations, they could lead to unauthorized access to functions protected by the onlyOwner
and onlyOwnerOrApproved
modifiers.
The contract uses the revert
statement with a custom error message. While this is not a security flaw, it does increase the gas cost for failed transactions compared to a simple revert()
without a message.
Since the contract is abstract, it does not have a constructor or any state variables. The security of the contract will also depend on how the inheriting contract initializes and manages its state.
The contract does not implement any functionality beyond the modifiers; thus, the security of the functions that use these modifiers will depend on their implementation in the derived contracts.
Overall, the code is straightforward and follows good practices by using OpenZeppelin's secure and audited contracts. However, a comprehensive audit of the entire contract, including derived contracts, is necessary to ensure security, especially in the context of how these modifiers are used and whether the ERC721 implementation is secure.``
Centralization risks are primarily associated with contracts where the owner has significant control over critical functions. In LiquidInfrastructureERC20, the owner's control over minting, approval, and management of NFTs poses centralization risks, especially if the owner's address is compromised. Introducing a multisig wallet for critical functions can distribute decision-making authority and mitigate centralization risks.
Contract Owner Control: The owner's authority over minting, approval, and NFT management poses centralization risks.
Multisig Wallet Implementation: Introduce multisig wallets for critical functions to distribute decision-making authority and enhance protocol decentralization.
Security Auditing: Conduct comprehensive security audits to identify and mitigate potential vulnerabilities associated with centralized control.
The revenue distribution mechanism from NFTs to token holders introduces an innovative approach to decentralized finance. However, several aspects require careful review and potential optimization to ensure efficiency, reliability, and security.
One primary concern is the potential for gas limit issues during distributions, particularly in the distributeToAllHolders
function. Attempting to distribute to all holders in a single transaction could exceed the block gas limit, resulting in transaction failures. Optimizing gas usage in distribution functions is crucial to mitigate this risk and ensure seamless operation under varying conditions.
Thorough testing of the distribution logic is essential to validate its correctness and reliability. Testing should cover various scenarios and edge cases, including different numbers of token holders and potential failure scenarios. By simulating diverse conditions, developers can identify and address potential issues, ensuring the robustness of the distribution mechanism.
Addressing potential vulnerabilities, such as gas limit constraints and centralization risks, is critical to maintaining protocol integrity and security. Mitigation strategies may include gas optimization techniques, decentralization measures, and comprehensive security audits to identify and remedy potential vulnerabilities.
Identified vulnerabilities in contracts pose systemic risks to the protocol's security and stability, potentially undermining its integrity and functionality. Comprehensive measures are required to address these risks effectively and safeguard the protocol against potential threats.
Comprehensive testing and auditing are essential to identify and mitigate potential vulnerabilities in the protocol's codebase. Testing should cover various scenarios and edge cases, including potential failure scenarios, to ensure the robustness and reliability of the protocol under diverse conditions.
Architectural improvements, such as enhancing access control mechanisms and optimizing gas usage, are necessary to mitigate systemic risks and enhance protocol security. Measures may include the introduction of role-based permission systems, gas-efficient algorithms, and interoperability enhancements to broaden the protocol's utility and adoption.
Ensuring the robustness of off-chain infrastructure is crucial to the protocol's security and reliability. Off-chain components should be thoroughly tested and audited to prevent potential vulnerabilities and ensure seamless integration with on-chain protocols. Continuous monitoring and maintenance of off-chain infrastructure are necessary to detect and address potential issues promptly.
9 hours
#0 - c4-pre-sort
2024-02-22T19:16:07Z
0xRobocop marked the issue as insufficient quality report
#1 - c4-judge
2024-03-08T14:32:35Z
0xA5DF marked the issue as grade-b