Due to lack of validation, a malicious bidder can intentionally increasing the info.totalAuctionTokenAmount
and therefore the malicious bidder can manipulate the claimAmount
to be received
Within the TempleGold contract, the MAX_SUPPLY
would be defined as 1_000_000_000 ether
(1 billion) like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/TempleGold.sol#L47
Within the DaiGoldAuction contract, the nextAuctionGoldAmount
would be defined to keep track of next epoch auction Temple Gold amount like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L41
Within the DaiGoldAuction#distributeGold()
, the DaiGoldAuction#_distributeGold()
would be called like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L300
Within the DaiGoldAuction#_distributeGold()
, the TempleGold#mint()
would be called like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L305
Within the TempleGold#mint()
, the TempleGold#_distribute()
would be called like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/TempleGold.sol#L155
Within the TempleGold#_distribute()
, the TempleGoldStaking#notifyDistribution()
would be called with the stakingAmount
and the DaiGoldAuction#notifyDistribution()
would be called with the escrowAmount
like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/TempleGold.sol#L230
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/TempleGold.sol#L236
Within the DaiGoldAuction#notifyDistribution()
, the nextAuctionGoldAmount
would be incremented by adding a given amount
(which is the escrowAmount
assigned in the TempleGold#_distribute()
above) like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L174
Within the DaiGoldAuction#startAuction()
, the nextAuctionGoldAmount
would be stored into the totalGoldAmount
and then it would be stored into the info.totalAuctionTokenAmount
(This means that the nextAuctionGoldAmount
would indirectly be stored into the info.totalAuctionTokenAmount
) like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L114
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L121
After the bidding period would be finished, a user would call the DaiGoldAuction#claim()
to claim the share of TempleGold for epoch.
Within the DaiGoldAuction#claim()
, the claimAmount
would be calculated based on the formula, which includes info.totalAuctionTokenAmount
, and then it would be transferred to the user (msg.sender
) like this:
https://github.com/Cyfrin/2024-07-templegold/blob/main/protocol/contracts/templegold/DaiGoldAuction.sol#L161-L162
The DaiGoldAuction#distributeGold()
above is supposed to be called by only privileged-user.
However, within the DaiGoldAuction#distributeGold()
, there is no validation heck whether or not the caller (msg.sender
) of the DaiGoldAuction#distribute()
is a privileged-user.
This allow anyone to call the DaiGoldAuction#distributeGold()
to mint TGLD to the both contracts (TempleGoldStaking and the DaiGoldAuction) and increase the nextAuctionGoldAmount
as much as the user want.
If the malicious bidder would repeadedly call the DaiGoldAuction#distributeGold()
before the auction get started, the amount of TGLD-minted and the nextAuctionGoldAmount
can be increased to the amount, which is close to the max supply of the TGLD is 1 billion (MAX_SUPPLY = 1_000_000_000 ether
),
After the malicious action above, if an auctionStarter
would call the DaiGoldAuction#startAuction()
, the nextAuctionGoldAmount
, which is close to the max supply of the TGLD is 1 billion (MAX_SUPPLY = 1_000_000_000 ether
), would be stored into the totalGoldAmount
and then it would be stored into the info.totalAuctionTokenAmount
in the DaiGoldAuction#startAuction()
.
Since the claimAmount
would be calculated in the DaiGoldAuction#claim()
based on the formula-including the info.totalAuctionTokenAmount
, the claimAmount
can be maximized due to that the info.totalAuctionTokenAmount
has been the amount, which is close to the max supply of the TGLD is 1 billion (MAX_SUPPLY = 1_000_000_000 ether
):
Hence, after the bidding period is finished, the malicious bidder can be successful to (claim and) receive so much amount of TGLD by intentionally increasing the info.totalAuctionTokenAmount
and therefore the malicious bidder can manipulate the claimAmount
to be received.
Let's say Alice is an auctionStarter
and Bob is a malicious bidder who would like to maximize the amount of TGLD to be claimed.
1/ Now, the auction is not started.
2/ Bob would repeadedly call the DaiGoldAuction#distributeGold()
.
By repeadedly doing so, eventually, the nextAuctionGoldAmount
would be increased to 999_000_000 ether
, which is close to the max supply of the TGLD (MAX_SUPPLY = 1_000_000_000 ether
).
3/ Alice would call the DaiGoldAuction#startAuction()
to start an auction.
At this point, the increased nextAuctionGoldAmount
(999_000_000 ether
) would be stored into the totalGoldAmount
and then it would be stored into the info.totalAuctionTokenAmount
.
4/ Bob (and other bidders) would bid.
5/ The bidding period is finished.
6/ Bob would call the DaiGoldAuction#claim()
The claimAmount
is calculated based on the formula, which includes the info.totalAuctionTokenAmount
.
Since the increased nextAuctionGoldAmount
(999_000_000 ether
) has been stored into the info.totalAuctionTokenAmount
when the step 3/, the claimAmount
can also be increased (maximized) like this:
7/ As a result, Bob could receive so much amount of TGLD.
(NOTE: By the way, in this case, other bidders could alsov receive so much amount of TGLD)
A malicious bidder can intentionally increasing the info.totalAuctionTokenAmount
and therefore the malicious bidder can manipulate the claimAmount
to be received.
Foundry
Within the DaiGoldAuction#distributeGold()
, consider adding an access control modifier (i.e. onlyElevatedAccess
) - so that only privileged-user can call the DaiGoldAuction#distributeGold()
like this:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.