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

Rename GroupID and change it to bytes #595

Merged
merged 3 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func submitRelayEntrySeed(c *cli.Context) error {
entry := &event.Entry{
RequestID: big.NewInt(int64(requestID)),
Value: relay.GenesisEntryValue(),
GroupID: big.NewInt(int64(requestID)),
GroupPubKey: big.NewInt(0).Bytes(),
PreviousEntry: big.NewInt(0),
Timestamp: time.Now().UTC(),
Seed: big.NewInt(0),
Expand Down
2 changes: 1 addition & 1 deletion cmd/smoketest.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func SmokeTest(c *cli.Context) error {
chainHandle.ThresholdRelay().SubmitRelayEntry(&event.Entry{
RequestID: big.NewInt(0),
Value: big.NewInt(0),
GroupID: big.NewInt(0),
GroupPubKey: big.NewInt(0).Bytes(),
Seed: big.NewInt(0),
PreviousEntry: &big.Int{},
})
Expand Down
12 changes: 6 additions & 6 deletions contracts/solidity/contracts/KeepRandomBeaconImplV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract KeepRandomBeaconImplV1 is Ownable {

// These are the public events that are used by clients
event RelayEntryRequested(uint256 requestID, uint256 payment, uint256 blockReward, uint256 seed, uint blockNumber);
event RelayEntryGenerated(uint256 requestID, uint256 requestResponse, uint256 requestGroupID, uint256 previousEntry, uint blockNumber, uint256 seed);
event RelayEntryGenerated(uint256 requestID, uint256 requestResponse, bytes requestGroupPubKey, uint256 previousEntry, uint blockNumber, uint256 seed);

uint256 internal _seq;
uint256 internal _minPayment;
Expand All @@ -31,7 +31,7 @@ contract KeepRandomBeaconImplV1 is Ownable {
mapping (uint256 => address) internal _requestPayer;
mapping (uint256 => uint256) internal _requestPayment;
mapping (uint256 => uint256) internal _blockReward;
mapping (uint256 => uint256) internal _requestGroup;
mapping (uint256 => bytes) internal _requestGroup;

mapping (uint256 => bool) internal _relayEntryRequested;

Expand Down Expand Up @@ -140,9 +140,9 @@ contract KeepRandomBeaconImplV1 is Ownable {
* @dev Creates a new relay entry and stores the associated data on the chain.
* @param requestID The request that started this generation - to tie the results back to the request.
* @param groupSignature The generated random number.
* @param groupID Public key of the group that generated the threshold signature.
* @param groupPubKey Public key of the group that generated the threshold signature.
*/
function relayEntry(uint256 requestID, uint256 groupSignature, uint256 groupID, uint256 previousEntry, uint256 seed) public {
function relayEntry(uint256 requestID, uint256 groupSignature, bytes groupPubKey, uint256 previousEntry, uint256 seed) public {
// Temporary solution for M2. Every group member submits a new relay entry
// with the same request ID and we filter out duplicates here.
// This behavior will change post-M2 when we'll integrate phase 14 and/or
Expand All @@ -154,8 +154,8 @@ contract KeepRandomBeaconImplV1 is Ownable {

// TODO: validate groupSignature using BLS.sol

_requestGroup[requestID] = groupID;
emit RelayEntryGenerated(requestID, groupSignature, groupID, previousEntry, block.number, seed);
_requestGroup[requestID] = groupPubKey;
emit RelayEntryGenerated(requestID, groupSignature, groupPubKey, previousEntry, block.number, seed);
GroupContract(_groupContract).runGroupSelection(groupSignature);
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/solidity/contracts/KeepRandomBeaconStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract KeepRandomBeaconStub is Ownable {

// These are the public events that are used by clients
event RelayEntryRequested(uint256 requestID, uint256 payment, uint256 blockReward, uint256 seed, uint blockNumber);
event RelayEntryGenerated(uint256 requestID, uint256 requestResponse, uint256 requestGroupID, uint256 previousEntry, uint blockNumber);
event RelayEntryGenerated(uint256 requestID, uint256 requestResponse, uint256 requestGroupPubKey, uint256 previousEntry, uint blockNumber);
event RelayResetEvent(uint256 lastValidRelayEntry, uint256 lastValidRelayTxHash, uint256 lastValidRelayBlock);
event SubmitGroupPublicKeyEvent(byte[] groupPublicKey, uint256 requestID, uint256 activationBlockHeight);

Expand Down Expand Up @@ -58,8 +58,8 @@ contract KeepRandomBeaconStub is Ownable {

// Return mocked data instead of interacting with relay.
uint256 groupSignature = uint256(keccak256(abi.encodePacked(_previousEntry, block.timestamp, seed)));
uint256 groupID = uint256(keccak256(abi.encodePacked(block.timestamp, uint(1))));
emit RelayEntryGenerated(requestID, groupSignature, groupID, _previousEntry, block.number);
uint256 groupPubKey = uint256(keccak256(abi.encodePacked(block.timestamp, uint(1))));
emit RelayEntryGenerated(requestID, groupSignature, groupPubKey, _previousEntry, block.number);

_previousEntry = groupSignature;
return requestID;
Expand Down
2 changes: 1 addition & 1 deletion pkg/beacon/relay/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Entry struct {
RequestID *big.Int
Value *big.Int
GroupID *big.Int
GroupPubKey []byte
PreviousEntry *big.Int
Timestamp time.Time
Seed *big.Int
Expand Down
2 changes: 1 addition & 1 deletion pkg/beacon/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *Node) GenerateRelayEntryIfEligible(
Value: rightSizeSignature,
PreviousEntry: previousValue,
Timestamp: time.Now().UTC(),
GroupID: &big.Int{},
GroupPubKey: signer.member.GroupPublicKeyBytes(),
Seed: seed,
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/chain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (ec *ethereumChain) SubmitRelayEntry(

_, err = ec.keepRandomBeaconContract.SubmitRelayEntry(
newEntry.RequestID,
newEntry.GroupID,
newEntry.GroupPubKey,
newEntry.PreviousEntry,
newEntry.Value,
newEntry.Seed,
Expand All @@ -285,15 +285,15 @@ func (ec *ethereumChain) OnRelayEntryGenerated(
func(
requestID *big.Int,
requestResponse *big.Int,
requestGroupID *big.Int,
requestGroupPubKey []byte,
previousEntry *big.Int,
blockNumber *big.Int,
seed *big.Int,
) {
handle(&event.Entry{
RequestID: requestID,
Value: requestResponse,
GroupID: requestGroupID,
GroupPubKey: requestGroupPubKey,
PreviousEntry: previousEntry,
Timestamp: time.Now().UTC(),
Seed: seed,
Expand Down
8 changes: 4 additions & 4 deletions pkg/chain/ethereum/keep_random_beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (krb *KeepRandomBeacon) RequestRelayEntry(
// SubmitRelayEntry submits a group signature for consideration.
func (krb *KeepRandomBeacon) SubmitRelayEntry(
requestID *big.Int,
groupID *big.Int,
groupPubKey []byte,
previousEntry *big.Int,
groupSignature *big.Int,
seed *big.Int,
Expand All @@ -129,7 +129,7 @@ func (krb *KeepRandomBeacon) SubmitRelayEntry(
krb.transactorOptions,
requestID,
groupSignature,
groupID,
groupPubKey,
previousEntry,
seed,
)
Expand Down Expand Up @@ -206,7 +206,7 @@ func (krb *KeepRandomBeacon) WatchRelayEntryRequested(
type relayEntryGeneratedFunc func(
requestID *big.Int,
requestResponse *big.Int,
requestGroupID *big.Int,
requestGroupPubKey []byte,
previousEntry *big.Int,
blockNumber *big.Int,
seed *big.Int,
Expand Down Expand Up @@ -245,7 +245,7 @@ func (krb *KeepRandomBeacon) WatchRelayEntryGenerated(
success(
event.RequestID,
event.RequestResponse,
event.RequestGroupID,
event.RequestGroupPubKey,
event.PreviousEntry,
event.BlockNumber,
event.Seed,
Expand Down
14 changes: 7 additions & 7 deletions pkg/chain/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *localChain) SubmitGroupPublicKey(
requestID *big.Int,
groupPublicKey []byte,
) *async.GroupRegistrationPromise {
groupID := requestID.String()
groupPubKey := requestID.String()

groupRegistrationPromise := &async.GroupRegistrationPromise{}
groupRegistration := &event.GroupRegistration{
Expand All @@ -118,12 +118,12 @@ func (c *localChain) SubmitGroupPublicKey(

c.groupRegistrationsMutex.Lock()
defer c.groupRegistrationsMutex.Unlock()
if existing, exists := c.groupRegistrations[groupID]; exists {
if existing, exists := c.groupRegistrations[groupPubKey]; exists {
if bytes.Compare(existing, groupPublicKey) != 0 {
err := fmt.Errorf(
"mismatched public key for [%s], submission failed; \n"+
"[%v] vs [%v]",
groupID,
groupPubKey,
existing,
groupPublicKey,
)
Expand All @@ -136,7 +136,7 @@ func (c *localChain) SubmitGroupPublicKey(

return groupRegistrationPromise
}
c.groupRegistrations[groupID] = groupPublicKey
c.groupRegistrations[groupPubKey] = groupPublicKey

groupRegistrationPromise.Fulfill(groupRegistration)

Expand All @@ -163,13 +163,13 @@ func (c *localChain) SubmitRelayEntry(entry *event.Entry) *async.RelayEntryPromi
c.groupRelayEntriesMutex.Lock()
defer c.groupRelayEntriesMutex.Unlock()

existing, exists := c.groupRelayEntries[entry.GroupID.String()+entry.RequestID.String()]
existing, exists := c.groupRelayEntries[string(entry.GroupPubKey)+entry.RequestID.String()]
if exists {
if existing.Cmp(entry.Value) != 0 {
err := fmt.Errorf(
"mismatched signature for [%v], submission failed; \n"+
"[%v] vs [%v]\n",
entry.GroupID,
entry.GroupPubKey,
existing,
entry.Value,
)
Expand All @@ -181,7 +181,7 @@ func (c *localChain) SubmitRelayEntry(entry *event.Entry) *async.RelayEntryPromi

return relayEntryPromise
}
c.groupRelayEntries[entry.GroupID.String()+entry.RequestID.String()] = entry.Value
c.groupRelayEntries[string(entry.GroupPubKey)+entry.RequestID.String()] = entry.Value

c.handlerMutex.Lock()
for _, handler := range c.relayEntryHandlers {
Expand Down
2 changes: 1 addition & 1 deletion pkg/chain/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestLocalSubmitRelayEntry(t *testing.T) {
relayEntryPromise := chainHandle.SubmitRelayEntry(
&event.Entry{
RequestID: big.NewInt(int64(19)),
GroupID: big.NewInt(int64(1)),
GroupPubKey: []byte("1"),
},
)

Expand Down