Skip to content

Instantly share code, notes, and snippets.

Minimal Upgrade Beacon Proxy (runtime code)

  • Get the current implementation contract address from the upgrade beacon via STATICCALL
  • Then, put calldata in memory to supply as argument in DELEGATECALL to implementation
  • Finally, return or revert based on DELEGATECALL status, supplying return buffer in either case
  • 48 bytes long when using an upgrade beacon with a compact address (starts with 5 zero bytes)
0x59595959365960205959596e<upgrade_beacon_last_15_bytes>5afa1551368280375af43d3d93803e602e57fd5bf3

pc  op  name                      [stack] <memory> {return_buffer} *return* ~revert~
@0age
0age / HomeWork.sol
Created June 9, 2019 14:33
HomeWork V1 source (flattened)
pragma solidity 0.5.9; // optimization enabled, runs: 10000, evm: constantinople
/**
* @title HomeWork Interface (version 1) - EIP165 ID 0xe5399799
* @author 0age
* @notice Homework is a utility to find, share, and reuse "home" addresses for
* contracts. Anyone can work to find a new home address by searching for keys,
* a 32-byte value with the first 20 bytes equal to the finder's calling address
* (or derived by hashing an arbitrary 32-byte salt and the caller's address),
@0age
0age / MetamorphicDelegatorFactory.sol
Last active September 20, 2023 08:53
Deploy (and redeploy) contracts to known addresses
pragma solidity 0.5.8;
/**
* @title Metamorphic Delegator Factory
* @author 0age
* @notice This contract creates metamorphic contracts, or contracts that can be
* redeployed with new code to the same address. First, it deploys a contract
* with the initialization code of the contract you want to deploy stored in its
* RUNTIME code. Then, it deploys the contract, which retrieves the address of
@0age
0age / MetamorphicContractInitCode.txt
Last active May 24, 2023 10:24
Metamorphic Contract Initialization Code
* @title Metamorphic Contract
* @author 0age, derived from cloner contract by @mhswende
* @notice This contract will create a metamorphic contract, or an upgradeable
* contract that does not rely on a transparent proxy, when deployed using
* CREATE2. It expects the deployer to provide a getImplementation() function
* that will return an implementation address, which it will then clone and
* deploy. Unlike with upgradeable transparent proxies, the state of a
* metamorphic contract will be wiped clean with each upgrade. With great power
* comes great responsibility - implement appropriate controls and educate the
* users of your contract if it will be interacted with!
@0age
0age / rewardFunction.js
Created September 26, 2018 01:01
Calculate the reward for creating an upgradeable proxy contract with a given efficient address.
#!/usr/bin/env node
var Decimal = require('decimal.js') // $ yarn add decimal.js
// pulling out the big guns (maybe a tad excessive...)
Decimal.config(
{
precision: 500,
toExpNeg: -500
}
)

Keybase proof

I hereby claim:

  • I am 0age on github.
  • I am 0age (https://keybase.io/0age) on keybase.
  • I have a public key whose fingerprint is EC35 AB0B 6C4A D409 0FEF 81D5 50F4 5C3C 02E6 FD2F

To claim this, I am signing this object: