I hereby claim:
- I am noot on github.
- I am leth (https://keybase.io/leth) on keybase.
- I have a public key whose fingerprint is 4301 553B 7AA4 7E3A 3841 1BE0 5C74 C182 02E3 3376
To claim this, I am signing this object:
bool isUpgraded; | |
address newContract; | |
mapping (address => uint256) balances; | |
function setBalance(address _addr, uint256 _val) { | |
if(isUpgraded){ | |
// function signature | |
bytes4 sig = bytes4(keccak256("setBalance(address,uint256)")); //make sure the hash doesn't have spaces | |
newContract.call(sig, _addr, _val); // call setBalance in new contract, passing in signature and parameters | |
} |
contract OldContract { | |
// _sig = bytes4(keccak256("callMe()")); | |
function upgradeMe(bytes4 _sig) { | |
newContract.call(_sig); | |
} | |
} | |
contract NewContract { | |
function callMe() { | |
... |
contract oldContract { | |
bool isUpgraded; | |
address newContract; | |
mapping (address => uint256) balances; | |
function setBalance(address _addr, uint256 _val) { | |
if(isUpgraded){ | |
// function signature | |
bytes4 sig = bytes4(keccak256("setBalance(address,uint256)")); //make sure the hash doesn't have spaces | |
// delegate call will allow the called function to make changes on the values inside this contract |
pragma solidity ^0.4.19; | |
contract Transfers { | |
mapping(address => uint) balance; | |
function deposit() public payable { | |
balance[msg.sender] += msg.value; | |
} | |
function withdraw(address _addr, uint _value) public { |
contract OldContract { | |
// _sig = bytes4(keccak256("sum(uint,uint)")); | |
function upgradeMe(bytes4 _sig, address _newContract, uint _a, uint _b) returns (uint ans) { | |
assembly { | |
// free memory pointer : 0x40 | |
let x := mload(0x40) // get empty storage location | |
mstore ( x, sig ) // 4 bytes - place signature in empty storage | |
mstore (add(x, 0x04), _a) // 32 bytes - place first argument next to 4-bit signature |
interface oldContract { | |
function setBalance(address _addr, uint256 _val); | |
} | |
interface newContract { | |
function setBalance(address _addr, uint256 _val); | |
} | |
contract oldContract { | |
// same code as before |
contract Registry { | |
address[] versions; | |
uint currentVersion; | |
mapping(address => bool) isUpdated; | |
function addBalance(address _addr, uint256 _val) { | |
bytes4 sig = bytes4(keccak256("addBalance(address,uint256)")); | |
if(!isUpdated[_addr]) { | |
bytes4 sigGet = bytes4(keccak256("getBalance(address)")); | |
address prevVersion = versions[currVersion-1]; |
pragma solidity ^0.4.0; | |
contract Asm { | |
function bitwise(uint32 a, uint32 b) returns (bytes4) { | |
assembly { | |
let res := eq(a,b) | |
mstore(0x0, res) | |
return(0x0, 32) | |
} | |
} | |
var secrets = require("./secrets.json"); | |
var HDWalletProvider = require("truffle-hdwallet-provider"); | |
var Web3 = require('web3'); | |
var web3 = new Web3(Web3.givenProvider || "ws://localhost:8545"); | |
module.exports = { | |
// See <http://truffleframework.com/docs/advanced/configuration> | |
// to customize your Truffle configuration! | |
networks: { | |
development: { |
I hereby claim:
To claim this, I am signing this object: