reNFT - SAQ's results

Collateral-free, permissionless, and highly customizable EVM NFT rentals.

General Information

Platform: Code4rena

Start Date: 08/01/2024

Pot Size: $83,600 USDC

Total HM: 23

Participants: 116

Period: 10 days

Judge: 0xean

Total Solo HM: 1

Id: 317

League: ETH

reNFT

Findings Distribution

Researcher Performance

Rank: 18/116

Findings: 2

Award: $571.48

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: 0xAnah

Also found by: 0x11singh99, 0xhex, 0xta, SAQ, mgf15, shamsulhaq123, sivanesh_808, slvDev

Labels

bug
G (Gas Optimization)
grade-a
sufficient quality report
G-06

Awards

301.6239 USDC - $301.62

External Links

Summary

Gas Optimization

noIssueInstances
[G-01]Avoid contract existence checks by using low level calls8-
[G-02]<X> += <Y> COSTS MORE GAS THAN <X> = <X> + <Y> FOR STATE VARIABLES or ( -= )2-
[G-03]Multiplication/division by two should use bit shifting3-
[G-04]Not using the named return variable when a function returns, wastes deployment gas1-
[G-05]Can make the variable outside the loop to save gas5-
[G-06]State varaibles only set in the Constructor should be declared Immutable1-
[G-07]With assembly, .call (bool success)  transfer can be done gas-optimized1-
[G-08]Using ERC721A instead of ERC721 for more gas-efficient8-
[G-09]Non efficient zero initialization2-
[G-10]Pre-increment and pre-decrement are cheaper than +1 ,-15-
[G-11]Use assembly for loops3-
[G-12]do-while is cheaper than for-loops when the initial check can be skipped5-
[G-13]Cache external calls outside of loop to avoid re-calling function on each iteration3-
[G-14]Gas savings can be achieved by changing the model for assigning value to the structure 123 gas1-
[G-15]Use assembly in place of abi.decode to extract calldata values more efficiently2-

Gas Optimizations

[G-01] Avoid contract existence checks by using low level calls

file:

102        (bool success, bytes memory data) = token.call(
103            abi.encodeWithSelector(IERC20.transfer.selector, to, value)

116            revert Errors.PaymentEscrowModule_PaymentTransferFailed(token, to, value);

268                    (orderType.isPayOrder() && isRentalOver) || orderType.isBaseOrder()

279                    revert Errors.Shared_OrderTypeNotSupported(uint8(orderType));

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L116C1-L116C87

file: /packages/Reclaimer.sol

33        IERC721(item.token).safeTransferFrom(address(this), recipient, item.identifier);

74            revert Errors.ReclaimerPackage_OnlyDelegateCallAllowed();

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Reclaimer.sol#L33C1-L33C89

file: /packages/Signer.sol

112        bytes32 digest = _DOMAIN_SEPARATOR.toTypedDataHash(payloadHash);

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Signer.sol#L112C1-L112C73

file:/policies/Create.sol

124         ISafe(address(this)).enableModule(_stopPolicy);

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L124

[G-02] <X> += <Y> COSTS MORE GAS THAN <X> = <X> + <Y> FOR STATE VARIABLES or ( -= )

file: /modules/PaymentEscrow.sol

306        balanceOf[token] += amount;

294        balanceOf[token] -= amount;

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L306C1-L306C36

[G-03] Multiplication/division by two should use bit shifting

<x> * 2 is the same as <x> << 1. While the compiler uses the SHL opcode to accomplish both, the version that uses multiplication incurs an overhead of 20 gas due to JUMPs to and from a compiler utility function that introduces checks which can be avoided by using unchecked {} around the division by two.

<x> / 2 is the same as <x> >> 1. While the compiler uses the SHR opcode to accomplish both, the version that uses division incurs an overhead of  20 gas due  to JUMPs to and from a compiler utility function that introduces checks which can be avoided by using unchecked {} around the division by two.

file: /modules/PaymentEscrow.sol

90        return (amount * fee) / 10000;

138        uint256 numerator = (amount * elapsedTime) * 1000;

142        renterAmount = ((numerator / totalTime) + 500) / 1000;

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L90C1-L90C39

[G-04] Not using the named return variable when a function returns, wastes deployment gas

file: /Create2Deployer.sol

94         return address(uint160(uint256(addressHash)));

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Create2Deployer.sol#L94C1-L94C55

[G-05] Can make the variable outside the loop to save gas

Consider making the stack variables before the loop which gonna save gas

file:/modules/PaymentEscrow.sol

233            Item memory item = items[i];

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L233C1-L233C41

file: /src/packages/Accumulator.sol

122            RentalId rentalId;

123            uint256 amount;

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Accumulator.sol#L122C1-L123C28

file: /policies/Create.sol

263            SpentItem memory offer = offers[i];

377            ReceivedItem memory consideration = considerations[i];

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L263C1-L263C48

[G-06] State varaibles only set in the Constructor should be declared Immutable

file: /Kernel.sol

34        kernel = kernel_;

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Kernel.sol#L34C1-L34C26

[G-07] With assembly, .call (bool success)  transfer can be done gas-optimized

file: /modules/PaymentEscrow.sol

102  (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.transfer.selector, to, value)
        );

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L102C6-L104C11

