diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/vm/oracle_contracts.go | 14 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 7 |
2 files changed, 20 insertions, 1 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index b9525e00b..f999cc6b1 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1597,7 +1597,19 @@ func (g *GovernanceContract) register( value := g.contract.Value() offset := g.state.NodesOffsetByAddress(caller) - // Can not stake if already staked. + // Can not register if already registered. + if offset.Cmp(big.NewInt(0)) >= 0 { + return nil, errExecutionReverted + } + + nodeKeyAddr, err := publicKeyToNodeKeyAddress(publicKey) + if err != nil { + return nil, errExecutionReverted + } + + offset = g.state.NodesOffsetByNodeKeyAddress(nodeKeyAddr) + + // Can not register if node key is duplicate. if offset.Cmp(big.NewInt(0)) >= 0 { return nil, errExecutionReverted } diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index 55876f9b2..5a9250ee5 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -344,6 +344,13 @@ func (g *OracleContractsTestSuite) TestStakingMechanism() { _, err = g.call(GovernanceContractAddress, addr, input, amount) g.Require().Error(err) + // Duplicate public key should fail + _, addrDup := newPrefundAccount(g.stateDB) + input, err = GovernanceABI.ABI.Pack("register", pk, "Test1", "test1@dexon.org", "Taipei", "https://dexon.org") + g.Require().NoError(err) + _, err = g.call(GovernanceContractAddress, addrDup, input, amount) + g.Require().Error(err) + // Stake more to qualify. input, err = GovernanceABI.ABI.Pack("stake") g.Require().NoError(err) |