Open hats-bug-reporter[bot] opened 1 year ago
Thanks for the submission!
That´s a valid finding, although I want to mention that it is impossible to acquire Portal Energy Tokens before a Portal was activated. Therefore, steps 4-6 will never happen.
Nonetheless, this is a valid low severity because the contract provides confusing information, i.e. doesn´t work as intended.
I would prefer to disable the quoteBuy/SellPortalEnergy functions alltogether before the Portal is activated.
Let me know if you agree with this solution:
function quoteSellPortalEnergy(uint256 _amountInput) external activePortalCheck view returns(uint256) { }
Thanks for the feedback!
Just out of curiosity: in the scenario where multiple Portals are opened: is it still impossible to acquire portal energy before portal was activated?
Agree with the solution, this way there is no added complexity.
Thanks for the confirmation. 🤝
There are only two primary ways to acquire Portal Energy:
stake() cannot be called before the Portal is activated. buyPortalEnergy cannot be called by anyone who doesn´t have an initialized account. A new account can only be initialized by calling stake().
Therefore, it´s impossible to acquire Portal Energy of a Portal that is inactive. :)
Github username: @0xfuje Twitter username: 0xfuje Submission hash (on-chain): 0x7c559946325e3b283826358af8a423908409d282cb208fc006ce5faeaeb2152b Severity: low
Description:
Description
The problem is that
portalEnergy
quote functions do not take into account whenconstantProduct
have not yet been set, since it will only have a non-zero value afteractivatePortal()
. Any time the user calls the functions before the active phase it will return a misleading value.portalEnergyToken
has a marketquoteSellPortalEnergy()
with100 * 1e18
PSM
for hisportalEnergy
100 * 1e18
portal energy tokenportalEnergyToken
sell is worth much lessPSM
Proof of Concept
run
forge test --match-test testInaccurateQuotesDuringFundingPhase -vvvv
Recommendation
Consider calculating the
_constantProduct
in memory in the quote functions before the funding phase (without touching the storage variableconstantProduct
). In the active phase, the storage var can be used loaded to memory. Based on theconstantProduct = fundingBalance ** 2 / FUNDING_EXCHANGE_RATIO
calculation: