Skip to content

Commit

Permalink
Merge pull request #9 from binance-chain/issue8
Browse files Browse the repository at this point in the history
[R4R]fix gov hub do not well handle when the target account is not contract
  • Loading branch information
unclezoro committed May 27, 2020
2 parents ad7c557 + 12a4c16 commit 3f966fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions contracts/GovHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ contract GovHub is System{
if (target == address(this)){
updateParam(key, value);
}else{
if (!isContract(target)){
emit failReasonWithStr("the target is not a contract");
return;
}
try IParamSubscriber(target).updateParam(key, value){
}catch Error(string memory reason) {
emit failReasonWithStr(reason);
Expand Down Expand Up @@ -110,4 +114,10 @@ contract GovHub is System{
emit failReasonWithStr("unknown param");
}
}

function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}
10 changes: 10 additions & 0 deletions contracts/GovHub.template
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ contract GovHub is System{
if (target == address(this)){
updateParam(key, value);
}else{
if (!isContract(target)){
emit failReasonWithStr("the target is not a contract");
return;
}
try IParamSubscriber(target).updateParam(key, value){
}catch Error(string memory reason) {
emit failReasonWithStr(reason);
Expand Down Expand Up @@ -111,4 +115,10 @@ contract GovHub is System{
emit failReasonWithStr("unknown param");
}
}

function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}
Loading

0 comments on commit 3f966fb

Please sign in to comment.