You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changing the type of the arguments of categoryID and indexSize to uint16 and respectively uint8 will also change the value of abi.encodePacked(categoryID, indexSize). This can create unintended consequences because other contracts might rely on a predictable address.
These arguments are also used in other functions and could create other unintended consequences or might need other parts of the system to be changed to accommodate new types.
Even though the uint8 type does not create issues, because the accommodating type is bigger, uint16 should match the one defined in the structure.
It's also important to note why the types are not uint256 in the first place; they can be "packed" by Solidity in one storage slot, thus saving space and reducing gas consumption.
Recommendation
When adding the pool registry information, one should cast categoryID to uint16.
Another way to go about this is to save categoryID and indexSize as uint256, increasing gas cost but reducing the need to juggle types.
The text was updated successfully, but these errors were encountered:
cleanunicorn
changed the title
MarketCapSqrtController - The arguments should match the saved types
[MarketCapSqrtController] - The arguments should match the saved types
Oct 6, 2020
Description
The function
prepareIndexPool
acceptscategoryID
andindexSize
as arguments.These arguments, along with
name
andsymbol
, are used to create a new index pool.After the pool is created, the new pool address is saved in a registry.
When the save happens, they are cast to
uint8
. However, this type does not match forIndexPoolMeta.categoryID
, its defined type isuint16
.Changing the type of the arguments of
categoryID
andindexSize
touint16
and respectivelyuint8
will also change the value ofabi.encodePacked(categoryID, indexSize)
. This can create unintended consequences because other contracts might rely on a predictable address.These arguments are also used in other functions and could create other unintended consequences or might need other parts of the system to be changed to accommodate new types.
Even though the
uint8
type does not create issues, because the accommodating type is bigger,uint16
should match the one defined in the structure.It's also important to note why the types are not
uint256
in the first place; they can be "packed" by Solidity in one storage slot, thus saving space and reducing gas consumption.Recommendation
When adding the pool registry information, one should cast
categoryID
touint16
.i.e.
Another way to go about this is to save
categoryID
andindexSize
asuint256
, increasing gas cost but reducing the need to juggle types.The text was updated successfully, but these errors were encountered: