Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Audit] FM_PC_ExternalPrice_Redeeming, LM_ManualExternalPriceSetter_v1, #704

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

Zitzak
Copy link
Collaborator

@Zitzak Zitzak commented Dec 20, 2024

What needs to be audit.

The contracts that need to be audited are

  • FM_PC_ExternalPrice_Redeeming
  • LM_ManualExternalPriceSetter_v1
  • ERC20Issuance_Blacklist_v1

@Zitzak Zitzak added the audit a feature needs auditing label Dec 20, 2024
@Zitzak Zitzak force-pushed the feature/FM_PC_Oracle_Redeeming_v1 branch from dfede6f to 4c9bd6b Compare December 20, 2024 15:52
if (price_ == 0) revert Module__LM_ExternalPriceSetter__InvalidPrice();

// Normalize price to internal decimal precision.
_redemptionPrice = _normalizePrice(price_, _issuanceTokenDecimals);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs above, this should be the _collateralTokenDecimals, not _issuanceTokenDecimals.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confident the implementation is correct as is.

For redemption, we're pricing 'how many collateral tokens you get for 1 issuance token', so the input price should be in issuance token decimals, as stated in the documentation. This maintains consistency with the pricing model where 1 unit is always denominated in the issuance token.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feeds into the conversation about using the collateral price for all calculation see comment

redemptionAmount_,
address(token()),
block.timestamp,
RedemptionState.PROCESSING

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other states don't seem to really be used

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be used when integrated with a different module

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An indexer will be used to track state changes and redemption orders which will be visualized within our admin panel.

However the block.timestamp can probably be removed as recommended elsewhere, as those can be retrieved from the event


