Use another address’s code while retaining the caller’s state context.
LET’S PICTURE IT
A borrowed instruction manual operates on your cabinet rather than the manual owner’s cabinet.
SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.The first sixteen-byte value occupies the low-order half of slot zero. Low-order bytes are shown on the right.The second uint128 fits in the remaining sixteen bytes. Both values now share slot zero.C needs a complete thirty-two-byte slot, so it begins at slot one. Two packed small values plus C use two slots.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Separate code and storage address
DELEGATECALL runs target code using the caller’s storage context. In a proxy design, application writes generally affect the proxy’s storage.
Preserve caller-related fields
The delegated frame preserves msg.sender and msg.value from the delegating context. This differs from an ordinary CALL to the implementation address.
Coordinate storage meaning
Implementation code interprets whatever bytes already occupy the caller’s slots. A layout mismatch can corrupt state even when the delegated code is otherwise valid.
Treat target choice as authority
Code selected for delegation can act on the caller’s state. Protect the target selection and upgrade path rather than considering the target a harmless read-only library by default.
Trace the idea
User → Proxy
Proxy → DELEGATECALL Implementation
code source: Implementation
storage context: Proxy
msg.sender in delegated code: User
Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.
QUICK CHECK · NO PRESSURE
Does delegated code normally write the implementation’s own storage?