Incorrect handling of revert when `viaIR = true`
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Calling a function which takes no input arguments, under a scenario in which the function should revert with a message:
- When `viaIR = false`, the function reverts with the expected message
- When `viaIR = true`, the function reverts with a different message
## Environment
- Compiler version: 0.8.19
- Framework/IDE: hardhat-truffle5
- Operating system: MacOS
I have tested this problem separately with hardhat versions 2.12.7 and 2.14.0.
The reproduction below uses the 'truffle5' plugin, but it also works without it.
## Steps to Reproduce
```solidity
pragma solidity 0.8.19;
contract MyContract {
bool private alreadyCalled;
function initialize() external {
require(!alreadyCalled, "already called");
alreadyCalled = true;
}
}
```
```javascript
const MyContract = artifacts.require("MyContract");
contract("MyContract", () => {
it("Test", async () => {
const myContract = await MyContract.new();
await myContract.initialize();
try {
await myContract.initialize();
} catch (error) {
console.log(error.message);
}
});
});
```
Outcome:
```
+---------+-------+-----------------------------------------------------------------------------------------+
| HardHat | viaIR | Printout |
+---------+-------+-----------------------------------------------------------------------------------------+
| 2.12.7 | false | VM Exception while processing transaction: reverted with reason string 'already called' |
+---------+-------+-----------------------------------------------------------------------------------------+
| 2.12.7 | true | Transaction reverted: function was called with incorrect parameters |
+---------+-------+-----------------------------------------------------------------------------------------+
| 2.14.0 | false | VM Exception while processing transaction: reverted with reason string 'already called' |
+---------+-------+-----------------------------------------------------------------------------------------+
| 2.14.0 | true | Transaction reverted and Hardhat couldn't infer the reason |
+---------+-------+-----------------------------------------------------------------------------------------+
```
Strangely enough, adding a `console.log` inside the contract function solves the problem.
This is possibly a HardHat issue, so I shall post it there too.
Please find the project configuration below.
File package.json:
```json
{
"scripts": {
"build": "hardhat compile",
"test": "hardhat test --bail"
},
"devDependencies": {
"@nomiclabs/hardhat-truffle5": "2.0.7",
"@nomiclabs/hardhat-web3": "2.0.0",
"hardhat": "2.12.7"
}
}
```
File hardhat.config.js:
```javascript
require("@nomiclabs/hardhat-truffle5");
module.exports = {
solidity: {
version: "0.8.19",
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200
}
}
},
paths: {
sources: "./project/contracts",
tests: "./project/tests",
cache: "./project/cache",
artifacts: "./project/artifacts"
}
};
```
Thanks :)
Contributor guide
Research direction
Start by reproducing the contract in project/contracts and the test in project/tests with the settings in hardhat.config.js, comparing viaIR true and false. Check package.json for the stated Hardhat versions and confirm that the second initialize call reports the expected "already called" revert message in both modes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, solidity
- Domain
- blockchain, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100