diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-03 14:08:52 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:59 +0800 |
commit | 6d75ecc6fe12cd0f767c9df4cb6fff8a514f4046 (patch) | |
tree | 3ec2d9f679b902eb69b1dde5f763195d39ac9789 | |
parent | fbe6ddc62f7ebed15c6705f108d36d889c15e73d (diff) | |
download | dexon-6d75ecc6fe12cd0f767c9df4cb6fff8a514f4046.tar.gz dexon-6d75ecc6fe12cd0f767c9df4cb6fff8a514f4046.tar.zst dexon-6d75ecc6fe12cd0f767c9df4cb6fff8a514f4046.zip |
core: vm: fineFailStopDKG if MPK not registered (#329)
* core: vm: fineFailStopDKG if MPK not registered
* prevent on-chain randomness
-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 759727aa3..9f994c6fd 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1350,6 +1350,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) @@ -1367,19 +1375,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) { @@ -1591,7 +1607,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 ae7755a06..5037a7cc0 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -1016,6 +1016,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) |