I came across the following code
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
What is meaning of (int256)
in this line, and is there any possibility of overflow here? Or here:
magnitude = 2 ** 64
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityAn educated guess:
Since you did not provide the type of variable payoutsTo_
, I believe that it is:
mapping (address => int256) public payoutsTo_;
The following attempt of assigning a uint256
value to an int256
variable would not compile:
payoutsTo_[_customerAddress] += _dividends * magnitude;
Therefore, it is required to cast the value of _dividends * magnitude
to int256
.
Is there any possibility of overflow here, with
magnitude == 2 ** 64
?
Yes, the value of int256(_dividends * magnitude)
will:
2 ** (255 - 64) <= _dividends < 2 ** (256 - 64)
2 ** (256 - 64) < _dividends
_dividends
andmagnitude
?payoutsTo_
?mapping(address => int256) payoutsTo_