diff options
author | Wei-Ning Huang <w@byzantine-lab.io> | 2019-08-27 23:20:24 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-09-17 16:57:31 +0800 |
commit | 8d2396a5aa3f9963369a7d37128447b5be20903b (patch) | |
tree | 6f016d09a8ddd14b6356c070a8e5054d2297624e | |
parent | d626d8feb05b259edb87f210904cc004521dcfaa (diff) | |
download | go-tangerine-8d2396a5aa3f9963369a7d37128447b5be20903b.tar.gz go-tangerine-8d2396a5aa3f9963369a7d37128447b5be20903b.tar.zst go-tangerine-8d2396a5aa3f9963369a7d37128447b5be20903b.zip |
core: vm: fix DKG nacking threshold
DKG nacking threshold should only be t + 1 instead of 2t + 1
-rw-r--r-- | core/vm/oracle_contracts.go | 32 | ||||
-rw-r--r-- | vendor/vendor.json | 2 |
2 files changed, 19 insertions, 15 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index 23a005269..f30ed3bdb 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1572,10 +1572,11 @@ func (g *GovernanceContract) addDKGComplaint(comp []byte) ([]byte, error) { } // Calculate 2f + 1 - threshold := 2*g.configNotarySetSize(g.evm.Round).Uint64()/3 + 1 + threshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ + NotarySetSize: uint32(g.configNotarySetSize(g.evm.Round).Uint64())}) // If 2f + 1 of DKG set is finalized, one can not propose complaint anymore. - if g.state.DKGFinalizedsCount().Uint64() >= threshold { + if g.state.DKGFinalizedsCount().Uint64() >= uint64(threshold) { return nil, errExecutionReverted } @@ -1672,10 +1673,11 @@ func (g *GovernanceContract) addDKGMasterPublicKey(mpk []byte) ([]byte, error) { } // Calculate 2f + 1 - threshold := 2*g.configNotarySetSize(g.evm.Round).Uint64()/3 + 1 + threshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ + NotarySetSize: uint32(g.configNotarySetSize(g.evm.Round).Uint64())}) // If 2f + 1 of DKG set is mpk ready, one can not propose mpk anymore. - if g.state.DKGMPKReadysCount().Uint64() >= threshold { + if g.state.DKGMPKReadysCount().Uint64() >= uint64(threshold) { return nil, errExecutionReverted } @@ -1765,12 +1767,13 @@ func (g *GovernanceContract) addDKGFinalize(finalize []byte) ([]byte, error) { g.state.IncDKGFinalizedsCount() } - threshold := 2*g.configNotarySetSize(g.evm.Round).Uint64()/3 + 1 + threshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ + NotarySetSize: uint32(g.configNotarySetSize(g.evm.Round).Uint64())}) - if g.state.DKGFinalizedsCount().Uint64() == threshold { - tsigThreshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ + if g.state.DKGFinalizedsCount().Uint64() == uint64(threshold) { + nackThreshold := coreUtils.GetDKGNackThreshold(&coreTypes.Config{ NotarySetSize: uint32(g.configNotarySetSize(g.evm.Round).Uint64())}) - g.fineFailStopDKG(tsigThreshold) + g.fineFailStopDKG(nackThreshold) } return g.useGas(GovernanceActionGasCost) @@ -2258,8 +2261,6 @@ func (g *GovernanceContract) resetDKG(newSignedCRS []byte) ([]byte, error) { return nil, errExecutionReverted } - tsigThreshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ - NotarySetSize: uint32(g.configNotarySetSize(nextRound).Uint64())}) // Check if next DKG has not enough of success. if g.state.DKGSuccessesCount().Uint64() >= uint64(coreUtils.GetDKGValidThreshold(&coreTypes.Config{ @@ -2267,11 +2268,12 @@ func (g *GovernanceContract) resetDKG(newSignedCRS []byte) ([]byte, error) { })) { // Check if next DKG did not success. // Calculate 2f + 1 - threshold := 2*g.configNotarySetSize(nextRound).Uint64()/3 + 1 + threshold := coreUtils.GetDKGThreshold(&coreTypes.Config{ + NotarySetSize: uint32(g.configNotarySetSize(nextRound).Uint64())}) // If 2f + 1 of DKG set is finalized, check if DKG succeeded. - if g.state.DKGFinalizedsCount().Uint64() >= threshold { - gpk, err := g.coreDKGUtil.NewGroupPublicKey(&g.state, nextRound, tsigThreshold) + if g.state.DKGFinalizedsCount().Uint64() >= uint64(threshold) { + gpk, err := g.coreDKGUtil.NewGroupPublicKey(&g.state, nextRound, threshold) if gpk, ok := gpk.(*dkgTypes.GroupPublicKey); ok { if len(gpk.QualifyNodeIDs) < coreUtils.GetDKGValidThreshold(&coreTypes.Config{ NotarySetSize: uint32(g.configNotarySetSize(nextRound).Uint64())}) { @@ -2292,7 +2294,9 @@ func (g *GovernanceContract) resetDKG(newSignedCRS []byte) ([]byte, error) { } // Fine fail stop DKGs. - g.fineFailStopDKG(tsigThreshold) + nackThreshold := coreUtils.GetDKGNackThreshold(&coreTypes.Config{ + NotarySetSize: uint32(g.configNotarySetSize(nextRound).Uint64())}) + g.fineFailStopDKG(nackThreshold) // Update CRS. state, err := g.util.GetRoundState(round.Uint64()) diff --git a/vendor/vendor.json b/vendor/vendor.json index 856f5d32d..89e3a539d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -727,7 +727,7 @@ "versionExact": "master" }, { - "checksumSHA1": "fGYfxHDDS2gbDGdKpMiXSNMxE5w=", + "checksumSHA1": "WUtiTpef7+yqS9ptOUgC8bQaaAM=", "path": "github.com/tangerine-network/tangerine-consensus/core/utils", "revision": "1eecef2512d9c8a2bd3c0ef4af7a7b830fa30a0f", "revisionTime": "2019-09-16T06:50:28Z", |