Bytecode Verification
Overview
Kontrol supports verifying contracts using only their bytecode through the vm.etch
cheatcode. This is particularly useful when:
You want to verify interactions with contracts that only have bytecode available on-chain
You need to verify contracts where the Solidity source code is not available
You want to simulate mainnet forking scenarios
Basic Setup
To verify a contract using its bytecode, you'll need to:
Get the contract's bytecode (either from on-chain or other sources)
Use
vm.etch
to deploy the bytecode at a specific addressCreate an interface for the contract
Write and run your verification tests
Here's a basic example:
Getting Bytecode
There are several ways to get contract bytecode from the blockchain:
From Etherscan:
Navigate to the contract's page
Click on "Contract" tab
Click "Code" to see the bytecode
Using Foundry's cast:
Using web3.js/ethers.js:
If the contract source code is available locally, you can obtain the bytecode by compiling it with the appropriate compiler such as solc
for Solidity or vyper
for Vyper.
Best Practices
Storage Handling:
Use
vm.setArbitraryStorage
to make the contract's storage symbolicThis allows verification across all possible storage states
Interface Definition:
Define complete interfaces for all functions you want to verify
Include all necessary function signatures and events
Address Management:
Use consistent addresses across tests
Consider using
vm.createSelectFork
for mainnet simulations
Additional Resources
Last updated
Was this helpful?