Added command line tests for keccak optimization with low runs

The value of keccak256(0, 32) should not be replaced by the big constant
This commit is contained in:
hrkrshnn 2021-03-12 18:05:05 +01:00
parent 221292c278
commit b636ef881e
10 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1 @@
--ir-optimized --optimize --optimize-runs 50000

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-v3
pragma solidity >= 0.0.0;
contract C {
constructor() {
assembly {
mstore(0, 100)
// because this is part of deploy code, the keccak will not be evaluated
sstore(0, keccak256(0, 32))
}
}
fallback() external {
assembly {
mstore(0, 100)
// The keccak here would be evaluated
sstore(0, keccak256(0, 32))
}
}
}

View File

@ -0,0 +1,32 @@
Optimized IR:
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
object "C_12" {
code {
{
mstore(64, 128)
if callvalue() { revert(0, 0) }
mstore(0, 100)
sstore(0, keccak256(0, 32))
let _1 := datasize("C_12_deployed")
codecopy(0, dataoffset("C_12_deployed"), _1)
return(0, _1)
}
}
object "C_12_deployed" {
code {
{
mstore(64, 128)
if callvalue() { revert(0, 0) }
mstore(0, 100)
sstore(0, 17385872270140913825666367956517731270094621555228275961425792378517567244498)
stop()
}
}
}
}

View File

@ -0,0 +1 @@
--ir-optimized --optimize --optimize-runs 1

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-v3
pragma solidity >= 0.0.0;
contract C {
fallback() external {
assembly {
mstore(0, 100)
// because of the low runs value, the constant will not be optimized
sstore(0, keccak256(0, 32))
}
}
}

View File

@ -0,0 +1,30 @@
Optimized IR:
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
object "C_7" {
code {
{
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_7_deployed")
codecopy(0, dataoffset("C_7_deployed"), _1)
return(0, _1)
}
}
object "C_7_deployed" {
code {
{
mstore(64, 128)
if callvalue() { revert(0, 0) }
mstore(0, 100)
sstore(0, keccak256(0, 32))
stop()
}
}
}
}