kadenzipfel / smart-contract-vulnerabilities

A collection of smart contract vulnerabilities along with prevention methods
https://kadenzipfel.github.io/smart-contract-vulnerabilities/
1.83k stars 256 forks source link

Deleting a mapping within a struct vulnerability added. #76

Closed 0xSandyy closed 3 months ago

0xSandyy commented 3 months ago

Related Issue

Checklist

Describe the changes you've made:

This contribution adds a vulnerability that deals with an unique behavior caused by deleting structs which have a mapping inside them. delete gives a common idea that it will delete every content inside but this doesn't always happen and this contribution expands on that.

Type of change

Select the appropriate checkbox:

Additional Information

The impact of this issue is not straightforward but having data that is supposed to be deleted can have unexpected consequences.

0xSandyy commented 3 months ago

Hi, the issue is in the latest commit i.e 4992e34. I will make sure to add more clear commit messages.

0xSandyy commented 3 months ago

Hi, as per the docs and some research:

Mappings are implemented as hash tables and the EVM does not keep track of which keys have been used in the mapping. As a result, EVM doesn't know how to reset a mapping. However, individual keys and what they map to can be deleted: If a is a mapping, then delete a[x] will delete the value stored at x.