-
Notifications
You must be signed in to change notification settings - Fork 78
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
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
942c440
Remove proxy and eternal storage setup from Keep Group contract
ngrinkevich 6379be6
Move withdrawal functionality into a mixin contract
ngrinkevich 46b0618
Minor folder restructure
ngrinkevich f331f0c
Rename KeepGroup to KeepRandomBeaconBackend
ngrinkevich 1cc8238
Rename KeepRandomBeacon to KeepRandomBeaconFrontend
ngrinkevich 57b3cb2
Rename GroupContract to BackendContract
ngrinkevich 00e1fec
Use better names for backend/frontend beacon layout in js tests
ngrinkevich f91d7ac
Split request and relay entry functionality between frontend and back…
ngrinkevich 58d12fa
Minor cleanup in tests
ngrinkevich a36fef3
More renaming + cleanup
ngrinkevich f6f0df0
Update go code to perform relay entry on the backend contract
ngrinkevich 5355ffe
Update go code to watch relay request on the backend contract
ngrinkevich 57ec6a6
Rename previousEntry to groupSelectionSeed
ngrinkevich 4ea4cf3
Save selection seed on group selection start
ngrinkevich 47e962a
Make sure frontend sends signing group selection seed to the backend
ngrinkevich 0880a99
Refactor contract initialization with a helper
ngrinkevich 78e71a5
Merge branch 'master' into upgradeable-contract-components
ngrinkevich ed97496
Refactor init script to accept a list of contracts
ngrinkevich cd1c77f
Fix group selection tests
ngrinkevich b7b4af3
Refactor group expiration tests with contracts init helper
ngrinkevich 53b072a
Remove accidentally added files during merge conflict
ngrinkevich 1345752
Cleanup and fix solidity tests
ngrinkevich 0b1d09b
Speed up solidity tests
ngrinkevich fe162ad
Fix small balance check in withdraw ether test
ngrinkevich cb440a1
Update go code to new backend/frontend naming
ngrinkevich d9aa152
Use simpler name for KeepRandomBeaconFrontend proxy contract
ngrinkevich 619f25b
Include backend contracts during contract generation
ngrinkevich 8ac0311
Make sure relay entry and its events set to backend contract
ngrinkevich c4636f6
Merge branch 'master' into upgradeable-contract-components
ngrinkevich 8627b9d
Rename Backend contract to Operator contract
ngrinkevich 7b6f90a
Rename Frontend contract to Service contract
ngrinkevich 8037eb1
Update service contract to accept multiple operator contracts
ngrinkevich cd0feef
Update operator contract to accept multiple service contracts
ngrinkevich 3447272
Move relay request timeout constant to operator contract
ngrinkevich 92798fc
Rename operator/service contracts interface methods to match RFC 9
ngrinkevich 38d08d7
Rename runGroupSelection to createGroup to match RFC9
ngrinkevich 5b2b217
Add group created callback to update number of groups on service cont…
ngrinkevich bfd4072
Merge branch 'master' into upgradeable-contract-components
ngrinkevich 3fb881d
Make sure to clean generated files from gen/cmd folder
ngrinkevich 856e316
Fix missing renaming in docs and provisioning scripts
ngrinkevich 22d3089
Merge branch 'master' into upgradeable-contract-components
ngrinkevich 0d8870b
Add request relay callback to the service contract + cleanup tests
ngrinkevich e79e566
Remove accidentally added file during merge
ngrinkevich a6bd9ef
Add missing minimum payment check
ngrinkevich f4a9ade
Fix broken test
ngrinkevich a5b2a92
Minor renaming and cleanups
ngrinkevich 0aa2b32
Fix conflicting `groupActiveTime` name
ngrinkevich 8ee780e
Remove unnecessary getExpiredOffset() method
ngrinkevich b4413f5
Use better file names for solidity tests
ngrinkevich 28b49d1
Minor improvement in config
ngrinkevich a6cb4ac
Remove unused event
ngrinkevich 46127a6
Remove unnecessary await
ngrinkevich 184588a
Add missing event for entryId on service contract
ngrinkevich e03540d
Fix bug with duplicated entry counter
ngrinkevich a659bdb
Remove unused stub contract
ngrinkevich a29acfc
Remove accidentally added files during merge master
ngrinkevich 37e99f0
Make sure to get request ID from operator contract
ngrinkevich dd68089
Make callback mapping internal
ngrinkevich ff0778e
Minor improvements and cleanup
ngrinkevich dd80faf
Add `selectOperatorContract` method
ngrinkevich 76e82cc
Fix broken genesis entry script
ngrinkevich 8e953d0
Minor cleanup
ngrinkevich 159faa1
Remove KeepRandomBeaconService from Go side
ngrinkevich f63207d
Compile contracts before truffle test
ngrinkevich b4df69b
Minor comments improvements
ngrinkevich 3c84d71
Rename requestID to signingId
ngrinkevich 9dc8c83
Rename Request to SigningRequest
ngrinkevich 44127d2
Rename entryId to requestId
ngrinkevich a4b3354
Move initialize() to the top of the file
ngrinkevich 42a64ac
Remove number of groups storage from service contracts
ngrinkevich 4533cb0
Remove setGroupSize
ngrinkevich 0517d8a
Rename operator relay entry events to SigningRequested and SigningCom…
ngrinkevich 2b87246
Use better names for signing request events
ngrinkevich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Merge branch 'master' into upgradeable-contract-components
- Loading branch information
commit 22d30890da3c393f1cb08bf21df5cc265da7d5ca
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,22 @@ contract KeepRandomBeaconServiceImplV1 is Ownable, DelayedWithdrawal { | |
* @return An uint256 representing uniquely generated entry Id. | ||
*/ | ||
function requestRelayEntry(uint256 seed) public payable returns (uint256) { | ||
require( | ||
msg.value >= _minPayment, | ||
"Payment is less than required minimum." | ||
); | ||
|
||
_entryCounter++; | ||
ngrinkevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return requestRelayEntry(seed, address(0), ""); | ||
} | ||
|
||
/** | ||
* @dev Creates a request to generate a new relay entry, which will include a | ||
* random number (by signing the previous entry's random number). | ||
* @param seed Initial seed random value from the client. It should be a cryptographically generated random value. | ||
* @param callbackContract Callback contract address. Callback is called once a new relay entry has been generated. | ||
* @param callbackMethod Callback contract method signature. String representation of your method with a single | ||
* uint256 input parameter i.e. "relayEntryCallback(uint256)". | ||
* @return An uint256 representing uniquely generated relay request ID. It is also returned as part of the event. | ||
*/ | ||
function requestRelayEntry(uint256 seed, address callbackContract, string memory callbackMethod) public payable returns (uint256) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we drop the empty line here? |
||
_entryCounter++; | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
contracts/solidity/contracts/examples/CallbackContract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma solidity ^0.5.4; | ||
|
||
|
||
/** | ||
* @title CallbackContract | ||
* @dev Example callback contract for Random Beacon. | ||
*/ | ||
contract CallbackContract { | ||
|
||
uint256 internal _lastEntry; | ||
|
||
/** | ||
* @dev Example of a callback method. Method signature can be | ||
* calculated as bytes4(keccak256("callback(uint256)") | ||
*/ | ||
function callback(uint256 requestResponse) | ||
public | ||
{ | ||
_lastEntry = requestResponse; | ||
} | ||
|
||
/** | ||
* @dev Returns previous entry. | ||
*/ | ||
function lastEntry() public view returns (uint256) | ||
{ | ||
return _lastEntry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const KeepRandomBeaconService = artifacts.require('KeepRandomBeaconService.sol') | ||
const KeepRandomBeaconServiceImplV1 = artifacts.require("KeepRandomBeaconServiceImplV1.sol") | ||
|
||
// The data below should match genesis relay request data defined on contract | ||
// initialization i.e. in 2_deploy_contracts.js. Successful genesis entry will | ||
// trigger creation of the first group that will be chosen to respond on the | ||
// next relay request, resulting another relay entry with creation of another | ||
// group and so on. | ||
|
||
// https://www.wolframalpha.com/input/?i=pi+to+78+digits | ||
const previousEntry = web3.utils.toBN('31415926535897932384626433832795028841971693993751058209749445923078164062862') | ||
|
||
// https://www.wolframalpha.com/input/?i=e+to+78+digits | ||
const seed = web3.utils.toBN('27182818284590452353602874713526624977572470936999595749669676277240766303535') | ||
|
||
// Data generated using client keep-core/pkg/bls package signing previous entry using master secret key '123' | ||
const groupPubKey = "0x1f1954b33144db2b5c90da089e8bde287ec7089d5d6433f3b6becaefdb678b1b2a9de38d14bef2cf9afc3c698a4211fa7ada7b4f036a2dfef0dc122b423259d0" | ||
const groupSignature = web3.utils.toBN('10920102476789591414949377782104707130412218726336356788412941355500907533021') | ||
|
||
module.exports = async function () { | ||
|
||
const keepRandomBeaconService = await KeepRandomBeaconService.deployed() | ||
let contract = await KeepRandomBeaconServiceImplV1.at(keepRandomBeaconService.address) | ||
try { | ||
await contract.relayEntry(1, groupSignature, groupPubKey, previousEntry, seed) | ||
ngrinkevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log('Genesis entry successfully submitted.') | ||
} catch(error) { | ||
console.error('Genesis entry submission failed with', error) | ||
} | ||
|
||
process.exit() | ||
} |
31 changes: 31 additions & 0 deletions
31
contracts/solidity/scripts/request-relay-entry-with-callback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const crypto = require("crypto") | ||
const KeepRandomBeaconServiceImplV1 = artifacts.require("KeepRandomBeaconServiceImplV1.sol"); | ||
const KeepRandomBeaconService = artifacts.require('KeepRandomBeaconService.sol'); | ||
|
||
// Example usage: | ||
// truffle exec ./scripts/request-relay-entry-with-callback.js yourContractAddress "callbackMethodName" payment | ||
// truffle exec ./scripts/request-relay-entry-with-callback.js 0x9F57C01059057d821c6b4B04A4598322661C934F "callback(uint256)" 100 | ||
|
||
module.exports = async function() { | ||
|
||
const keepRandomBeaconService = await KeepRandomBeaconService.deployed() | ||
const contractInstance = await KeepRandomBeaconServiceImplV1.at(keepRandomBeaconService.address) | ||
|
||
try { | ||
let tx = await contractInstance.methods['requestRelayEntry(uint256,address,string)'](crypto.randomBytes(32), process.argv[4], process.argv[5], {value: process.argv[6]}) | ||
console.log('Successfully requested relay entry with a callback. RequestId =', tx.logs[0].args.requestID.toString()) | ||
console.log( | ||
'\n---Transaction Summary---' + '\n' + | ||
'From:' + tx.receipt.from + '\n' + | ||
'To:' + tx.receipt.to + '\n' + | ||
'BlockNumber:' + tx.receipt.blockNumber + '\n' + | ||
'TotalGas:' + tx.receipt.cumulativeGasUsed + '\n' + | ||
'TransactionHash:' + tx.receipt.transactionHash + '\n' + | ||
'--------------------------' | ||
) | ||
} catch(error) { | ||
console.error('Request failed with', error) | ||
} | ||
|
||
process.exit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
const KeepRandomBeaconServiceImplV1 = artifacts.require("KeepRandomBeaconServiceImplV1"); | ||
const crypto = require("crypto") | ||
const KeepRandomBeaconServiceImplV1 = artifacts.require("KeepRandomBeaconServiceImplV1.sol"); | ||
const KeepRandomBeaconService = artifacts.require('KeepRandomBeaconService.sol'); | ||
|
||
module.exports = async function() { | ||
|
||
const keepRandomBeaconServiceProxy = await KeepRandomBeaconService.deployed(); | ||
const keepRandomBeaconService = await KeepRandomBeaconService.deployed() | ||
const contractInstance = await KeepRandomBeaconServiceImplV1.at(keepRandomBeaconService.address) | ||
|
||
async function requestRelayEntry() { | ||
|
||
let crypto = require("crypto"); | ||
let KeepRandomBeaconContractAddress = await KeepRandomBeaconServiceImplV1.at(keepRandomBeaconServiceProxy.address); | ||
|
||
// Generate 32 byte sort of random number | ||
try { | ||
relayEntrySeed = crypto.randomBytes(32); | ||
} | ||
catch(error) { | ||
console.error(error); | ||
} | ||
|
||
try { | ||
let requestEntry = await KeepRandomBeaconContractAddress.requestRelayEntry(relayEntrySeed, {value: 2}); | ||
console.log( | ||
'---Transaction Summary---' + '\n' + | ||
'From:' + requestEntry.receipt.from + '\n' + | ||
'To:' + requestEntry.receipt.to + '\n' + | ||
'BlockNumber:' + requestEntry.receipt.blockNumber + '\n' + | ||
'TotalGas:' + requestEntry.receipt.cumulativeGasUsed + '\n' + | ||
'TransactionHash:' + requestEntry.receipt.transactionHash + '\n' + | ||
'--------------------------' | ||
); | ||
} | ||
catch(error) { | ||
console.log('Request Failed:'); | ||
console.error(error); | ||
} | ||
try { | ||
let tx = await contractInstance.requestRelayEntry(crypto.randomBytes(32), {value: 2}) | ||
console.log('Successfully requested relay entry with RequestId =', tx.logs[0].args.requestID.toString()) | ||
console.log( | ||
'\n---Transaction Summary---' + '\n' + | ||
'From:' + tx.receipt.from + '\n' + | ||
'To:' + tx.receipt.to + '\n' + | ||
'BlockNumber:' + tx.receipt.blockNumber + '\n' + | ||
'TotalGas:' + tx.receipt.cumulativeGasUsed + '\n' + | ||
'TransactionHash:' + tx.receipt.transactionHash + '\n' + | ||
'--------------------------' | ||
) | ||
} catch(error) { | ||
console.error('Request failed with', error) | ||
} | ||
|
||
requestRelayEntry(); | ||
} | ||
process.exit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {bls} from './helpers/data'; | ||
const Proxy = artifacts.require('./KeepRandomBeacon.sol'); | ||
const KeepRandomBeacon = artifacts.require('./KeepRandomBeaconImplV1.sol'); | ||
const KeepGroupStub = artifacts.require('./KeepGroupStub.sol'); | ||
const CallbackContract = artifacts.require('./examples/CallbackContract.sol'); | ||
|
||
contract('TestKeepRandomBeaconCallback', function() { | ||
const relayRequestTimeout = 10; | ||
let impl, proxy, keepRandomBeacon, callbackContract, keepGroupStub; | ||
|
||
before(async () => { | ||
impl = await KeepRandomBeacon.new(); | ||
proxy = await Proxy.new(impl.address); | ||
keepRandomBeacon = await KeepRandomBeacon.at(proxy.address); | ||
|
||
keepGroupStub = await KeepGroupStub.new(); | ||
await keepRandomBeacon.initialize(1, 1, bls.previousEntry, bls.groupPubKey, keepGroupStub.address, | ||
relayRequestTimeout); | ||
callbackContract = await CallbackContract.new(); | ||
}); | ||
|
||
it("should produce entry if callback contract was not provided", async function() { | ||
let tx = await keepRandomBeacon.requestRelayEntry(bls.seed, {value: 10}); | ||
let requestId = tx.logs[0].args.requestID; | ||
await keepRandomBeacon.relayEntry(requestId, bls.groupSignature, bls.groupPubKey, bls.previousEntry, bls.seed); | ||
|
||
let result = await keepRandomBeacon.previousEntry(); | ||
assert.isTrue(result.eq(bls.groupSignature), "Value should be updated on beacon contract."); | ||
}); | ||
|
||
it("should successfully call method on a callback contract", async function() { | ||
let tx = await keepRandomBeacon.methods['requestRelayEntry(uint256,address,string)'](bls.seed, callbackContract.address, "callback(uint256)", {value: 10}); | ||
let requestId = tx.logs[0].args.requestID; | ||
|
||
let result = await callbackContract.lastEntry(); | ||
assert.isFalse(result.eq(bls.groupSignature), "Entry value on the callback contract should not be the same as next relay entry."); | ||
|
||
await keepRandomBeacon.relayEntry(requestId, bls.groupSignature, bls.groupPubKey, bls.previousEntry, bls.seed); | ||
|
||
result = await callbackContract.lastEntry(); | ||
assert.isTrue(result.eq(bls.groupSignature), "Value updated by the callback should be the same as relay entry."); | ||
}); | ||
|
||
}); |
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we drop the empty line here?