Submitted by WatchPug
BathToken.sol#_deposit() calculates the actual transferred amount by comparing the before and after balance, however, since there is no reentrancy guard on this function, there is a risk of re-entrancy attack to mint more shares.
Some token standards, such as ERC777, allow a callback to the source of the funds (the from address) before the balances are updated in transferFrom(). This callback could be used to re-enter the function and inflate the amount.
https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L557-L568
With a ERC777 token by using the ERC777TokensSender tokensToSend hook to re-enter the deposit() function.
Given:
The attacker can create a contract with tokensToSend() function, then:
As a result, with only 1 + 1_000e18 transferred to the contract, the attacker minted 2_000e18 XYZ worth of shares.
Consider adding nonReentrant modifier from OZs ReentrancyGuard.
bghughes (Rubicon) marked as duplicate and commented:
HickupHH3 (judge) commented:
bghughes (Rubicon) confirmed