[G-08] Using ERC721A instead of ERC721 for more gas-efficient

ERC721A is a proposed extension to the ERC721 standard that aims to improve gas efficiency and reduce the cost of deploying and using non-fungible tokens (NFTs) on the Ethereum blockchain. 

file: /packages/Reclaimer.sol

33        IERC721(item.token).safeTransferFrom(address(this), recipient, item.identifier);

94            if (item.itemType == ItemType.ERC721)

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Reclaimer.sol#L33C1-L33C89

file: /policies/Create.sol

269                itemType = ItemType.ERC721;

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L269C1-L269C44

[G-09] Non efficient zero initialization

Solidity does not recognize null as a value, so uint variables are initialized to zero. Setting a uint variable to zero is redundant and can waste gas.

file: /modules/PaymentEscrow.sol

231        for (uint256 i = 0; i < items.length; ++i) {

341        for (uint256 i = 0; i < orders.length; ++i) {    

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L231C1-L231C53

[G-10] Pre-increment and pre-decrement are cheaper than +1 ,-1

file: /policies/Create.sol

184                uint256(keccak256(abi.encode(STORE.totalSafes() + 1, block.chainid)))

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#184

file: /src/Kernel.sol

431        getPolicyIndex[policy_] = activePolicies.length - 1;

445            getDependentIndex[keycode][policy_] = moduleDependents[keycode].length - 1;

469        Policy lastPolicy = activePolicies[activePolicies.length - 1];

601            Policy lastPolicy = dependents[dependents.length - 1];

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Kernel.sol#L431C1-L431C61

[G-11] Use assembly for loops

In the following instances, assembly is used for more gas efficient loops. The only memory slots that are manually used in the loops are scratch space (0x00-0x20), the free memory pointer (0x40), and the zero slot (0x60). This allows us to avoid using the free memory pointer to allocate new memory, which may result in memory expansion costs.

file: /modules/PaymentEscrow.sol

341       for (uint256 i = 0; i < orders.length; ++i) {
            // Settle all payments for the order.
            _settlePayment(
                orders[i].items,
                orders[i].orderType,
                orders[i].lender,
                orders[i].renter,
                orders[i].startTimestamp,
                orders[i].endTimestamp
            );
        }
    }

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L341C1-L352C6

file: /packages/Signer.sol

176    for (uint256 i = 0; i < order.hooks.length; ++i) {
            // Hash the hook.
            hookHashes[i] = _deriveHookHash(order.hooks[i]);
        }

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Signer.sol#L176C4-L179C10

file: /policies/Create.sol#

337    for (uint256 i; i < considerations.length; ++i) {
            // Get the consideration item.
            ReceivedItem memory consideration = considerations[i];

            // Only process an ERC20 item.
            if (!consideration.isERC20()) {
                revert Errors.CreatePolicy_SeaportItemTypeNotSupported(
                    consideration.itemType
                );
            }

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L337C6-L346C14

[G-12] do-while is cheaper than for-loops when the initial check can be skipped

for (uint256 i; i < len; ++i){ ... } -> do { ...; ++i } while (i < len);

file: /modules/PaymentEscrow.sol

231        for (uint256 i = 0; i < items.length; ++i) {

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L231C1-L231C53

file: /packages/Accumulator.sol

120        for (uint256 i = 0; i < rentalAssetUpdateLength; ++i) {

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Accumulator.sol#L120C1-L120C64

file: /packages/Reclaimer.sol

90        for (uint256 i = 0; i < itemCount; ++i) {

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Reclaimer.sol#L90

file: /policies/Stop.sol

205         for (uint256 i = 0; i < hooks.length; ++i) {

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Stop.sol#L205C1-L205C53

file: /Kernel.sol

566        for (uint256 i = 0; i < reqLength; ++i) {
            // Set the permission for the keycode -> policy -> function selector.
            Permissions memory request = requests_[i];
            modulePermissions[request.keycode][policy_][request.funcSelector] = grant_;

            emit Events.PermissionsUpdated(
                request.keycode,
                policy_,
                request.funcSelector,
                grant_
            );
        }
    }

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Kernel.sol#L566C1-L578C6

[G-13] Cache external calls outside of loop to avoid re-calling function on each iteration

file: /modules/PaymentEscrow.sol

266                    (orderType.isPayOrder() && isRentalOver) || orderType.isBaseOrder()

279                    revert Errors.Shared_OrderTypeNotSupported(uint8(orderType));

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L268C1-L268C88

file: /policies/Create.sol

343                revert Errors.CreatePolicy_SeaportItemTypeNotSupported(

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L343C1-L343C72

[G-14] Gas savings can be achieved by changing the model for assigning value to the structure 123 gas

Change this structName a = structName({item1: val1,item2: val2}); ==> structName a; a.item1 = val1; a.item2 = val2;

file: /policies/Create.sol

228       rentalItems[i + startIndex] = Item({
                itemType: itemType,
                settleTo: SettleTo.LENDER,
                token: offer.token,
                amount: offer.amount,
                identifier: offer.identifier
            });

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L228C12-L234C16

[G-15] Use assembly in place of abi.decode to extract calldata values more efficiently

Instead of using abi.decode, we can use assembly to decode our desired calldata values directly. This will allow us to avoid decoding calldata values that we will not use. For more details on how to implement this, check the following report

file: /modules/PaymentEscrow.sol

115        if (!success || (data.length != 0 && !abi.decode(data, (bool)))) {

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol#L115C1-L115C75

file: /src/policies/Create.sol

737      (RentPayload memory payload, bytes memory signature) = abi.decode(
            zoneParams.extraData,
            (RentPayload, bytes)
        );

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol#L737C3-L740C11

#0 - c4-pre-sort

2024-01-21T18:26:13Z

141345 marked the issue as sufficient quality report

#1 - 141345

2024-01-22T08:44:31Z

569 SAQ l r nc 2 0 9

G 1 b G 2 b G 3 n G 4 b G 5 n G 6 l G 7 n G 8 n G 9 n G 10 i G 11 n G 12 n G 13 l G 14 n G 15 n

#2 - c4-judge

2024-01-27T20:20:58Z

0xean marked the issue as grade-a

Findings Information

Awards

269.8643 USDC - $269.86

Labels

analysis-advanced
grade-a
sufficient quality report
A-09

External Links

Summary

noFile
[File-1]PaymentEscrow.sol
[File-2]Accumulator.sol
[File-3]Reclaimer.sol
[File-4]Signer.sol
[File-5]Admin.sol
[File-6]Create.sol
[File-7]policies/Factory.sol
[File-8]Guard.sol
[File-9]Stop.sol
[File-10]Create2Deployer.sol
[File-11]Kernel.sol

Analysis Issue Report

[File-1]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/modules/PaymentEscrow.sol

Admin Abuse Risks:

The PaymentEscrow contract has an owner and can be configured by an admin. Admin abuse risks may arise if the owner or admins misuse their privileges, such as setting an unreasonable fee or skimming funds. The setFee and skim functions are potential points of admin abuse if not properly monitored and controlled.

Systemic Risks:

The contract handles payment escrow for rental orders, and systemic risks may arise if there are flaws in the payment settlement logic. The calculation of fees and payment distribution needs to be accurate to ensure fair and secure transactions.

Technical Risks:

The safeTransfer function is used for transferring ERC-20 tokens, and it relies on the external token contract to return a boolean value indicating the success of the transfer. If a token's transfer function does not consistently return true/false, there might be potential issues.

Integration Risks:

The contract interacts with external ERC-20 tokens. If there are changes or issues with the ERC-20 standards of these tokens, it may lead to integration risks. Moreover, any systems relying on this contract's functionality need to be aware of the payment settlement mechanisms.

Non-Standard Token Risks:

The contract doesn't explicitly handle non-standard ERC-20 tokens. It assumes the standard transfer function `IERC20.transfer``. If non-standard tokens are intended to be supported, additional checks and handling might be necessary.

Additional Notes:

The contract is designed to be upgradeable, allowing for future improvements or bug fixes. However, the upgrade mechanism should be handled with caution, and freezing is available to prevent further upgrades.

Suggestions:

Implement access control mechanisms for critical functions to minimize admin abuse risks. Ensure proper testing of the payment settlement logic to prevent systemic risks. Consider additional checks for non-standard ERC-20 tokens if they are within the scope of the contract. Provide comprehensive documentation for users and developers interacting with this contract. Ensure that upgrades are thoroughly tested, and the freezing mechanism is used judiciously.

Overall:

The PaymentEscrow contract appears to provide a comprehensive solution for managing payments in rental orders. Admin abuse risks, systemic risks, and technical risks should be carefully addressed, and the contract should be well-documented to facilitate integration by other systems.

[File-2]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Accumulator.sol

Admin Abuse Risks:

The Accumulator contract is an abstract contract and does not have explicit admin-related functions or state variables. Admin abuse risks are not applicable in this context.

Systemic Risks:

The contract is designed for managing dynamically allocated data struct arrays in memory. Systemic risks may arise if there are errors in the implementation of the _insert and _convertToStatic functions, leading to incorrect accumulation or conversion of data.

Technical Risks:

The _insert and _convertToStatic functions use inline assembly to manipulate memory directly. Technical risks include the potential for errors in memory management, pointer arithmetic, or misalignment that could result in unexpected behavior.

Integration Risks:

Developers integrating this contract into their systems need to be aware of the memory manipulation mechanisms used in _insert and _convertToStatic. If not used correctly, it may lead to integration risks

Non-Standard Token Risks:

The contract does not interact with tokens or token standards. It is focused on managing dynamically allocated data in memory. Non-standard token risks are not applicable in this context.

Additional Notes:

The Accumulator contract is abstract, suggesting that it is intended to be inherited by other contracts to provide the described functionality. The use of inline assembly introduces gas efficiency but requires careful attention to avoid vulnerabilities and bugs.

Suggestions:

Developers inheriting from Accumulator should thoroughly test and understand the functionality provided by _insert and _convertToStatic. Consider providing detailed documentation on how to use and integrate the contract. If the contract is part of a larger system, ensure that developers using it are aware of the memory manipulation techniques employed.

Overall:

The Accumulator contract appears to provide a flexible solution for managing dynamically allocated data struct arrays in memory. While it doesn't pose admin abuse risks, developers should exercise caution in handling memory-related operations and thoroughly test the integration into their systems.

[File-3]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Reclaimer.sol

Admin Abuse Risks:

The Reclaimer contract has a potential risk of admin abuse through the use of delegate calls. Since this contract relies on being delegate called by the rental safe, any contract with the ability to execute delegate calls can potentially misuse this functionality.

Systemic Risks:

There are potential systemic risks associated with the delegate call mechanism. If not properly implemented or secured, it may lead to unexpected behaviors, such as unauthorized reclaiming of assets.

Technical Risks:

The use of delegate calls introduces technical risks, especially when relying on the context of the calling address. If the context is not carefully managed or if there are vulnerabilities in the delegate call process, it could result in unintended actions.

Integration Risks:

Developers integrating this contract into a system should be cautious about the security implications of delegate calls and ensure that only authorized addresses can initiate reclaiming actions. Any vulnerabilities in the system that allows unauthorized delegate calls could lead to exploitation.

Non-Standard Token Risks:

The contract interacts with ERC721 and ERC1155 tokens, which are standard tokens. Non-standard token risks are not applicable in this context.

Additional Notes:

The contract's design assumes that the delegate call is only made by the rental safe, which is expected to be enforced by the system's policies. Ensure that the system's policies indeed prevent unauthorized delegate calls.

Suggestions:

Provide thorough documentation explaining the security measures in place to prevent unauthorized calls. Consider implementing access controls to restrict who can initiate the reclaiming process, ensuring it is only done by the intended rental safe.

Overall:

The Reclaimer contract provides functionality to reclaim rented assets from a wallet contract once a rental has been stopped. However, it introduces potential admin abuse risks and requires careful consideration of security measures, especially in managing delegate calls and context. Developers should exercise caution and thoroughly test the integration of this contract into their systems.

[File-4]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/packages/Signer.sol

Admin Abuse Risks:

The Signer contract appears to be focused on signature verification and payload validation, minimizing admin abuse risks. However, it is essential to ensure that the associated contracts and systems using these signatures have robust access controls.

Systemic Risks:

The systemic risks seem minimal as the contract is designed to handle signed payloads securely. However, the robustness of the system may depend on the overall architecture and how the signed payloads are used in the broader context.

Technical Risks:

The use of ECDSA for signature verification is a standard and secure practice. However, the overall security of the system relies on proper implementation and usage in the associated contracts. Any vulnerabilities in the contract using these signatures could introduce technical risks.

Integration Risks:

Developers integrating this contract into a system should carefully follow the provided guidelines for signature verification and payload validation. Integration risks may arise if there are inconsistencies or errors in the way the signed payloads are handled.

Non-Standard Token Risks:

The contract does not seem to directly interact with tokens, and thus, non-standard token risks are not applicable in this context.

Additional Notes:

The contract makes use of EIP-712 for typed data hashing, providing a standardized way to structure and hash complex data structures. It relies on ECDSA signatures to validate the authenticity of the payloads, ensuring that they are created by the expected parties.

Suggestions:

Provide thorough documentation for developers on how to use and integrate this contract securely. Encourage best practices for secure key management and storage of private keys associated with the signing process.

Overall:

The Signer contract appears to be well-structured for handling signed payloads and verifying signatures. While the risks are generally low within the scope of this contract, it is crucial to consider the security of the entire system in which these signatures are utilized. Developers should follow best practices and adhere to security guidelines when integrating and using this contract.

[File-5]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Admin.sol

Admin Abuse Risks:

The Admin contract poses admin abuse risks as it provides powerful functions that can manage the protocol's whitelist, upgrade modules, and control fees. Access control through the onlyRole("ADMIN_ADMIN") modifier aims to mitigate these risks.

Systemic Risks:

Systemic risks are present due to the critical role of the Admin contract in managing protocol-related configurations. The careful execution of functions and adherence to security practices are crucial to minimizing systemic risks.

Technical Risks:

The technical risks are associated with the upgrade functionality in both the Storage and PaymentEscrow modules. Upgrading must be carefully validated to avoid introducing vulnerabilities. The freezing mechanisms help mitigate risks by preventing further upgrades.

Integration Risks:

Developers integrating with the protocol need to be cautious when interacting with the Admin contract. Proper understanding and usage of the functions, especially those related to module upgrades and fee settings, are essential to avoid integration risks.

Non-Standard Token Risks:

The contract interacts with tokens through the PaymentEscrow module, and the risks associated with token interactions are mainly governed by the implementation of the PaymentEscrow contract.

Additional Notes:

The contract follows a modular approach by depending on other contracts Storage and PaymentEscrow. It leverages these modules for storage and payment-related functionalities. The protocol fee-related functions setFee and skim should be used with caution, as they can impact the economic model of the protocol.

Suggestions:

Provide comprehensive documentation for developers, explaining the proper usage and potential risks associated with each function. Encourage a thorough review of the upgrade mechanisms, ensuring they conform to best practices and security standards. Consider additional checks and validations in critical functions to enhance the security posture. Consider adding emergency mechanisms or pause functionality in case of unexpected issues or vulnerabilities.

Overall:

The Admin contract plays a pivotal role in managing critical aspects of the protocol. Developers and administrators must exercise caution and adhere to best practices when interacting with this contract to minimize potential risks and ensure the overall security of the protocol. Regular audits and continuous monitoring are advisable to identify and address any emerging security concerns.

[File-6]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Create.sol

Admin Abuse Risks:

1- Access Control: The contract utilizes a role-based access control mechanism through the OpenZeppelin Policy contract, where certain functions are restricted to roles like "SEAPORT" and "CREATE_SIGNER". Ensure that these roles are assigned securely, and their usage does not lead to admin abuse.

Systemic Risks:

1- Dependency on External Contracts: The contract relies on various external contracts like ISafe, IHook, IZone, Storage, and PaymentEscrow. Ensure these contracts are trustworthy and well-audited, as any vulnerabilities in them could impact the functioning of the current contract.

Technical Risks:

1- Version Compatibility: The contract specifies pragma solidity ^0.8.20. Ensure compatibility with this version and consider upgrading to newer compiler versions for potential optimizations and security improvements.

Integration Risks:

1- Interface Dependencies: The contract interacts with other contracts using external interfaces (ISafe, IHook, IZone, etc.). Make sure that these interfaces are consistent with the expected behavior and that the connected contracts are correctly

Non-Standard Token Risks:

1- Token Standards: The contract appears to handle ERC-20, ERC-721, and ERC-1155 tokens. Ensure that the contract works correctly with tokens adhering to these standards. Additionally, confirm that it handles non-standard tokens appropriately if that's in scope.

Overall Recommendations:

Security Audits: Conduct thorough security audits, considering both the current contract and its dependencies. Role Assignments: Ensure that roles are assigned and managed securely to prevent unauthorized access. Interface Compatibility: Verify that the contract interfaces with other contracts are consistent with their implementations. Testing: Rigorously test the contract in different scenarios, including edge cases, to identify potential vulnerabilities. Code Comments: Consider adding or improving comments to enhance the code's readability and aid future audits.

[File-7]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Factory.sol

Admin Abuse Risks:

1- STORE Module Configuration: The configureDependencies function is responsible for configuring dependencies. However, if the kernel or other relevant modules' addresses can be changed by an admin, it may pose a risk. Ensure that module upgrades are restricted and appropriately controlled.

2- Permissions: The requestPermissions function requests permissions from the kernel. Admin abuse risks could arise if these permissions are overly permissive or if the permissions themselves can be modified after deployment.

Systemic Risks:

1- Dependence on External Contracts: The contract relies on external contracts like TokenCallbackHandler, SafeProxyFactory, and SafeL2. Systemic risks may arise if these external contracts are compromised or behave unexpectedly.

Technical Risks:

1- Delegate Call: The comments in the code mention assumptions about delegate call restrictions. Ensure that the guard policy effectively prevents unauthorized delegate calls, as the security of the system depends on it.

2- Reentrancy: The contract deploys rental safes and interacts with external contracts. Be cautious about reentrancy issues, especially when dealing with external contracts and funds.

Integration Risks:

1- Module/Guard Contracts: The initializeRentalSafe function assumes certain conditions about the guard policy. Confirm that these conditions hold, as improper integration with the guard policy might compromise the security of rental safes.

Non-Standard Token Risks:

1- Payment Token Handling: The contract interacts with payment tokens during the safe deployment process. Ensure that the handling of payment tokens is secure, and consider potential risks related to non-standard tokens.

General Recommendations:

Ensure that the contract follows best practices, such as using the latest Solidity version, especially for security patches. Thoroughly test the contract, including edge cases and potential attack vectors. Consider adding comprehensive comments and documentation to enhance code readability and facilitate future audits.

[File-8]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Guard.sol

Admin Abuse Risks:

1- Module Configuration: The configureDependencies and requestPermissions functions involve setting dependencies and permissions. Admin abuse risks may arise if the kernel's address or the permissions are not properly restricted, allowing an attacker to manipulate the dependencies or permissions.

Systemic Risks:

1- External Contracts: The contract relies on external contracts such as BaseGuard and other contracts imported from external libraries (LibString, etc.). Systemic risks may arise if these external contracts are compromised or behave unexpectedly.

Technical Risks:

1- Delegate Call Restrictions: The contract checks for delegate call permissions. Ensure that the logic properly restricts delegate calls to authorized addresses, as unrestricted delegate calls could pose a significant security risk.

2- Hook Functionality: The contract interacts with external hooks (IHook), forwarding control flow to external contracts. The security of the system depends on the correctness and security of these hooks. Ensure proper validation and security measures in the hook contracts.

Integration Risks:

1- Transaction Checks: The _checkTransaction function imposes restrictions on specific function selectors and operations. Integration risks may arise if the restrictions are not well-defined or if there are unforeseen consequences related to token transfers or guard module changes.

Non-Standard Token Risks:

1- ERC-721 and ERC-1155 Transactions: The contract explicitly restricts certain transactions involving ERC-721 and ERC-1155 tokens. Non-standard tokens may pose risks if their behavior deviates from the expected ERC-721 or ERC-1155 standards.

General Recommendations:

Thoroughly review the external contracts and libraries to ensure their security and reliability. Ensure proper access control and permissions within the contract, especially in functions like updateHookPath and updateHookStatus. Consider additional checks for potential attack vectors, such as reentrancy protection and gas limits. Ensure that the delegate call restrictions are robust and that delegate calls cannot be abused. Conduct extensive testing, including edge cases and security scenarios, to identify and mitigate potential risks.

[File-9]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/policies/Stop.sol

Admin Abuse Risks:

Admin Abuse Risks: 1- Module Configuration: The configureDependencies and requestPermissions functions involve setting dependencies and permissions. Admin abuse risks may arise if the kernel's address, storage, or payment escrow modules are not properly restricted, allowing an attacker to manipulate dependencies or permissions.

Systemic Risks:

1- External Contracts: The contract relies on external contracts such as Policy, Signer, Reclaimer, `Accumulator, and other contracts imported from external libraries. Systemic risks may arise if these external contracts are compromised or behave unexpectedly.

Technical Risks:

1- Delegate Call Permissions: The contract checks for delegate call permissions in the ISafe interface. Ensure that the logic properly restricts delegate calls to authorized addresses, as unrestricted delegate calls could pose a significant security risk.

2- Hook Functionality: The contract interacts with external hooks (IHook), forwarding control flow to external contracts. The security of the system depends on the correctness and security of these hooks. Ensure proper validation and security measures in the hook contracts.

3- Rental Asset Handling: The functions _reclaimRentedItems and _removeHooks involve interactions with external contracts and modules. Ensure that these interactions are secure, and proper checks are in place to prevent unauthorized access.

Integration Risks:

1- Escrow Settlement: The stopRent and stopRentBatch functions involve settling payments from the escrow contract. Integration risks may arise if the settlement process is not well-defined or if there are unforeseen consequences related to payment transfers.

Non-Standard Token Risks:

1- Rental Asset Handling: The contract appears to handle both ERC-721 and ERC-20 tokens. Non-standard tokens may pose risks if their behavior deviates from the expected ERC-721 or ERC-20 standards.

General Recommendations:

Thoroughly review the external contracts and libraries to ensure their security and reliability. Ensure proper access control and permissions within the contract, especially in functions like stopRent and stopRentBatch. Consider additional checks for potential attack vectors, such as reentrancy protection and gas limits. Ensure that the delegate call restrictions are robust and that delegate calls cannot be abused. Conduct extensive testing, including edge cases and security scenarios, to identify and mitigate potential risks.

[File-10]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Create2Deployer.sol

Admin Abuse Risks:

1- Deployed Contracts Mapping: The deployed mapping is used to track whether a specific deployment address has already been used. Admin abuse risks may arise if there is a vulnerability that allows an administrator to manipulate the deployed mapping, potentially leading to unauthorized contract deployments.

Systemic Risks:

1- CREATE2 Functionality: The contract utilizes the CREATE2 opcode to deploy contracts. Systemic risks may arise if there are vulnerabilities related to the CREATE2 opcode, such as implementation issues or unexpected behavior.

Technical Risks:

1- Dependent on Assembly: The use of assembly (assembly { ... }) for contract deployment involves low-level operations. Technical risks may arise if there are errors or vulnerabilities in the assembly code, especially in the calculation of the deployment address.

2- Address Matching Check: The check to ensure that the first 20 bytes of the salt match the sender's address may be vulnerable to unexpected behavior or edge cases. Thorough testing is required to validate the effectiveness and security of this check.

Integration Risks:

1- Init Code Specification: The deploy function relies on the provided initCode for contract deployment. Integration risks may arise if there are issues with the format or content of the initCode, potentially leading to deployment failures or vulnerabilities.

2- Gas Limitations: The deploy function uses assembly for contract deployment, and gas limits should be carefully considered. Integration risks may arise if the gas required for deployment exceeds the block gas limit, leading to transaction failures.

General Recommendations:

Perform thorough testing, including edge cases and security scenarios, to identify and mitigate potential risks. Consider involving external security audits to review the contract's logic, especially the assembly code for contract deployment. Ensure proper access control and permissions within the contract, preventing unauthorized manipulation of critical data. Monitor updates to the Ethereum protocol and related opcodes for any changes that may affect the functionality of CREATE2. Include robust error handling mechanisms to gracefully handle unexpected situations during deployment.

[File-11]

The bellow issues related to the File ( Link )

https://github.com/re-nft/smart-contracts/blob/3ddd32455a849c3c6dc3c3aad7a33a6c9b44c291/src/Kernel.sol

Admin Abuse Risks:

1- Change Kernel Functionality: The migrateKernel function allows the migration of the kernel to a new contract. Admin abuse risks may arise if unauthorized parties gain control over this functionality, leading to a potential loss of control over policies and modules.

2- Role Management: The grantRole and revokeRole functions provide admin addresses the ability to grant or revoke roles. Admin abuse risks may occur if roles are not managed properly, leading to unauthorized access or changes in permissions.

Systemic Risks:

1- Dependencies Handling: The system relies on dependencies between policies and modules. Systemic risks may arise if there are vulnerabilities in handling these dependencies, potentially leading to inconsistencies or unexpected behavior during module upgrades or deactivations.

2- Permissions System: The modulePermissions mapping tracks permissions for policies to interact with modules. Systemic risks may occur if there are vulnerabilities in the permission system, leading to unauthorized access or misuse of functionalities.

Technical Risks:

1- KernelAdapter Inheritance: The use of the KernelAdapter abstract contract introduces technical risks if there are issues with the inheritance hierarchy. Careful consideration and testing are necessary to ensure proper functionality.

2- Keycode Handling: The handling of keycodes and their association with modules introduces technical risks. Proper validation and management of keycodes are essential to prevent unexpected issues during module installations or upgrades.

Integration Risks:

1- Module Initialization: The initialization of modules (INIT function) during installation or upgrade may introduce integration risks if there are issues with the initialization process. Proper testing and validation are required to ensure modules are initialized correctly.

2- Policy Configuration Dependencies: The configureDependencies function in policies relies on accurate configuration of dependencies. Integration risks may arise if policies are not configured correctly, leading to dependency-related issues.

Non-Standard Token Risks:

No non-standard tokens are directly involved in this contract.

General Recommendations:

Implement robust access control mechanisms for admin functions, ensuring that only authorized addresses can perform critical actions like kernel migration and role management. Conduct thorough testing, especially focusing on dependencies between policies and modules, to identify and address potential systemic risks. Regularly audit and review the permission system to ensure that policies have the correct permissions to interact with modules. Consider involving external security audits to review the contract's logic and identify any vulnerabilities. Ensure proper validation and handling of keycodes to prevent unexpected issues during module installations or upgrades. Implement upgradeable contracts cautiously, and thoroughly test the upgrade process to avoid disruptions in functionality.

Time spent:

12 hours

#0 - c4-judge

2024-01-27T20:26:48Z

0xean marked the issue as grade-a

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter