A minimal beacon proxy

Hey guys, since a beacon proxy can be generated multiple times via a factory in some cases, a minimal version keeping the absolutely necessary components could be desired. A possible version is given below. Please leave comments or concerns if there is any.

abstract contract MinimalBeaconProxy is proxy {

    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    constructor(address beacon) {
        assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1));
        _setBeacon(beacon);
    }

    function _implementation() internal view virtual override returns (address) {
        return IBeacon(_getBeacon()).implementation();
    }

    function _getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
    }

    function _setBeacon(address newBeacon) internal {
        require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }
}

@frangio Hey Fran, can you please take a look at this thread? The motivation of designing this is mostly for gas savings, hence only the absolutely necessary functions are kept to make the proxy beacon pattern work. Would there be any security issues? Thanks.

Hey @maxareo! It looks good to me at first sight, and it makes sense to keep it small if you know you won't want to change beacon in the future (though you can always use an UUPS-like approach to do that). Still, definitely make sure you test this thoroughly (and audit if possible!).

1 Like

This doesn't look much smaller than our official BeaconProxy. Did you measure the bytecode size?

If you're looking to optimize runtime cost you should look into removing the beacon address from storage and storing it in an immutable variable.

Note that our Upgrades Plugin currently have no way of deploying custom proxies.

1 Like

I think what I truly meant was this one captures the core and essential functionalities of making a beacon proxy work. The amount of reading and thinking is minimized.