A vulnerability exists in the mintFertilizers function of the ReseedBarn contract (https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/main/protocol/contracts/beanstalk/init/reseed/L2/ReseedBarn.sol#L72-L96).
This function is responsible for minting fertilizers, which are stored in a linked list using the nextFid mapping.
The vulnerability arises when the fertilizerIds argument passed to mintFertilizers contains duplicate fertilizer IDs.
In mintFertilizers
it receives Fertilizers[] calldata fertilizerIds
and this fertilizerIds must be in order
because it is stored (Linked list) Id points to the next Id:
[0, 100] -> [100, 200] -> [200, 300] -> [300, 400]
If a fertilizerIds array contains a duplicate ID the Linked list will be corrupt.
eg: Id 100 is duplicate.
[0, 100] -> [100, 400] -> [200, 100] -> [100, 400]
POC:
A corrupted linked list can lead to unexpected behavior in functions that rely on traversing the fertilizer list. This could potentially result in:
1- Inability to access or modify specific fertilizers.
2- Incorrect data being returned when querying the fertilizer list.
enforce unique fertilizer IDs:
The contract should be modified to ensure that the fertilizerIds array passed to mintFertilizers does not contain any duplicates.
This can be achieved through validation before processing the data.
Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity
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.