aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-16 12:12:06 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:56 +0800
commited345b0fdfec596774e7be1b99618326dedcb93c (patch)
treef434fbf4c93ccfa3a7046d4d08665b077c7c9015
parent089d3f08d28cd797f73874363cc4865cf9e5e700 (diff)
downloadgo-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar.gz
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar.bz2
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar.lz
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar.xz
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.tar.zst
go-tangerine-ed345b0fdfec596774e7be1b99618326dedcb93c.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 aef1ab72b..55ea3f4dd 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -2605,11 +2605,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 bcb6eb01b..7c935913a 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -253,9 +253,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.
@@ -281,6 +287,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)