The last version 0.4.25 Solidity release fixes two major bugs. Another major bug has already been fixed in version 0.4.22, but it was only recently that the bug was discovered to exist.
Please note that the Ethereum Foundation runs a rewards program for the code generator part of Solidity.
Cleaning Exponent in Exponentiation
- Probability of occurrence: very low
- Exploitability: high
- Test Visibility: Low
- Fixed in version: 0.4.25
Summary: Using short types in the exponent of an exponentiation operation can lead to invalid results.
The Solidity language allows integer types that are shorter than 256 bits, although the Ethereum virtual machine only knows types that are exactly 256 bits. For this reason, the high-order bits must be set to zero from time to time. For many operations, it is not relevant whether those bits are set to zero or not (addition is an example). Therefore, the Solidity compiler delays this cleanup until it is needed to save gas.
In the very special circumstance that the exponent of the ** operator has a type that is shorter than 256 bits, but not shorter than the base type, and contains higher-order dirty bits, this can lead to an incorrect result. Note that literal exponents as in x ** 2 as well as the case where the type of the base is uint256 either int256 they are not affected.
Note that a function parameter can have higher-order dirty bits if called by a malicious entity, and the same is true for data returned by functions from contracts implemented by malicious entities.
Having looked at a large number of contracts, we believe that this bug affects only a very small number of smart contracts, if any, because regular uses of the exponentiation operator do not cause the bug.
This bug was found by better.
Memory corruption in multidimensional array decoder
- Probability of occurrence: low
- Exploitability: medium
- Test Visibility: High
- Introduced in version: 0.1.4
- Fixed in version: 0.4.22
Summary: Calling functions from other contracts that return fixed-size multidimensional arrays results in memory corruption.
If Solidity code calls a function that returns a multidimensional array of fixed size, the ABI-encoded data returned must be converted to Solidity’s internal array representation. In Solidity, multidimensional arrays are implemented as arrays of memory pointers, while in ABI, the data is inline-encoded. The decoder did not account for this difference with the result that the returned items are interpreted as memory pointers and thus can corrupt memory if the return values are accessed. Calling functions with multidimensional fixed-size array arguments is not affected, as is the return of fixed-size arrays from function calls if they are not used in a Solidity contract. The error is only in the component that decodes a fixed-size multidimensional array that is returned from a Solidity function call.
This bug was found by jmahhh.
Invalid encoding of structures in events
- Probability of occurrence: low
- Exploitability: low
- Test Visibility: High
- Introduced in version: 0.4.17
- Fixed in version: 0.4.25
Summary: Structures as event parameters are not handled correctly.
The structures were not intended to be supported as event parameters without the new ABI encoder. However, the compiler accepted them, but encoded their memory address instead of their actual value. Even with the new ABI encoder, the structures cannot be indexed event parameters.
Structs are now correctly disabled for the old encoder and, if indexed, for the new encoder as well.