Parralel data structure was present in https://github.com/Cyfrin/2023-12-stake-link/blob/main/contracts/core/sdlPool/base/SDLPool.sol which was later used in https://github.com/Cyfrin/2023-12-stake-link/blob/main/contracts/core/sdlPool/SDLPoolPrimary.sol contract's withdraw()
, handleOutgoingRESDL()
, handleIncomingRESDL()
& _storeNewLock()
. We can simply remove 2 mappings and modify another mapping to get expected results.
As you can see, a struct was present here: https://github.com/Cyfrin/2023-12-stake-link/blob/main/contracts/core/sdlPool/base/SDLPool.sol#L18. Later two mapping was written here: https://github.com/Cyfrin/2023-12-stake-link/blob/549b2b8c4a5b841686fceb9c311dca9ac58225df/contracts/core/sdlPool/base/SDLPool.sol#L36C1-L36C1 and here: https://github.com/Cyfrin/2023-12-stake-link/blob/549b2b8c4a5b841686fceb9c311dca9ac58225df/contracts/core/sdlPool/base/SDLPool.sol#L38
The struct looks like:
and mappings are:
and
The locks
mapping is set lockId
to Lock
struct. But this is redundant, we can simply add a variant named lockId
in the struct.
Same for balances
mapping, this mapping sets how many locks a user has, this balances
also can be be added as a variant in struct.
So struct should look like:
Now we simply have to replace another mapping: mapping(uint256 => address) internal lockOwners;
with mapping(address => Lock) internal ownerToLock
or with any better name. Now we can update the Lock
struct using the owner's address as key.
Data Consistency: Maintaining data consistency across parallel data structures can be challenging. If one data structure is updated and another is not, it can lead to inconsistencies in the state of the contract.
Gas Costs: Each additional data structure increases the gas cost for transactions. This is because each operation (read, write, update) on a data structure consumes a certain amount of gas. Therefore, the more data structures you have, the more gas you will consume.
Manual analysis
Use this struct structure:
and remove these 2 mappings :
and replace the mapping(uint256 => address) internal lockOwners;
with mapping(address => Lock) internal ownerToLock
and update contracts according to it.
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.