code-423n4 / 2021-07-sherlock-findings

0 stars 0 forks source link

Group related data into separate structs #69

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

pauliax

Vulnerability details

Impact

In Base struct having 3 separate fields that map from _protocol is error-prone. If you later introduce new fields, etc, you need not forget to delete them in function protocolRemove, etc. I think it would be better to have a separate struct for protocol-related data and map to that.

Recommended Mitigation Steps

An example solution, replace: mapping(bytes32 => address) protocolManagers; mapping(bytes32 => address) protocolAgents; mapping(bytes32 => bool) protocolIsCovered; with: struct ProtocolInfo { address manager; address agent; bool covered; } struct Base { ... mapping(bytes32 => ProtocolInfo) protocolInfo; ... } Then you can delete all fields this way: delete gs.protocolInfo[_protocol]; Similar solution may be applied to PoolStorage (protocolBalance, protocolPremium, isProtocol).