mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
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:
parent
221292c278
commit
b636ef881e
1
test/cmdlineTests/keccak_optimization_deploy_code/args
Normal file
1
test/cmdlineTests/keccak_optimization_deploy_code/args
Normal file
@ -0,0 +1 @@
|
||||
--ir-optimized --optimize --optimize-runs 50000
|
1
test/cmdlineTests/keccak_optimization_deploy_code/err
Normal file
1
test/cmdlineTests/keccak_optimization_deploy_code/err
Normal file
@ -0,0 +1 @@
|
||||
|
1
test/cmdlineTests/keccak_optimization_deploy_code/exit
Normal file
1
test/cmdlineTests/keccak_optimization_deploy_code/exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
21
test/cmdlineTests/keccak_optimization_deploy_code/input.sol
Normal file
21
test/cmdlineTests/keccak_optimization_deploy_code/input.sol
Normal 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))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
32
test/cmdlineTests/keccak_optimization_deploy_code/output
Normal file
32
test/cmdlineTests/keccak_optimization_deploy_code/output
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
test/cmdlineTests/keccak_optimization_low_runs/args
Normal file
1
test/cmdlineTests/keccak_optimization_low_runs/args
Normal file
@ -0,0 +1 @@
|
||||
--ir-optimized --optimize --optimize-runs 1
|
1
test/cmdlineTests/keccak_optimization_low_runs/err
Normal file
1
test/cmdlineTests/keccak_optimization_low_runs/err
Normal file
@ -0,0 +1 @@
|
||||
|
1
test/cmdlineTests/keccak_optimization_low_runs/exit
Normal file
1
test/cmdlineTests/keccak_optimization_low_runs/exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
12
test/cmdlineTests/keccak_optimization_low_runs/input.sol
Normal file
12
test/cmdlineTests/keccak_optimization_low_runs/input.sol
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
30
test/cmdlineTests/keccak_optimization_low_runs/output
Normal file
30
test/cmdlineTests/keccak_optimization_low_runs/output
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user