<!-- canonical: https://0xsimao.com/findings/trestle-amounts-share-skipping-reward -->

# Amounts to distribute are added directly to tokenPerShare, skipping using rewardPerToken

Medium · Three Sigma · Modular blockchain infrastructure · 27th January 2024

Finding 3S-TR-M05 of the Trestle wTIA Bridge security review.

- Report: /reports/trestle-wtia-bridge
- Source: https://github.com/0xsimao/audits/blob/main/Three%20Sigma/2024-01-27-trestle.pdf

---

### Description

Rewards are emitted at a rate of rewardTokenPerBlock. However, when distributing, the
received reward tokens are added directly to rewardPerToken, instead of being left in the
contract and letting rewardTokenPerBlock distribute the amounts over time.

### Recommendation

Don't add the amount to swap to amountToDistribute, but let the tokens in the contract so
rewards can be emitted according to rewardTokenPerBlock. In fact, the swap should be
performed before calculating emittedRewards(), so it does not happen that the tokens to
distribute are cropped due to not having enough balance and then due to the swap there is
now balance.

### Status

Addressed by disabling taxes.

Disclosed by 0xSimao (https://0xsimao.com/).

---

Related findings:

- [`LenderCommitmentGroup_Smart` does not use `mulDiv` when converting between token and share amounts, possibly leading to DoS or loss of funds](https://0xsimao.com/findings/teller-finance-mul-div-converting-share): Teller Finance
- [`fyToken` contribution limits are incorrect as they compare `fyToken` and `buyToken` amounts with `idoSize` in `idoToken` units](https://0xsimao.com/findings/blast-ido-pools-contribution-limits-compare-buy): Blast IDO Pools
- [Reward Token Loss for LPs During NFT Position Transfer](https://0xsimao.com/findings/bmx-reward-nft-position-transfer): BMX Deli Swap
- [Precision Loss in `notifyRewardAmount` Function Causes Unclaimable RewardToken](https://0xsimao.com/findings/exactly-protocol-update-staking-contract-ii-precision-notify-reward-unclaimable): Exactly Protocol Update - Staking Contract
