aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-16 12:12:06 +0800
committerGitHub <noreply@github.com>2019-04-16 12:12:06 +0800
commit35be27df35e31ba95a8540b4e1173e29aee4e61a (patch)
treeac35e3c9f7736611e3544697aeba7ed20d59e733
parent0845e84c9aea684da7d03c3063ebb19651c84caa (diff)
downloadgo-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar.gz
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar.bz2
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar.lz
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar.xz
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.tar.zst
go-tangerine-35be27df35e31ba95a8540b4e1173e29aee4e61a.zip
core: vm: prevent setting owner to blackhole (#366)
* core: vm: prevent setting owner to blackhole * core: vm: same for transferNodeOwner
-rw-r--r--core/vm/oracle_contracts.go6
-rw-r--r--core/vm/oracle_contracts_test.go14
2 files changed, 19 insertions, 1 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index b36a05d15..c82fed3cf 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -2607,11 +2607,17 @@ func (g *GovernanceContract) transferOwnership(newOwner common.Address) ([]byte,
if g.contract.Caller() != g.state.Owner() {
return nil, errExecutionReverted
}
+ if newOwner == (common.Address{}) {
+ return nil, errExecutionReverted
+ }
g.state.SetOwner(newOwner)
return nil, nil
}
func (g *GovernanceContract) transferNodeOwnership(newOwner common.Address) ([]byte, error) {
+ if newOwner == (common.Address{}) {
+ return nil, errExecutionReverted
+ }
caller := g.contract.Caller()
offset := g.state.NodesOffsetByAddress(caller)
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index 4fb05a34e..bdd407abd 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -254,9 +254,15 @@ func (g *OracleContractsTestSuite) call(
}
func (g *OracleContractsTestSuite) TestTransferOwnership() {
+ input, err := GovernanceABI.ABI.Pack("transferOwnership", common.Address{})
+ g.Require().NoError(err)
+ // Call with owner but invalid new owner.
+ _, err = g.call(GovernanceContractAddress, g.config.Owner, input, big.NewInt(0))
+ g.Require().NotNil(err)
+
_, addr := newPrefundAccount(g.stateDB)
- input, err := GovernanceABI.ABI.Pack("transferOwnership", addr)
+ input, err = GovernanceABI.ABI.Pack("transferOwnership", addr)
g.Require().NoError(err)
// Call with non-owner.
@@ -282,6 +288,12 @@ func (g *OracleContractsTestSuite) TestTransferNodeOwnership() {
offset := g.s.NodesOffsetByAddress(addr)
+ // Call with not valid new owner.
+ input, err = GovernanceABI.ABI.Pack("transferNodeOwnership", common.Address{})
+ g.Require().NoError(err)
+ _, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
+ g.Require().NotNil(err)
+
_, newAddr := newPrefundAccount(g.stateDB)
newNodeKeyAddr := crypto.PubkeyToAddress(privKey.PublicKey)