Heart::beat() could be called several times in one block if no one called it for a some time
The beat() function could be called multiple times in one block if it had not been called for a while, allowing a user to repeatedly trigger it and collect rewards. An attacker could exploit this to drain rewards or cause unintended state changes.
Originally disclosed on Code4rena
Submitted by rvierdiiev, also found by datapunk, devtooligan, itsmeSTYJ, Jeiwan, Lambda, Trust, and zzzitron
beat() function is allowed to be called by anyone once in frequency() period. The purpose of it is to update the prices and do another operations related to bond market. User who ran it are rewarded. There is no need to run this function more then 1 time in frequency() period. However if beat() was last time called more then frequency() time ago then user can execute beat() function (block.timestamp - lastBeat)/frequency() times in a row in same block and get rewards.
Proof of Concept
https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Heart.sol#L92 https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Heart.sol#L103
Recommended Mitigation Steps
https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Heart.sol#L103
Change this line to lastBeat = block.timestamp - (block.timestamp - lastBeat) % frequency();
So no matter how much time the beat() was not called, it is possible to call it only once per frequency().
Oighty (Olympus) confirmed and commented:
See comment on #405. This approach actually solves both of our issues though.
Going to use this issue as the primary since the solution is elegant and solves the problem.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract updated the last-called timestamp to the current block time instead of advancing it by only one frequency period, so the number of missed periods remained available for repeated calls.
Impact
An attacker could call beat() multiple times in one block and collect multiple rewards, potentially draining reward funds or causing repeated state updates.
What the attacker needed
Beat() not called for multiple frequency periods; attacker can call beat()
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract has a function that anyone can call once per time period to update prices and earn a reward. If nobody called it for several periods, the contract allowed calling it many times in a row in the same transaction, so one person could collect multiple rewards at once.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.