-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert reasons not detected in external calls with viaIR: true
and optimizer enabled
#2453
Comments
viaIR: true
and optimizer enabledviaIR: true
and optimizer enabled
Here's another case of this, though it's a bit different. This one fails only with the latest compiler built from I found it while debugging a revert with How to reproduceHere's a repro showing the problem both with No failure on 0.8.12mkdir test/ contracts/
cat <<EOF > hardhat.config.js
require("@nomiclabs/hardhat-waffle");
require('@nomiclabs/hardhat-truffle5');
module.exports = {
solidity: {
compilers: [{
version: "0.8.12",
settings: {
viaIR: true,
optimizer: { enabled: true },
},
}]
}
};
EOF
cat <<EOF > test/CountersTest.js
const { expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const CountersImpl = artifacts.require('CountersImpl');
it('expectRevert', async function () {
const counter = await CountersImpl.new();
await expectRevert(counter.decrement(), 'Counter: decrement overflow');
});
it('expect().to.be.revertedWith', async function () {
const counter = await CountersImpl.new();
await expect(counter.decrement()).to.be.revertedWith('Counter: decrement overflow');
});
EOF
cat <<EOF > contracts/CountersImpl.sol
contract CountersImpl {
function current() public {}
function increment() public {}
function decrement() public {
require(false, "Counter: decrement overflow");
}
}
EOF
npm install hardhat @nomiclabs/hardhat-waffle chai @openzeppelin/test-helpers @nomiclabs/hardhat-truffle5
npx hardhat test Output:
Without
|
Also, when testing on Rinkeby, the issue happens. It is find when testing with local node Envs:
result with
|
This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days. |
Still relevant. |
This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days. |
Still relevant. |
This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days. |
Still relevant. |
fyi, this happens to more and more tests. We now have an additional 58 failing tests in zeppelin with our latest development version. |
I am getting hit by this, I have a hardhat test on this branch that passes with |
This happened to me on the most recent hardhat version, |
i have a similar experience, failures that only appear with viaIR enabled |
Hi folks, we are working on some having basic support for this, but please keep in mind that we won't be able to have a really good support until this issue is fixed. The reason is that Hardhat relies on non-optimized code for a lot of its heuristics, and |
@fvictorio can you give us some insight into why heuristics are needed at all? The data returned by REVERT is deterministic |
@karmacoma-eth you are right that for revert reasons, things should just work. I was referring more to general support for viaIR compiled code. In this particular case, what's happening is that we still run some heuristics when an error has revert data, which is probably a mistake (at least if the revert data is an I think we'll have a (probably beta) release with basic support for viaIR next week. |
@fvictorio It's now possible to disable all Yul Optimizer steps and have only the stack-related optimizations enabled (see ethereum/solidity#12533 (comment)). Would that be good enough to keep heuristics working? |
If a contract compiled with optimization and
viaIR: true
calls an external function that reverts,to.be.revertedWith()
matcher does not detect the right revert reason.This does not happen:
viaIR: false
,I saw cases whereEDIT: this one was actually an unrelated problem caused by a bug in the compiler. Only the one below is relevant here.to.be.revertedWith()
thinks here was no reason given at all (see run 994880 in ethereum/solidity#12736):and ones where it's misdetected as something else (see repro below):
This might be caused by the same thing as #2115 but the effects are a bit different so I'm reporting as a separate issue.
How to reproduce
Run this in the shell:
Test output:
The text was updated successfully, but these errors were encountered: