argotorg / argotorg/solidity

Pattern PUSH0 SHR appears in optimized code

Open
#15,024 5 comments 0 reactions 1 assignee Claimed by @matheusaaguiar View on GitHub
bug :bug: medium effort medium impact
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

Optimizer does not optimize out ```PUSH0 SHR``` instructions ( x >> 0 is always x)

## Environment

- Compiler version: solc v0.8.23
- Target EVM version (as per compiler settings): default
- Framework/IDE (e.g. Truffle or Remix): none
- EVM execution environment / backend / blockchain client: none
- Operating system: Linux
- Compiled with command: ```solc/solc0.8.23 -o build/examples/push0shr.sol/ --overwrite --ast-compact-json --asm --bin-runtime --bin --optimize --optimize-runs 200000 --abi --combined-json=srcmap-runtime,generated-sources-runtime examples/push0shr.so```

## Steps to Reproduce

compile the following example with the above command:

```solidity
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

contract Push0Shr
{
uint256 rand_counter = 0;
function random() public returns(uint256)
{
rand_counter += 1;
return uint256(keccak256(abi.encodePacked(block.prevrandao, block.timestamp, rand_counter, msg.sender)));
}
}
```
The pattern appears to be generated by the source location s:l:f = (207, 97, 0)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.