PI-9: Helper Function Bug Fix
Executed on April 18, 2025 at 18:48 UTC.
Summary
Update the _setSortedDepositIds function to properly set the Deposit ID-to-index mapping.
Links
- Implementation Commit: 452ee9638e5c86cfa73b1c25f5f1cdac80cd84ff
Problem
The protocol stores a list of each Farmer's Deposits on-chain, which is used to allow clients like the Pinto UI to easily query Deposit data. The protocol also stores a mapping of Deposit IDs to index in order to efficiently look up a Deposit's index. PI-8 introduced an updateSortedDepositIds function that allows anyone to submit a Deposit ordering for one token, validated in ascending Stem order, but this function did not properly update the mapping to reflect the new ordering. As a result, a later full Deposit removal could use a stale index and remove the wrong ID from the list.
Solution
Update LibSilo._setSortedDepositIds to properly update the mapping based on the new ordering. Each Deposit ID is mapped to its zero-based index before the ordered list is stored.
Rationale
Keeping the index mapping consistent with the ordered list preserves correct Deposit index lookup and removal after reordering. The existing validation requires a nonempty, complete list in strictly ascending Stem order.
Contract Changes
Initialization
No initializer was called. The upgrade did not automatically rewrite existing account mappings. A successful call to updateSortedDepositIds updates the supplied account and token’s index mapping.
Facet Changes
| Facet | Action | Previous Implementation | New Implementation |
ApprovalFacet | Replace | 0x61b9a20a5fc4a9965c2309c2feff56b5ebe855cd | 0xa7c95ed70be8f91f8d8af91de193710fa7ab32bb |
ClaimFacet | Replace | 0x44df048857445cd8cba3b8cc26132816d827ff14 | 0xd38c3e61bf08734cd808aca15c944389968612e0 |
ConvertFacet | Replace | 0x1af9097b043e26f41d082c5adb89cd606528e526 | 0xdfa197784879926e2358a7c71c6a0bd487f919fd |
PipelineConvertFacet | Replace | 0xf26ab0c4a354f12c9e8fa86c423f463e2c72ddd8 | 0xc54cd71bfa5d0fe05d887eabbec4dbbc94cf74ba |
SiloFacet | Replace | 0xd954a3245a868ab3e991786d4e5e71892099a19d | 0xf6af001b8879a2e30db294b4c8deccbd0d168b34 |
SiloGettersFacet | Replace | 0x6f9a49560a1db78cd32f1332e15fcaedc77aa66b | 0xadfd7fbe59ca2624cec1b04f9bc65c7f90efed36 |
All six facets were replaced with unchanged external interfaces. The changed internal helper is called only by SiloFacet.updateSortedDepositIds(). The other replacements do not introduce additional function changes.
Other Contract / Parameter Changes
The externally linked libraries below were redeployed. Only LibSilo’s own source changed. LibTokenSilo, LibConvert and LibPipelineConvert retained their own source. ApprovalFacet and SiloGettersFacet have no externally linked libraries. No protocol parameters were changed.
| Library | Previous Implementation | New Implementation | Used By |
LibSilo | 0x49bfc93e96d467d79fc809c8f6da466f8ebb8975 | 0xefa4e6492966228a7af3d5d9045bd9c9e5dc72bf | ClaimFacet, ConvertFacet, PipelineConvertFacet, SiloFacet |
LibTokenSilo | 0xe47c1d275ceb1554ce802a0755cc679294f1ae81 | 0xf2a0e7fb0e9b1189b14274418e4ac78ae449b4ed | ClaimFacet, ConvertFacet, PipelineConvertFacet, SiloFacet |
LibConvert | 0xd10b907e2f8f452c4d43848a4f632a00eff9530b | 0x71e8ab0a025c0b96d64c34759880e6ba2ba0baa0 | ConvertFacet |
LibPipelineConvert | 0x9b42c78bd19fdf3cf3b3c16c9184e1169bf2c7aa | 0xa4a2d1e394faac3e60297a55cdceeb38c0b6ca18 | ConvertFacet, PipelineConvertFacet |
Function Changes
- Updated
LibSilo._setSortedDepositIds(), called bySiloFacet.updateSortedDepositIds(), to assignidIndex[sortedDepositIds[i]] = ifor every validated Deposit ID before storing the array. This keeps the existinggetIndexForDepositId()getter and index-based Deposit removal consistent with the new ordering. The external validation, return types and event interfaces were unchanged.