-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix initialization #16
Conversation
@@ -435,7 +430,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet { | |||
function _removeFromPoolsInactive(address _who) internal { | |||
address[] storage poolsInactive = addressArrayStorage[POOLS_INACTIVE]; | |||
uint256 indexToRemove = poolInactiveIndex(_who); | |||
if (poolsInactive[indexToRemove] == _who) { | |||
if (indexToRemove + 1 && poolsInactive[indexToRemove] == _who) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't compile for me.
/home/vk/src/poanetwork/pos-test-setup/pos-contracts/contracts/abstracts/ValidatorSetBase.sol:433:13: TypeError: Operator && not compatible with types uint256 and bool
if (indexToRemove + 1 && poolsInactive[indexToRemove] == _who) {
^-------------------------------------------------------^
,/home/vk/src/poanetwork/pos-test-setup/pos-contracts/contracts/abstracts/ValidatorSetBase.sol:433:13: TypeError: Type uint256 is not implicitly convertible to expected type bool.
if (indexToRemove + 1 && poolsInactive[indexToRemove] == _who) {
^-------------------------------------------------------^
@@ -661,6 +653,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet { | |||
keccak256(abi.encode(POOL_STAKERS, _pool)) | |||
]; | |||
uint256 indexToRemove = poolStakerIndex(_pool, _staker); | |||
if (!(indexToRemove + 1)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't compile either.
,/home/vk/src/poanetwork/pos-test-setup/pos-contracts/contracts/abstracts/ValidatorSetBase.sol:656:13: TypeError: Unary operator ! cannot be applied to type uint256
if (!(indexToRemove + 1)) return;
^------------------^
,/home/vk/src/poanetwork/pos-test-setup/pos-contracts/contracts/abstracts/ValidatorSetBase.sol:656:13: TypeError: Type uint256 is not implicitly convertible to expected type bool.
if (!(indexToRemove + 1)) return;
^------------------^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be another way of dealing with non-existent elements apart from intentional underflow. Underflow behaviour might be implementation-specific.
@vkomenda I thought the EVM guaranteed wrapping, but I could be wrong. |
I think there really isn't: https://solidity.readthedocs.io/en/v0.4.21/types.html#mappings |
Contracts must be initialized before their proxies.
cbb1674
to
ef5d527
Compare
This showed up as an out-of-bounds array access during initialization, but it could have just as easily caused problems at runtime. Additionally, document that the pool index lookup functions return uint256(~0) if the address is not found.
and so should not be in the repository
ef5d527
to
25795c4
Compare
@afck, thanks for the link. I concur. |
These changes allow the smart contracts to successfully initialize, and for the node to successfully boot.