Platform: Code4rena
Start Date: 15/02/2022
Pot Size: $30,000 USDC
Total HM: 18
Participants: 35
Period: 3 days
Judge: GalloDaSballo
Total Solo HM: 8
Id: 87
League: ETH
Rank: 17/35
Findings: 1
Award: $455.89
🌟 Selected for report: 1
🚀 Solo Findings: 0
🌟 Selected for report: Czar102
Also found by: 0x1f8b, SolidityScan
https://github.com/code-423n4/2022-02-redacted-cartel/blob/main/contracts/BribeVault.sol#L164-L205
depositBribeERC20
function in BriveVault
is reentrant in line 187, where an address supplied by the caller is called.
A bad actor that has DEPOSITOR_ROLE
and is a contract can execute a folowing attack:
BriveVault
and the attacker contract has unlimited tokens. Reentrancy aims back to a function in the attacker contract, which calls depositBribeERC20
again.bribeIdentifier
. token
is set to a dummy contract and amount
to uint(-2)
.transferFrom
is called, which calls attacker contract, which can call depositBribeERC20
again, this time will transfer 1 wei of a valuable token, using the same bribeIdentifier
. All checks pass as the previous token hasn't been registered yet. Then, a valid transfer happens. After that, the amount is set to 1 wei and the token is saved. Event is emitted and the function returns value. Then, attacker function returns and dummy token returns. The operation is to increment amount in storage by the transfer value, which increases b.amount
to the maximum integer. The token is nonzero, so the if statement is passed.Thus, an attacker can grant any amount of tokens from BriveVault
to a certain bribe, stealing all the funds once the bribe will be withdrawn.
Set bribe token before the transfer is made.
#0 - kphed
2022-02-18T01:27:00Z
Marking as duplicate since it's the same general concern that depositors would be malicious actors.
Duplicate of https://github.com/code-423n4/2022-02-redacted-cartel-findings/issues/1.
#1 - GalloDaSballo
2022-03-06T16:03:57Z
I do believe re-entrancy is possible, so I recommend the sponsor to add the nonReentrant
modifier to the deposit function
The example shown above works because the function trusts the DEPOSITOR_ROLE
so I'd agree with the sponsor with grouping with #1
I'll keep the finding separate as this deals with reEntrancy.
Mitigation would be to enforce a bribeIdentifier to be used for a specific token (and it being enforced), as well as adding nonReentrant
Because the function is permissioned, I believe medium severity to be more appropriate