diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-03 14:08:52 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-15 22:09:55 +0800 |
commit | aff2c3533badc7415c223580c591a3274330185c (patch) | |
tree | 4a5dbb1a747841874ff1a7f2b885bb65f16322e7 /core/vm | |
parent | 359a404b587b25b863fe107d3f98c61863e6ea49 (diff) | |
download | go-tangerine-aff2c3533badc7415c223580c591a3274330185c.tar.gz go-tangerine-aff2c3533badc7415c223580c591a3274330185c.tar.zst go-tangerine-aff2c3533badc7415c223580c591a3274330185c.zip |
core: vm: fineFailStopDKG if MPK not registered (#329)
* core: vm: fineFailStopDKG if MPK not registered
* prevent on-chain randomness
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/oracle_contracts.go | 40 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 1 |
2 files changed, 29 insertions, 12 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index deeedfc15..b794ac8e5 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1348,6 +1348,14 @@ func (g *GovernanceContract) clearDKG() { } func (g *GovernanceContract) fineFailStopDKG(threshold int) { + fineNode := make(map[coreTypes.NodeID]struct{}) + dkgSet := g.getNotarySet(g.state.DKGRound()) + for id := range dkgSet { + if g.state.DKGMasterPublicKeyProposed(Bytes32(id.Hash)) { + continue + } + fineNode[id] = struct{}{} + } complaintsByID := map[coreTypes.NodeID]map[coreTypes.NodeID]struct{}{} for _, complaint := range g.state.DKGComplaints() { comp := new(dkgTypes.Complaint) @@ -1365,19 +1373,27 @@ func (g *GovernanceContract) fineFailStopDKG(threshold int) { } for id, complaints := range complaintsByID { if len(complaints) >= threshold { - offset := g.state.NodesOffsetByNodeKeyAddress(IdToAddress(id)) - // Node might have been unstaked. - if offset.Cmp(big.NewInt(0)) < 0 { - continue - } - - node := g.state.Node(offset) - amount := g.state.FineValue(big.NewInt(FineTypeFailStopDKG)) - node.Fined = new(big.Int).Add(node.Fined, amount) - g.state.UpdateNode(offset, node) - g.state.emitFined(node.Owner, amount) + fineNode[id] = struct{}{} } } + nodes := make(coreTypes.NodeIDs, 0, len(fineNode)) + for id := range fineNode { + nodes = append(nodes, id) + } + sort.Sort(nodes) + for _, id := range nodes { + offset := g.state.NodesOffsetByNodeKeyAddress(IdToAddress(id)) + // Node might have been unstaked. + if offset.Cmp(big.NewInt(0)) < 0 { + continue + } + + node := g.state.Node(offset) + amount := g.state.FineValue(big.NewInt(FineTypeFailStopDKG)) + node.Fined = new(big.Int).Add(node.Fined, amount) + g.state.UpdateNode(offset, node) + g.state.emitFined(node.Owner, amount) + } } func (g *GovernanceContract) addDKGComplaint(comp []byte) ([]byte, error) { @@ -1589,7 +1605,7 @@ func (g *GovernanceContract) addDKGFinalize(finalize []byte) ([]byte, error) { threshold := 2*g.configNotarySetSize(g.evm.Round).Uint64()/3 + 1 - if g.state.DKGFinalizedsCount().Uint64() >= threshold { + if g.state.DKGFinalizedsCount().Uint64() == threshold { tsigThreshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ NotarySetSize: uint32(g.configNotarySetSize(g.evm.Round).Uint64())}) g.fineFailStopDKG(tsigThreshold) diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index 6985eb2b9..dd7de495b 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -1015,6 +1015,7 @@ func (g *OracleContractsTestSuite) TestResetDKG() { panic(err) } g.s.PushDKGMasterPublicKey(b) + g.s.PutDKGMasterPublicKeyProposed(Bytes32(id.Hash), true) // Prepare Complaint. y := dkgTypes.Complaint{} b, err = rlp.EncodeToBytes(&y) |