diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-20 21:27:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 21:27:26 +0800 |
commit | a13464c2482971712350fe41a58ea8b30ec0c361 (patch) | |
tree | 6f0f0764d7359ba494485381dd319c7174f8926c | |
parent | d94c48b4d6c035afab825c36c7dd3551070d450f (diff) | |
download | dexon-a13464c2482971712350fe41a58ea8b30ec0c361.tar.gz dexon-a13464c2482971712350fe41a58ea8b30ec0c361.tar.zst dexon-a13464c2482971712350fe41a58ea8b30ec0c361.zip |
core: vm: deny duplicate public key from registering (#289)
-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) |