FieldFacet.sowThe plotIndexes array is designed to contain unique plot indexes, ensuring that no index appears more than once. However, due to an oversight in the sow function in the FieldFacet, it is possible for multiple entries to have the same index.
During the sow function call, the index is assigned as follows:
Here, the index is determined by s.sys.fields[s.sys.activeField].pods and is later incremented by the newly sown pods. However, if pods = 0, s.sys.fields[s.sys.activeField].pods remains unchanged, causing the same index to be pushed into the plotIndexes array on subsequent sow calls.
Functions utilizing the plotIndexes array will return incorrect values.
For example, getPlotsFromAccount will return the same plot multiple times.
Additionally, removePlotIndexFromAccount will only remove a single instance of the index, failing to perform correctly.
Include a requirement in the sow function to ensure that pods > 0:
To reproduce the issue, add the following test to protocol/test/foundry/field/Field.t.sol and execute it using forge test --match-test test_bug:
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.