-
Notifications
You must be signed in to change notification settings - Fork 151
Description
Hello! 👋
Our team here at Moonsong Labs has been working on adding support for zkSync on foundry & we have been cooperating with several of your repos to make sure all your tests are successful with our new implementation.
We are opening this issue today to inform you of required action to ensure this repository's contracts are compatible with zkSync in the future.
In summary, we've identified two issues that we will elaborate on below:
- Different Create2 addresses leading to test failures.
- Cheatcodes in the EraVM (where they are not normally enabled).
Important note: To replicate, be sure you are using the latest compiler version to ensure you take advantage of the compilation time speed-ups improvements (~16m).
forge test --zksync If you want to further improve compilation times, you may also use:
forge test --zksync --force-evmla trueIn this case, compilation times should be even shorter (~4m) but there’s an additional blocker due to the EraVM contract size limit. Many contracts result in being too big, leading to a bytecode size limit. These bytecode size limitations should be addressed first to replicate these issues if you follow this path. If you decide to follow this path, please review 2. Cheatcodes in non-inlineable libraries below to take into account limitations.
1. Create2 Test Failures
The following tests make use of ConfigEngineDeployer.sol and fail in zkSync mode as the etched bytecode is not a multiple of 32.
tests/AaveV3BatchDeployment.t.sol:AaveV3BatchDeployment
tests/core/ATokenEdgeCases.t.sol:ATokenEdgeCasesTests
tests/core/ATokenEvents.t.sol:ATokenEventsTests
tests/core/ATokenModifiers.t.sol:ATokenModifiersTests
tests/core/ATokenPermit.t.sol:ATokenPermitTests
tests/core/ATokenRepay.t.sol:ATokenRepayTests
tests/core/ATokenRescueTokens.sol:ATokenRescueTokensTests
tests/core/ATokenTransfers.t.sol:ATokenTransferTests
tests/core/AaveOracle.t.sol:AaveOracleTest
tests/core/AddressesProviderRegistry.t.sol:PoolAddressesProviderRegistryTest
tests/core/BridgeLogic.t.sol:BridgeLogicTests
tests/core/L2Pool.t.sol:L2PoolTests
tests/core/Pool.Borrow.t.sol:PoolBorrowTests
tests/core/Pool.FlashLoans.t.sol:PoolFlashLoansTests
tests/core/Pool.Liquidations.t.sol:PoolLiquidationTests
tests/core/Pool.Repay.t.sol:PoolRepayTests
tests/core/Pool.Supply.t.sol:PoolSupplyTests
tests/core/Pool.Withdraw.t.sol:PoolWithdrawTests
tests/core/Pool.t.sol:PoolTests
tests/core/PoolAddressesProvider.t.sol:PoolAddressesProviderTests
tests/core/PoolConfigurator.ACLModifiers.t.sol:PoolConfiguratorACLModifiersTest
tests/core/PoolConfigurator.borrowCaps.t.sol:PoolConfiguratorBorrowCapTests
tests/core/PoolConfigurator.eMode.sol:PoolConfiguratorEModeConfigTests
tests/core/PoolConfigurator.initReserves.t.sol:PoolConfiguratorInitReservesTest
tests/core/PoolConfigurator.liquidationFee.t.sol:PoolConfiguratorLiquidationFeeTests
tests/core/PoolConfigurator.pendingLTV.t.sol:PoolConfiguratorPendingLtvTests
tests/core/PoolConfigurator.reserveRiskConfig.t.sol:PoolConfiguratorReserveRiskConfigs
tests/core/PoolConfigurator.supplyCaps.t.sol:PoolConfiguratorSupplyCapTests
tests/core/PoolConfigurator.upgradeabilty.t.sol:PoolConfiguratorUpgradeabilityTests
tests/core/PoolLogic.initReserves.edge.t.sol:PoolLogicInitReservesTests
tests/core/PriceOracleSentinel.t.sol:PriceOracleSentinelTest
tests/core/RateStrategy.t.sol:RateStrategyTests
tests/core/RatesOverflow.t.sol:RatesOverflowCheckTests
tests/core/ScaledBalanceTokenBase.t.sol:ScaledBalanceTokenBaseEdgeTests
tests/core/StableDebtToken.t.sol:StableDebtTokenEventsTests
tests/core/VariableDebtToken.t.sol:VariableDebtTokenEventsTests
tests/core/ZeroInteresRateStrategy.t.sol:ZeroReserveInterestRateStrategyTests
tests/periphery/EmissionsManager.t.sol:EmissionManagerTest
tests/periphery/ParaswapAdapters.t.sol:ParaswapAdaptersTest
tests/periphery/RewardsController.t.sol:RewardsControllerTest
tests/periphery/StakedTokenTransferStrategy.t.sol:StakedTokenTransferStrategyTest
tests/periphery/WrappedTokenGateway.t.sol:WrappedTokenGatewayTestsThe bytecode length panics are fixed with padding the bytecode here with extra 0s:
7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3000000000000000000000000000000000000000000000000000000
This however still fails as the create2 addresses do not match between zkSync and EVM.
Ran 1 test for tests/core/ATokenEvents.t.sol:ATokenEventsTests/test_atoken_burnEvents_withdrawAmountLessThanInterests
[FAIL. Reason: setup failed: revert: failure at create2 address derivation] setUp() (gas: 0)
2. Cheatcodes in non-inlineable libraries
The library SlotParser which is used in aave-v3-origin is using the vm.load cheatcode.
library SlotParser {
Vm private constant vm = Vm(address(uint160(uint256(keccak256('hevm cheat code')))));
function loadAddressFromSlot(address target, bytes32 slot) external view returns (address) {
return address(uint160(uint256(vm.load(target, slot))));
}
}
This piece of code would run inside the EraVM, where cheatcodes are not enabled. Any contract calls inside a test will fall under the same problem.
A possible workaround would be to refactor the library and move the use of the cheatcode to a helper function to use in the test. In that case the code will be executed in EVM where the cheatcodes will be enabled. For a further detailed explanation you can check this comment.
These steps mark the final adjustments needed to ensure compatibility with zkSync for aave-v3-origin. If you encounter any further issues or have additional questions, please do not hesitate to reach out!