Skip to content

Instantly share code, notes, and snippets.

@Masa331
Created September 12, 2018 13:55
Show Gist options
  • Save Masa331/b1437f979d7e3a909b82e95d8967ec42 to your computer and use it in GitHub Desktop.
Save Masa331/b1437f979d7e3a909b82e95d8967ec42 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.24;
contract Fund {
address public owner;
address public exec;
constructor() public {
owner = msg.sender;
}
function setProxy(address newExec) public onlyOwner {
exec = newExec;
}
function proxy(string funcName, int numArg1, int numArg2, string stringArg1, string stringArg2) public onlyOwner {
bool result = exec.delegatecall(bytes4(keccak256(abi.encodePacked(funcName))), numArg1, numArg2, stringArg1, stringArg2);
if (!result) {
revert("Something went wrong during the exec call.");
}
}
modifier onlyOwner() {
require(msg.sender == owner, "This can be only called by contract owner.");
_;
}
}
pragma solidity ^0.4.24;
contract CommonLib2 {
string public result;
function word() public {
result = "hi";
}
}
contract CommonLib3 {
string public result;
function word() public {
result = "bye";
}
}
contract Fund {
string public result;
address public lib;
function setLib(address newAddr) public {
lib = newAddr;
}
function word() public {
bool success = lib.delegatecall(bytes4(keccak256("word()")));
if(!success) {
revert('FOOOOOOOOOOOOOOOOOOK');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment