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

Upgradeable contract components implementation #773

Merged
merged 73 commits into from
Jul 4, 2019

Conversation

ngrinkevich
Copy link
Contributor

@ngrinkevich ngrinkevich commented Apr 27, 2019

Refs #802

Implements RFC5 upgradeable contract components scheme. Adds minor refactoring to reduce the amount of repeated code.

Further additions required to fully match RFC5, saving these for a separate PR:

  • createGroup() method on Operator contract
  • Service contract to select operator on requestRelayEntry()

First step as part of the refactoring this contract as immutable back-end
for the random beacon. Removing getters for the constants since these are
now auto-generated from public variables.
@ngrinkevich ngrinkevich force-pushed the upgradeable-contract-components branch from 4e39d06 to 46b0618 Compare April 30, 2019 16:19
@ngrinkevich ngrinkevich marked this pull request as ready for review May 25, 2019 22:01
This contract is not used by the Keep client, CLI for relay requests has
been implemented with truffle scripts and located in `contract/scripts`.
@sthompson22 sthompson22 added the 👊 attack Possible attacks that may need investigation. label Jul 1, 2019
Copy link
Contributor

@sthompson22 sthompson22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for going through all of the infra config files.

Based on what I'm seeing here once this is merged keep-dev should get provisioned properly. I'll fire a relay request once I see this deployment go out.

For keep-test we'll need to be a bit more careful on rolling this out since external parties have as-is configuration files. Once keep-dev is proven to be kosher I'll make the arrangements for keep-test.

@sthompson22
Copy link
Contributor

Did not mean to add that label - sorry.

@sthompson22 sthompson22 removed the 👊 attack Possible attacks that may need investigation. label Jul 1, 2019
@sthompson22
Copy link
Contributor

It may be worth running a keep-dev deployment off of this branch before it's merged, unless someones already done it.

@dimpar dimpar mentioned this pull request Jul 2, 2019
config.toml.SAMPLE Outdated Show resolved Hide resolved
config.toml.SAMPLE Outdated Show resolved Hide resolved
contracts/solidity/contracts/KeepRandomBeaconOperator.sol Outdated Show resolved Hide resolved
Copy link
Member

@pdyraga pdyraga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ngrinkevich I think I accepted the fact of the existence of separate request counters, especially that I can't propose any better alternative, not counting a separate counter contract which I am not sure if is any better. 😉

Let's work on naming a little - use requestId everywhere consistently in the service contract and have signingId in the operator contract just like you proposed. I also think we should avoid duplicating the state about the number of groups between service and operator contract as it always hurts long-term and I do not see any security reason for doing it. Other than that, I think some events can be removed.

I left a lot of comments but most of them are about proposed renames. I think we are really close to merging it.

contracts/solidity/contracts/KeepRandomBeaconOperator.sol Outdated Show resolved Hide resolved
contracts/solidity/contracts/KeepRandomBeaconOperator.sol Outdated Show resolved Hide resolved
// to trigger the creation of the first group. Requests are removed on successful
// entries so genesis entry can only be called once.
requestCounter++;
requests[requestCounter] = Request(0, 0, _genesisGroupPubKey, _serviceContract);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use 1 instead of 0 for requestID? Service contract increses the counter before calling sign so if we were sending this request through the service contract, we'd start with 1.

An alternative could be to store this request under signingId = 0, that is, to do not increment requestCounter in the previous line. It could make sense since it's a special - seed - request and we may want to differentiate it as such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not addressed.

contracts/solidity/contracts/KeepRandomBeaconOperator.sol Outdated Show resolved Hide resolved
contracts/solidity/contracts/KeepRandomBeaconOperator.sol Outdated Show resolved Hide resolved
emit RelayEntryGenerated(requestId, entry);

if (_callbacks[requestId].callbackContract != address(0)) {
_callbacks[requestId].callbackContract.call(abi.encodeWithSignature(_callbacks[requestId].callbackMethod, entry));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Users/piotr/go/src/github.com/keep-network/keep-core/contracts/solidity/contracts/KeepRandomBeaconServiceImplV1.sol:144:13: Warning: Return value of low-level calls not used.
            _callbacks[requestId].callbackContract.call(abi.encodeWithSignature(_callbacks[requestId].callbackMethod, entry));
            ^---------------------------------------------------------------------------------------------------------------^

@pdyraga
Copy link
Member

pdyraga commented Jul 4, 2019

No longer existing KeepGroup contract is referenced in contracts/solidity/scripts/initiate-unstake.js

Fixed in #900 in 3a4b96f

@pdyraga
Copy link
Member

pdyraga commented Jul 4, 2019

Tested genesis, works as expected:

➜  solidity git:(encryption-for-state-management) ✗ truffle exec ./scripts/genesis.js --network local
Using network 'local'.

Genesis entry successfully submitted.

Tested relay request with no callback, works as expected:

➜  solidity git:(upgradeable-contract-components) ✗ truffle exec ./scripts/request-relay-entry.js --network local
Using network 'local'.

Successfully requested relay entry with RequestId = 3

---Transaction Summary---
From:0xfa3da235947aab49d439f3bcb46effd1a7237e32
To:0x5d1a5270c7cf288e81d4f6b4276a3c8ba0d0e6b3
BlockNumber:78240
TotalGas:154360
TransactionHash:0xdf1d904144c37a9ab0e0de4a262a342c5f789cb997656ef6268e333ef402602e
--------------------------

Tested relay request with callback, works as expected:

➜  solidity git:(upgradeable-contract-components) ✗ truffle exec ./scripts/request-relay-entry-with-callback.js 0xdd5eaa61d0d0476d7653490daa22b67e7e77ab78 "callback(uint256)" 100 --network local
Using network 'local'.

Successfully requested relay entry with a callback. RequestId = 4

---Transaction Summary---
From:0xfa3da235947aab49d439f3bcb46effd1a7237e32
To:0x5d1a5270c7cf288e81d4f6b4276a3c8ba0d0e6b3
BlockNumber:78247
TotalGas:198836
TransactionHash:0x6c7c92416be57b56f199c97d56165e176f770819af37ed5b57d8052c3b918c26
--------------------------
pragma solidity >=0.4.21 <0.6.0;

contract Caller { 
    uint256 internal _lastEntry;

    function callback(uint256 entry) public {
        _lastEntry = entry;
    }
    
    function lastEntry() public view returns (uint256)
    {
        return _lastEntry;
    }
}

image

@pdyraga
Copy link
Member

pdyraga commented Jul 4, 2019

Things that still need to be addressed in separate PRs:

  • operator contract selection
  • operator contract shouldn't trigger group selection - see this conversation

@pdyraga
Copy link
Member

pdyraga commented Jul 4, 2019

I left some comments but they are all non-blocking. I'll try to address some of them in a separate PR today.

@pdyraga pdyraga merged commit 759a03b into master Jul 4, 2019
@pdyraga pdyraga deleted the upgradeable-contract-components branch July 4, 2019 10:39
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.

5 participants