aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/governance.go
diff options
context:
space:
mode:
authorWei-Ning Huang <aitjcize@gmail.com>2018-11-14 10:57:53 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:53 +0800
commit3a84568a63f64423683a1dbb9f46cee886a39270 (patch)
tree070d3478a6f2031b447148ee1d51a952565c02ab /core/vm/governance.go
parentc1138b576524413f8d5755f77aaebd759d6317fc (diff)
downloaddexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.gz
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.bz2
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.lz
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.xz
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.zst
dexon-3a84568a63f64423683a1dbb9f46cee886a39270.zip
core: validate DKG set with correct nodeset in round-2 (#19)
* vendor: sync consensus core * core: validate DKG set with correct nodeset in round-2
Diffstat (limited to 'core/vm/governance.go')
-rw-r--r--core/vm/governance.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go
index 49141761f..b38733e1a 100644
--- a/core/vm/governance.go
+++ b/core/vm/governance.go
@@ -1467,11 +1467,22 @@ func (g *GovernanceContract) penalize() {
g.contract.UseGas(g.contract.Gas)
}
-func (g *GovernanceContract) inDKGSet(nodeID coreTypes.NodeID) bool {
+func (g *GovernanceContract) inDKGSet(round *big.Int, nodeID coreTypes.NodeID) bool {
target := coreTypes.NewDKGSetTarget(coreCommon.Hash(g.state.CurrentCRS()))
ns := coreTypes.NewNodeSet()
- for _, x := range g.state.Nodes() {
+ configRound := big.NewInt(0) // If round < core.ConfigRoundShift, use 0.
+ if round.Uint64() >= core.ConfigRoundShift {
+ configRound = new(big.Int).Sub(round, big.NewInt(int64(core.ConfigRoundShift)))
+ }
+
+ statedb, err := g.evm.Context.StateAtNumber(g.state.RoundHeight(configRound).Uint64())
+ if err != nil {
+ panic(err)
+ }
+
+ state := GovernanceStateHelper{statedb}
+ for _, x := range state.Nodes() {
mpk, err := ecdsa.NewPublicKeyFromByteSlice(x.PublicKey)
if err != nil {
panic(err)
@@ -1515,7 +1526,7 @@ func (g *GovernanceContract) addDKGComplaint(round *big.Int, comp []byte) ([]byt
}
// DKGComplaint must belongs to someone in DKG set.
- if !g.inDKGSet(dkgComplaint.ProposerID) {
+ if !g.inDKGSet(round, dkgComplaint.ProposerID) {
g.penalize()
return nil, errExecutionReverted
}
@@ -1555,7 +1566,7 @@ func (g *GovernanceContract) addDKGMasterPublicKey(round *big.Int, mpk []byte) (
}
// DKGMasterPublicKey must belongs to someone in DKG set.
- if !g.inDKGSet(dkgMasterPK.ProposerID) {
+ if !g.inDKGSet(round, dkgMasterPK.ProposerID) {
g.penalize()
return nil, errExecutionReverted
}
@@ -1588,7 +1599,7 @@ func (g *GovernanceContract) addDKGFinalize(round *big.Int, finalize []byte) ([]
}
// DKGFInalize must belongs to someone in DKG set.
- if !g.inDKGSet(dkgFinalize.ProposerID) {
+ if !g.inDKGSet(round, dkgFinalize.ProposerID) {
g.penalize()
return nil, errExecutionReverted
}
@@ -1757,13 +1768,12 @@ func (g *GovernanceContract) transferOwnership(newOwner common.Address) ([]byte,
func (g *GovernanceContract) snapshotRound(round, height *big.Int) ([]byte, error) {
// Validate if this mapping is correct.
- rawHeight, ok := g.evm.Context.RoundHeight.Load(round)
+ realHeight, ok := g.evm.Context.GetRoundHeight(round.Uint64())
if !ok {
g.penalize()
return nil, errExecutionReverted
}
- realHeight := rawHeight.(uint64)
if height.Cmp(new(big.Int).SetUint64(realHeight)) != 0 {
g.penalize()
return nil, errExecutionReverted