From ed345b0fdfec596774e7be1b99618326dedcb93c Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Tue, 16 Apr 2019 12:12:06 +0800 Subject: core: vm: prevent setting owner to blackhole (#366) * core: vm: prevent setting owner to blackhole * core: vm: same for transferNodeOwner --- core/vm/oracle_contracts.go | 6 ++++++ core/vm/oracle_contracts_test.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3