Closed SidestreamColdMelon closed 6 months ago
Current state of the flattening: running make verify
inside this PR (with nightly-2cb8757
build of the foundry) and comparing it to the code of the previously deployed spell would produce the following diff: https://www.diffchecker.com/mhQp4BXR/
Spotted differences:
pragma solidity
version is different
pragma solidity =0.8.16 >=0.5.12 >=0.8.16 <0.9.0;
is produced by the hevm flatten
pragma solidity 0.8.16;
is produced by the forge flatten
compiler_version
sent to etherscan for verification is actually loaded from the out/dapp.sol.json
(file produced during the compilation), and is currently set to v0.8.16+commit.07a7930e
// lib/dss-exec-lib/src/CollateralOpts.sol
)
forge flatten
, while commented in when hevm flatten
OriginalInterfaceName_1
(eg see ProxyLike
)
hevm flatten
, the order is:
lib/dss-exec-lib/src/CollateralOpts.sol
lib/dss-exec-lib/src/DssExecLib.sol
lib/dss-exec-lib/src/DssAction.sol
lib/dss-exec-lib/src/DssExec.sol
lib/dss-test/lib/dss-interfaces/src/ERC/GemAbstract.sol
lib/dss-test/lib/dss-interfaces/src/dss/VatAbstract.sol
src/DssSpell.sol
forge flatten
, the order is:
lib/dss-exec-lib/src/CollateralOpts.sol
lib/dss-exec-lib/src/DssExec.sol
lib/dss-test/lib/dss-interfaces/src/ERC/GemAbstract.sol
lib/dss-test/lib/dss-interfaces/src/dss/VatAbstract.sol
lib/dss-exec-lib/src/DssExecLib.sol
lib/dss-exec-lib/src/DssAction.sol
src/DssSpell.sol
Should not be a problem, but I wonder if it affects the order of the opcodes in the binary
It doesn't matter. Each contract or library bytecode is a separate "entity". What the verifier does is to check against all bytecodes generated by the compilation and match it against the contract under verification.
What the verifier does is to check against all bytecodes generated by the compilation
Do you refer to some known implementation of the verifier that does it this way?
To be honest, I don't know about the implementation details of any verifier tools, but I'm inferring based on how smart contracts are deployed on-chain.
Each contract/library is a separate entity in the state trie, with their own nonce, balance and bytecode.
I'm guessing that what any verifier tool does is:
The change in the order of declaration of the contracts could potentially just impact the order under each compiled bytecode is compared against the one on-chain, but not the final result.
I'm not fluent in Rust, but Blockscout's verifier – that does roughly what I'm trying to describe – can be found here:
Since goerli PR can't proceed (as goerli is not mining any blocks and was officially deprecated), we can try to use sepolia to validate flattening correctness.
While temporary changing hardcoded network ids in various scripts in order to deploy the spell to Sepolia, I've realised that we first need to deploy ExecLib in order for the deployment command to work, while ExecLib depends on the chainlog to be deployed, which blows up the scope of this PR and doesn't actually help others to review it.
To merge this sooner, my suggestion is to test code flattening functionality locally (i.e. flatten a spell in the PR vs master and compare flattened code or the compiled binaries).
Other than the order of the contracts being different after flattening, the only differences I could find in the latest spell were:
Neither of those seems like a blocker, so I'm gonna approve it.
Description
This PR implements minimal changes required to remove dependency on dapp.tools and replace it with foundry commands (ie
hevm
withforge
,seth
withcast
).In order to try out this PR, one have to install a foundry build containing the fix with rewritten implementation of the flattening logic, eg:
Or a later version that also includes this major fix.