Skip to content
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

Merged
merged 5 commits into from
Jan 17, 2019
Merged

Conversation

DemiMarie
Copy link
Contributor

These changes allow the smart contracts to successfully initialize, and for the node to successfully boot.

@DemiMarie DemiMarie requested review from vkomenda and varasev January 17, 2019 15:31
@@ -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) {
Copy link
Contributor

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;
Copy link
Contributor

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;
            ^------------------^

Copy link
Contributor

@vkomenda vkomenda left a 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.

@DemiMarie
Copy link
Contributor Author

@vkomenda I thought the EVM guaranteed wrapping, but I could be wrong.

@afck
Copy link
Collaborator

afck commented Jan 17, 2019

There must be another way of dealing with non-existent elements

I think there really isn't: https://solidity.readthedocs.io/en/v0.4.21/types.html#mappings
Conceptually, mappings are initialized so that all keys exist and have the default value. So a nonexistent element is indistinguishable from one that has been intentionally set to the default value.

Contracts must be initialized before their proxies.
@DemiMarie DemiMarie force-pushed the fix-initialization branch 2 times, most recently from cbb1674 to ef5d527 Compare January 17, 2019 17:53
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
@vkomenda
Copy link
Contributor

@afck, thanks for the link. I concur.
@DemiMarie, all I found about the integer overflow spec was an open issue:
ethereum/solidity#796
It might be difficult to implement against an evolving spec. So I'd assume implementations can diverge.

@DemiMarie DemiMarie merged commit 49feb0d into poanetwork:master Jan 17, 2019
@DemiMarie DemiMarie deleted the fix-initialization branch January 17, 2019 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants