diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-20 21:27:26 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-13 18:11:44 +0800 |
commit | ba1eb31880ea5fae9a8e99b21ac165360e0ea30e (patch) | |
tree | 2eab4ae92f1d206e5a2744a6aa716982c869bdc6 | |
parent | da2926ef1626550865400d033e3219fe0a3781e4 (diff) | |
download | go-tangerine-ba1eb31880ea5fae9a8e99b21ac165360e0ea30e.tar.gz go-tangerine-ba1eb31880ea5fae9a8e99b21ac165360e0ea30e.tar.zst go-tangerine-ba1eb31880ea5fae9a8e99b21ac165360e0ea30e.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 e6fe81aa4..c94d58b1f 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1593,7 +1593,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) |