Encode-Club-Solidity-Foundations / Lesson-01

21 stars 14 forks source link

Solidity potholes #37

Open ml-sudocode opened 2 years ago

ml-sudocode commented 2 years ago

I've heard that solidity has some unexpected behavior that lead to smart contract risks. one example is where if you look up a non-existent item in a merkle tree, instead of returning an error, it returns a default of 0. what other examples are there?

MatheusDaros commented 2 years ago

Hello @michelleylai Thanks for the question. It is not considered to be "unexpected behavior" to return 0 for a non-existent item in a merkle tree in solidity since lots of the Encoding/Decoding operations for locating members by reference rely on this behavior, so that when the hash is not present, you return the default value for that type. This is especially useful in mappings, for example. There are indeed some technical details similar to this one that sometimes happen, but often those get fixed as newer versions of solidity and evm are released.