2

I am learning to write a proxy contract in Solidity.

What do we mean by collision when writing proxy contract for a smart contract?

I have some other questions as well , pls refer to comments inside this code snippet.

contract Proxy {
      // slots to prevent collision ( idk what it actually means ) 
        bytes32 public constant IMPLEMENTATION_SLOT = bytes32(          // slot for implementation contract ( this slot stores address of implementation contract ) 
            uint(keccak256("eip1967.proxy.implementation")) - 1 // can I write anything instead of eip1967.proxy.implementation here ? What exactly is the meaning of this line ?
        ); 
        
        bytes32 public constant ADMIN_SLOT = bytes32(                   // slot for admin contract ( this slot stores address of admin contract ) 
            uint(keccak256("eip1967.proxy.admin")) - 1 // can I write anything instead of eip1967.proxy.admin here ? What exactly is the meaning of this line ?
        ); 
        );
// rest of the code here 
}

library StorageSlot {

    struct AddressSlot {
        address value;
    } // why is the value stored inside AddressSlot struct and not just simply as normal variable address value ?

    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly {
            r.slot := slot
        } // what does this code inside assembly do ?
    }
}

1 Answer 1

1

In this case, the collision refers to memory collision.

For example: Your Proxy contract has the address of the Implementation/Logic contract. And that address is written inside Proxy contract's storage.

However, what happens if one of the functions in your Implementation/Logic contracts overwrites that memory slot? Suddenly your Proxy contract can't call the Implementation contract because he lost the address.

That is an example of memory collision.

I advise you to watch this tutorial that showcases the memory collision to understand it better: Link to video

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.