// Create and emit the order.
_createAndEmitOrder(
_receiver, _depositAmount, collateralRedeemAmount, issuanceFeeAmount

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issuanceFeeAmount is just one of the fees charged, it's unclear why it does not pass all fees combined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(jelle:) I thnk it is because the protocolFeeAmount, projectFeeAmount are taken from the collateral, and the issaunceFee from the issuance token.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right (jelle), we charge different fees here. The project fee can only be charged from the collateral while the protocol fee can be charge from issuance and collateral.

The event emitting the fee amount in the _createAndEmitOrder function serves the purpose of giving the project information they need for their users, as well as their admin panel.

However this question did reveal to me that what we should have been passing into the function is not the issuanceFeeAmount (which is part of the protocol fee), but the projectFeeAmount. So turns out to still be a great catch @omega-audits

public
override(BondingCurveBase_v1)
onlyModuleRole(WHITELIST_ROLE)
buyingIsEnabled

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buyingisenabled is also checked in super.buyFor, so it could be removed here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my point of view, we need it because the function is public and could be called directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to agree here with @omega-audits, as calling this function directly, as you're mentioning, will direct to the base buyFor where the modifier is located.

Could you please expand a bit on your point @vendrell46. Thank you

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    function buyFor(address _receiver, uint _depositAmount, uint _minAmountOut)
        public
        virtual
        override(BondingCurveBase_v1)
        validReceiver(_receiver)
        buyingIsEnabled
    {
        (uint amountIssued, uint collateralFeeAmount) =
            _buyOrder(_receiver, _depositAmount, _minAmountOut);
        _addVirtualIssuanceAmount(amountIssued);
        _addVirtualCollateralAmount(_depositAmount - collateralFeeAmount);
    }
    ```
    
    This is correct this is redundant and should be removed.

vendrell46 and others added 4 commits January 15, 2025 18:39
…20Issuance_Blacklist

* Contract structure defined

* removed IFundingManager extension

* IFundingManager_v1 needed

* extended IRedeemingBondingCurveBase_v1 as well

* ExternalPriceSetter, blacklist, Oracle and interfaces added

* formatting files and adapting to the code of conduct

* ManualExternalPriceSetter_v1 modified as LM

* added fees checks, paymentOrder to the process and defined role for blacklist

* managing roles, renaming, and removing unneeded things

* whitelist logic removed, blacklist fixes

* missing logic implemented

* blacklist fixes and custom error added

* switched from role to mapping for blacklist manager

* moved blacklist files to external, modified sell, and more context added

* PAYMENT_QUEUE_ROLE added, _sellOrder overriden

* emit_timestamp(IssuancePriceSet,RedemptionPriceSet),NatSpec

* fix: remove collateral transfer & collateral check

- The function `handleCollateralTokensAfterSell` was still expecting to
transfer collateral, which would revert in the current implementation.
- The _sellOrder` function had a conditional check which would let
the contract revert given there will not be any collateral in the
contract

* style: run make fmt for formating

* small fixes and documentation added

* docs added for issuance and redemption setters

* Rename ERC20Issuance_blacklist_v1.sol to ERC20Issuance_Blacklist_v1.sol

* Rename IERC20Issuance_blacklist_v1.sol to IERC20Issuance_Blacklist_v1.sol

* fixed executeRedemptionQueue, docs and renaming

* formatting natspec

* feat: add treasury collateral withdraw

* Fix fmt

* fix: typo

* fix: fmt

* fix: remove oracle from init

* fixed natspec

* modifier moved

* feat: update openRedemptionAmount

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* applied suggestions

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* formatting

* Update src/modules/fundingManager/oracle/interfaces/IFM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* formatting

* Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* formatting

* Modifier buyingIsEnabled and sellingIsEnabled added

* formatting, updating code from parent and adding interface check

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/ERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/interfaces/ILM_ManualExternalPriceSetter_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/interfaces/ILM_ManualExternalPriceSetter_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/external/token/interfaces/IERC20Issuance_Blacklist_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/FM_PC_ExternalPrice_Redeeming_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/LM_ManualExternalPriceSetter_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* Update src/modules/fundingManager/oracle/LM_ManualExternalPriceSetter_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* formatting

* formatting

* moved constants

* changed notice to dev

* adding named returned variable

* modifier renamed and buyingIsEnabled added to buy

* return named variables to interface

* formatting

* fix: revert during deployment

* fix issue with authorization

* fix: interface check

* interface natspec same as contract

* line too long fixed

* removed dot from title

* _ensureTokenBalance overriden

* remove function

* fix fmt

* Update src/modules/fundingManager/oracle/interfaces/IOraclePrice_v1.sol

Co-authored-by: Marvin Kruse <[email protected]>

* fix: Move LM_ManualPriceSetter into LM folder

---------

Co-authored-by: scab24 <[email protected]>
Co-authored-by: Zitzak <[email protected]>
Co-authored-by: Marvin <[email protected]>
Co-authored-by: Marvin Kruse <[email protected]>
Co-authored-by: Sergio <[email protected]>
* Remove unnecessary safety check

* Abstract projectFeeCollected

* Create tests

* Fmt

* Update src/modules/fundingManager/bondingCurve/interfaces/IRedeemingBondingCurveBase_v1.sol

Co-authored-by: Marvin <[email protected]>

* Add check to _handleCollateralTokensAfterSell

* Revert "Add check to _handleCollateralTokensAfterSell"

This reverts commit 32f9bb3.

* Readd the check but only for projectCollateralFeeCollected

* Update IFM_BC_Bancor_Redeeming_VirtualSupply_v1.sol

* fmt

* Apply comment suggestions from code review

Co-authored-by: Marvin Kruse <[email protected]>

* Rename Error

* Apply suggestions from code review

* Fix: Resolve version mismatches

* Chore: Resolve formatting issue

---------

Co-authored-by: Marvin <[email protected]>
Co-authored-by: Marvin Kruse <[email protected]>
* fix: decimal conversion error

* fix: add 10^tokenDecimal
@Zitzak Zitzak force-pushed the feature/FM_PC_Oracle_Redeeming_v1 branch from a979f51 to dd17de3 Compare January 15, 2025 18:06
@Zitzak Zitzak force-pushed the feature/FM_PC_Oracle_Redeeming_v1 branch from dd17de3 to 587247c Compare January 15, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit a feature needs auditing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants