SolidityDev (@SolidityDev99) header
SolidityDev (@SolidityDev99) profile picture

Dev @threesigmaxyz https://nitter.gq/t.co/cyD1bbfhzI

Joined February 2023
A great example of such a helper contract which can be inherited by the implementation is: github.com/ethereum-optimism… 10/10
2
40
In terms of implementation, for this system to work the proxy should be deployed with the extra code (which adds its immutable variables to the calldata) and the implementation should inherit some helper functions to allow the it to access the variables in calldata. 9/10
1
2
67
This is evident in the code of the proxy, which now has a couple extra opcodes (github.com/Saw-mon-and-Natal…), to copy the end of its bytecode to the memory used for the delegate call. 8/10
1
1
17
To access these variables the implementation contract can just read them from calldata, which is much cheaper then reading them from storage. 7/10
1
1
12
This proxy contract then has a modification in its fallback function, which attaches these immutable variables to every call forwarded through the proxy (i.e. the delegate call to the implementation). 6/10
1
1
13
The clever solution for this problem is called a clone with immutable vars, and it works by defining these variables upon the proxy deployment, and storing them at the end of the proxy contract's bytecode. 5/10
1
1
12
At first glance this might seem like the only option, as these variables cannot be stored in the implementation contract, since they are supposed to change from proxy to proxy. 4/10
1
1
12
Even though this solution works fine, it can be very inefficient as those variables, which are sometimes immutable through the use of the contract, will inevitably be stored in storage. 3/10
1
1
10
Let's say you want to have multiple proxies (with different storage) pointing to the same implementation. The typical and easiest way to do so is to initialize these variables in storage by calling the initialize() function of the implementation through the proxy contract. 2/10
1
1
13
This week, I had the opportunity to dig around Optimism's Fault Proof Alpha codebase, trying to catch something for their bounty. A few hours in, I stumbled upon a new concept for me called ClonesWith ImmutableArgs which took me a few hours to fully grasp. 1/10
1
2
115
Source: Contract Metadata — Solidity 0.8.17 documentation docs.soliditylang.org/en/v0.…
72
Automatic Interface Generation and NatSpec - By retrieving the metadata file, anyone can access the ABI and NatSpec user documentation, which can be used to automatically generate a user interface for the contract with human-readable function descriptors. 8/8
1
123
Source code authentication - By comparing the creation transaction (or CREATE opcode data) with the source code obtained through the metadafile (compiled using the correct compiler settings). 7/8
1
14
With the metadata file, obtained on IPFS or Swarm using the metadata hash, anyone can perform: 5/8
1
28
The current version of the Solidity compiler adds, by default, at the end of the bytecode, a CBOR-encoded mapping "{"ipfs": , "solc": }" like the following: "0xa2 0x64 'i' 'p' 'f' 's' 0x58 0x22 <34 bytes IPFS hash> 0x64 's' 'o' 'l' 'c' 0x43 <3 byte version encoding> 0x00 0x33"5/8
1
29
By default, the compiler appends the IPFS hash of the metadata file to the end of the bytecode of each contract, so that anyone can retrieve the file in an authenticated way without having to resort to a centralized data provider. 4/8
1
19
For this file to be publicly available, the developer needs to publish it to IPFS (or Swarm). Since the metadata contains references to the source code, it is also required to upload all source files in addition to the metadata file. 3/8
1
11
Using the 'solc' compiler, this file can be generated with the 'solc --metadata' command. 2/8
1
11
In order to safely interact with contracts and verify their source code, the Solidity compiler automatically generates the contract metadata: a file containing information about the compiler version, the sources used, the ABI and NatSpec documentation. 1/8
1
1
134