indexed
Keyword in Events Causes Data Loss for Dynamic Array Variables
#25
Labels
indexed
Keyword in Events Causes Data Loss for Dynamic Array Variables
#25
Github username: @MatinR1
Twitter username: MatinRezaii1
Submission hash (on-chain): 0x15191bdce8a415162459395c3c243c5b5fc5ecc75be921124457b7c11bf6706a
Severity: low
Description:
Description
when the
indexed
keyword is used for reference type variables such as dynamic arrays or strings, it will return the hash of the mentioned variables.Thus, the event which is supposed to inform all of the applications subscribed to its emitting transaction (e.g. front-end of the DApp, or the backend listeners to that event), would get a meaningless and obscure 32 bytes that correspond to keccak256 of an encoded dynamic array. This may cause some problems on the DApp side and even lead to data loss. For more information about the
indexed
events, check here:(https://docs.soliditylang.org/en/v0.8.17/abi-spec.html?highlight=indexed#events)
The problem exists inside the Rebalancing contract. The event UpdatedTokens is defined in such a way that the dynamical array of
newTokens
is indexed. With doing so, the expected parameters wouldn't be emitted properly and front-end would get meaningless one-way hashes.Attachments
Consider this scenario as an example:
1 - The function
updateTokens()
is called by the asset manager2 - Inside the function
updateTokens()
we expect to see the the array of "_newTokens" be emitted:3 - But as the event topic is defined as
indexed
we'll get an obscure 32-byte hash and listeners will not be notified properly. Thus, the array of recently updated tokens would be lost in the DApp.For test purpose one can run this test file:
Outputs of test:
UpdatedTokens
event:UpdatedTokens1
event:As you can see, the intended outputs wouldn't be emitted if the
indexed
keyword is used for newTokens (address[]).Consider modifying the event UpdatedTokens inside the contract Rebalancing:
The text was updated successfully, but these errors were encountered: