Status DataClose notification

Hesty Disclosed Report

Audit Report

Wrong factor will lead to PropertyToken and property revenue locked in TokenFactory forever for all sold properties

Target

https://github.com/la-bomba-studio/hesty-contract/tree/29596447b9a06d4ad53360d4a15f349ebf9fa0d8

Vulnerability details

This is a combination of two issue.

  1. During the creation of a property to be split into PropertyToken, amount inputted in TokenFactory::createProperty(amount, ..) will be stored in TokenFactory.property mapping and used for accounting and distribution of PropertyToken to investor when a raise is complete. The issue is that constructor of PropertyToken multiply this value by 1e18 and mint everything to TokenFactory. Instruction from HestyAssetIssuance to mint to TokenFactory

  2. TokenFactory will end up with amount * 1e18 PropertyTokens. There is no way to retrieve or burn those tokens. It will dilute totally all investor as the difference factor is huge. Once completeRaise() is called, investor will be able to retrieve their tokens, but a large part will be stuck in TokenFactory Time pass and the owner will try to call TokenFactory::distributeRevenue() or HestyRouter::adminDistribution() Those functions will send EURC in PropertyToken, and user can collect their rewards with PropertyToken::claimDividensExternal(). Though dividend are calculated per token and take into account totalSupply

Share of investor will be insignificant and because of Solidity rounding down, will always be equal to 0.

All EURC distributed will end up stuck into TokenProperty, or TokenFactory as it's possible to call claimDividend for someone else

There is no way to either retrieved stucked EURC revenue in TokenProperty nor TokenFactory.

This issue will happen for every house raises done using the protocol and all rewards distributed will be stuck forever.

Validation steps

Steps

  1. Deploy all contract and link them together
  2. KYC investor and home owner
  3. TokenFactory::createProperty, with 1000 amount of wanted PropertyToken and total price of 100_000 EURC, tokenPrice = 100.
  4. Investor and investor2 both buy 50_000 EURC, ie 500 PToken each
  5. No more investor can participate because from TokenFactory property data, all of them have been sold
  6. Raise is finalized with TokenFactory::closeRaise(), owner get back his investment minus fees.
  7. Investor claim their token using TokenFactory::getInvestmentTokens()
  8. X months passes, let's say 10_000 EURC revenue has been made from house
  9. Admin distribute 10_000 EURC to investors of Ptoken HestyRouter::adminDistribution()
  10. Investors try to get their revenues calling TokenFactory::claimInvestmentReturns(), and got nothing
  11. 10_000 EURC are stuck in either PropertyToken or in TokenFactory if someone calls TokenFactory::claimInvestmentReturns(address(tokenFactory), id)

Fix

  1. Remove the multiplication by 1e18 in PropertyToken
//PropertyToken.sol
constructor(
    address tokenManagerContract_,
    uint256 initialSupply_,
    string memory  name_,
    string memory symbol_,
    address rewardAsset_,
    address ctrHestyControl_,
    address owner
) ERC20(name_, symbol_) AccessControlDefaultAdminRules(
3 days,
  owner // Explicit initial `DEFAULT_ADMIN_ROLE` holder
){

    // Supplies higher than TEN_POWER_FIFTEEN ether will result in precision lost
    require(initialSupply_ < TEN_POWER_FIFTEEN, "Precision lost");

    // Property Token Supply Issuance
-   _mint(address(tokenManagerContract_), initialSupply_ * 1 ether);
+   _mint(address(tokenManagerContract_), initialSupply_);

    rewardAsset     = IERC20(rewardAsset_);
    ctrHestyControl = IHestyAccessControl(ctrHestyControl_);

}
  1. Note that previous step is not enough, as it is possible to finalize a raise when threshold is met. Say we have 1000 token, with threshold at 50%, if 500 tokens are bought, and the raise is finalized, there will still be 500 tokens locked in TokenFactory, so half revenue locked as well. Leftover PropertyToken in TokenFactory needs to be burned at finalization or sent back to owner? This is up to the protocol to decide.

PoC

Instructions to run PoC with foundry/forge

Install forge in the repo :

forge init
forge update

Update foundry.toml with those value

[profile.default]
src = "contracts"
out = "out"
libs = ["lib"]
via_ir = true

Install openzeppelin lib :

forge soldeer init #with foundry-toml
forge soldeer install @openzeppelin-contracts~4.9.6

You should have in foundry.toml :

[profile.default]
src = "contracts"
out = "out"
libs = ["lib", "dependencies"]
via_ir = true

[dependencies]
forge-std = "1.9.6"
"@openzeppelin-contracts" = "4.9.6"

Change in remappings.txt :

@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-4.9.6/
forge-std-1.9.6/=dependencies/forge-std-1.9.6/

Add Poc into contracts/Test.t.sol

Run forge, if stack too deep error add --via-ir, in case not set in foundry.toml :

forge build --via-ir
forge test -vvv --via-ir #OR
forge test --mt testCompleteRaiseAndDistributeDividends -vvv

Test.t.sol

File is sent along with the report under the name Test.sol, otherwise it was not working as Test.t.sol

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.