aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-06 18:25:25 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:57 +0800
commit7145a003009c2178994c2278370ff79e2d831ed9 (patch)
treea88e6644393c17b33316c5e6046344523ee7eb01 /core/vm
parentd18c109ba821efbf9edf80adbec0b971b78644e3 (diff)
downloaddexon-7145a003009c2178994c2278370ff79e2d831ed9.tar
dexon-7145a003009c2178994c2278370ff79e2d831ed9.tar.gz
dexon-7145a003009c2178994c2278370ff79e2d831ed9.tar.bz2
dexon-7145a003009c2178994c2278370ff79e2d831ed9.tar.lz
dexon-7145a003009c2178994c2278370ff79e2d831ed9.tar.xz
dexon-7145a003009c2178994c2278370ff79e2d831ed9.tar.zst
dexon-7145a003009c2178994c2278370ff79e2d831ed9.zip
core: fix dkg
Diffstat (limited to 'core/vm')
-rw-r--r--core/vm/oracle_contracts.go59
1 files changed, 47 insertions, 12 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index cf060e9ac..fa5bea54c 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -1226,17 +1226,42 @@ func (g *GovernanceContract) penalize() ([]byte, error) {
func (g *GovernanceContract) configDKGSetSize(round *big.Int) *big.Int {
s, err := getConfigState(g.evm, round)
if err != nil {
- panic(err)
+ return big.NewInt(0)
}
return s.DKGSetSize()
}
+
func (g *GovernanceContract) getDKGSet(round *big.Int) map[coreTypes.NodeID]struct{} {
- target := coreTypes.NewDKGSetTarget(coreCommon.Hash(g.state.CRS()))
+ crsRound := g.state.CRSRound()
+ var crs common.Hash
+ cmp := round.Cmp(crsRound)
+ if round.Cmp(big.NewInt(int64(dexCore.DKGDelayRound))) <= 0 {
+ state, err := getRoundState(g.evm, big.NewInt(0))
+ if err != nil {
+ return map[coreTypes.NodeID]struct{}{}
+ }
+ crs = state.CRS()
+ for i := uint64(0); i < round.Uint64(); i++ {
+ crs = crypto.Keccak256Hash(crs[:])
+ }
+ } else if cmp > 0 {
+ return map[coreTypes.NodeID]struct{}{}
+ } else if cmp == 0 {
+ crs = g.state.CRS()
+ } else {
+ state, err := getRoundState(g.evm, round)
+ if err != nil {
+ return map[coreTypes.NodeID]struct{}{}
+ }
+ crs = state.CRS()
+ }
+
+ target := coreTypes.NewDKGSetTarget(coreCommon.Hash(crs))
ns := coreTypes.NewNodeSet()
state, err := getConfigState(g.evm, round)
if err != nil {
- panic(err)
+ return map[coreTypes.NodeID]struct{}{}
}
for _, x := range state.QualifiedNodes() {
mpk, err := ecdsa.NewPublicKeyFromByteSlice(x.PublicKey)
@@ -1265,6 +1290,10 @@ func (g *GovernanceContract) clearDKG() {
}
func (g *GovernanceContract) addDKGComplaint(round *big.Int, comp []byte) ([]byte, error) {
+ if round.Uint64() != g.evm.Round.Uint64()+1 {
+ return nil, errExecutionReverted
+ }
+
caller := g.contract.Caller()
offset := g.state.NodesOffsetByNodeKeyAddress(caller)
@@ -1335,16 +1364,14 @@ func (g *GovernanceContract) addDKGComplaint(round *big.Int, comp []byte) ([]byt
}
func (g *GovernanceContract) addDKGMasterPublicKey(round *big.Int, mpk []byte) ([]byte, error) {
- if g.evm.Round.Uint64() > 0 {
- if round.Uint64() != g.evm.Round.Uint64()+1 {
- return nil, errExecutionReverted
- }
+ if round.Uint64() != g.evm.Round.Uint64()+1 {
+ return nil, errExecutionReverted
+ }
- if g.state.DKGRound().Cmp(g.evm.Round) == 0 {
- // Clear DKG states for next round.
- g.clearDKG()
- g.state.SetDKGRound(round)
- }
+ if g.state.DKGRound().Cmp(g.evm.Round) == 0 {
+ // Clear DKG states for next round.
+ g.clearDKG()
+ g.state.SetDKGRound(round)
}
caller := g.contract.Caller()
@@ -1390,6 +1417,10 @@ func (g *GovernanceContract) addDKGMasterPublicKey(round *big.Int, mpk []byte) (
}
func (g *GovernanceContract) addDKGMPKReady(round *big.Int, ready []byte) ([]byte, error) {
+ if round.Uint64() != g.evm.Round.Uint64()+1 {
+ return nil, errExecutionReverted
+ }
+
caller := g.contract.Caller()
var dkgReady dkgTypes.MPKReady
@@ -1416,6 +1447,10 @@ func (g *GovernanceContract) addDKGMPKReady(round *big.Int, ready []byte) ([]byt
}
func (g *GovernanceContract) addDKGFinalize(round *big.Int, finalize []byte) ([]byte, error) {
+ if round.Uint64() != g.evm.Round.Uint64()+1 {
+ return nil, errExecutionReverted
+ }
+
caller := g.contract.Caller()
var dkgFinalize dkgTypes.Finalize