foundry-yul
foundry-yul copied to clipboard
fix: some yul commands cause compile error (iszero, eq, etc)
forge test throw an error due to the some of yul functions such as iszero or eq, etc.
I will leave here an example code in order to reproduce the issue.
// yul contract
object "CompileTest" {
code {
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
return(0, datasize("Runtime"))
}
object "Runtime" {
code {
function lte(a, b) -> r {
r := iszero(gt(a, b))
}
function returnUint(v) {
mstore(0, v)
return(0, 0x20)
}
}
}
}
and test code
// CompileTest.t.sol
pragma solidity 0.8.15;
import "forge-std/Test.sol";
import "./lib/YulDeployer.sol";
interface CompileTest {}
contract CompileTestTest is Test {
YulDeployer yulDeployer = new YulDeployer();
CompileTest compileTestContract;
function setUp() public {
compileTestContract = CompileTest(yulDeployer.deployContract("CompileTest"));
}
function testExample() public {
// Don't do anything
}
}
the error:
stderr err="Error: Function "iszero" not found.
--> yul/CompileTest.yul:10:22:
|
10 | r := iszero(gt(a, b))
| ^^^^^^
Error: Variable count for assignment to "r" does not match number of values (1 vs. 0)
--> yul/CompileTest.yul:10:17:
|
10 | r := iszero(gt(a, b))
| ^^^^^^^^^^^^^^^^^^^^^
Error:
u{1b}[31mInvalid datau{1b}[0m
"
2023-02-25T06:33:11.819759Z ERROR forge::runner: setUp failed reason="EvmError: Revert" contract=0x7fa9385be102ac3eac297483dd6233d62b3e1496
Would be good to merge it , had the same issue
Would be good to merge it , had the same issue
In order to merge it, I need maintainer's approval, right?
@CodeForcer @flyq
--yul Switch to Yul mode, ignoring all options except --machine, --yul-dialect, --optimize and --yul-optimizations and assumes input is Yul. --strict-assembly Switch to strict assembly mode, ignoring all options except --machine, --yul-dialect, --optimize and --yul-optimizations and assumes input is strict assembly.is the error caused by
iszerois astrict assembly, notYul?
Yes I experienced the error I mentioned above with --yul. I fixes the error when I use --strict-assembly.
@flyq thanks for the approval. Do I have right to merge or someone else should merge it?