daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 59 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. contract Registry {
  2.     address[] versions;
  3.     uint currentVersion;
  4.     mapping(address => bool) isUpdated;
  5.    
  6.     function addBalance(address _addr, uint256 _val) {
  7.         bytes4 sig = bytes4(keccak256("addBalance(address,uint256)"));
  8.         if(!isUpdated[_addr]) {
  9.             bytes4 sigGet = bytes4(keccak256("getBalance(address)"));
  10.             address prevVersion = versions[currVersion-1];
  11.            
  12.             // use assembly to call getBalance in previous contract so we can update
  13.             // value in current contract correctly
  14.             assembly {            
  15.                 let x := mload(0x40) // get empty storage location
  16.                 mstore ( x, sigGet ) // 4 bytes - place signature in empty storage
  17.                 mstore (add(x, 0x04), _addr) // 20 bytes - place first argument next to 4-bit signature
  18.            
  19.                 let ret := call (gas,
  20.                     prevVersion,
  21.                     0, // no wei value passed to function
  22.                     x, // input
  23.                     0x18, // input size = 20 + 4 bytes
  24.                     x, // output stored at input location, save space
  25.                     0x20 // output size = 32 bytes
  26.                 )
  27.                
  28.                 let ans := mload(x)
  29.                 mstore(0x40, add(x,0x20)) // update free memory pointer
  30.             }
  31.            
  32.             uint _val += ans;
  33.         }
  34.        
  35.         versions[currVersion].call(sig, _addr, _val);
  36. }
  37.  
  38. contract oldContract {
  39.     mapping (address => uint256) public balances;
  40.  
  41.     function addBalance(address _addr, uint256 _val) {
  42.         balances[_addr] += _val;
  43.     }
  44.    
  45.     function getBalance(address _addr) returns (uint) {
  46.         return balances[_addr];
  47.     }
  48. }
  49.  
  50. contract newContract {
  51.     function addBalance(address _addr, uint256 _val){
  52.       // do stuff
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top