A 180 byte proxy that checks its implementation still has code, delegates the call, and returns a fixed size window of the result.
Historical Significance
The fixed return size dates this contract to before RETURNDATASIZE was usable, when a proxy had to guess how much return data to reserve. Guessing high wasted memory gas on every call; guessing low truncated results. Reserving a flat 4096 bytes was the pragmatic answer, and the extcodesize guard addresses the other hazard of the era, that a delegatecall to nothing looks exactly like success.
Key Facts
Description
An internal helper receives the hardcoded implementation address and the calldata. It uses a Yul switch on extcodesize to reject a target with no code, which matters because a delegatecall to an empty address succeeds silently and would make every call appear to work.
The delegatecall forwards all gas minus ten thousand and asks for a fixed 4096 byte return window rather than using returndatasize. A second switch on the result reverts through the invalid opcode on failure, and on success returns that whole fixed window.
Source Verified
Byzantium Era
First Metropolis hard fork. Added zk-SNARK precompiles, REVERT opcode, and staticcall.
Bytecode Overview
Verified Source Available
This contract has verified source code.
View Verification ProofShow source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
pragma solidity ^0.4.18;
contract Proxy {
function () public payable {
forward(0xAF8A60B8d53F0563abAdC3b33D0bf28517a6B696, msg.data);
}
function forward(address _target, bytes _data) internal {
assembly {
switch extcodesize(_target)
case 0 { revert(0, 0) }
let ret := 0x1000
let result := delegatecall(sub(gas, 10000), _target, add(_data, 0x20), mload(_data), 0, ret)
switch result
case 0 { invalid() }
return(0, ret)
}
}
}