Skip to content
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

variables reevaluate block.timestamp when called #2167

Closed
2 tasks done
FredCoen opened this issue Jun 30, 2022 · 3 comments
Closed
2 tasks done

variables reevaluate block.timestamp when called #2167

FredCoen opened this issue Jun 30, 2022 · 3 comments
Labels
T-bug Type: bug

Comments

@FredCoen
Copy link

FredCoen commented Jun 30, 2022

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (49f35c7 2022-06-30T00:06:55.326479Z)

What command(s) is the bug in?

No response

Operating System

macOS (Apple Silicon)

Describe the bug


uint256 a = block.timestamp;
console2.log(a);
vm.warp(a+1);
console2.log(a);

This snippet prints 1 and 2 to the console. Seems block.timestamp gets reevaluated instead of using the stored value for a from the stack? Is this expected behaviour?

@FredCoen FredCoen added the T-bug Type: bug label Jun 30, 2022
@FredCoen FredCoen changed the title variables reevaluate block.timestamp expression when called variables reevaluate block.timestamp when called Jun 30, 2022
@onbjerg
Copy link
Member

onbjerg commented Jun 30, 2022

It's a Solidity optimization we can't get around. The compiler assumes block.timestamp evaluates to a constant so instead of pushing the value on the stack it just replaces all occurrences of a with a call to the TIMESTAMP opcode.

@onbjerg onbjerg closed this as completed Jun 30, 2022
@FredCoen
Copy link
Author

i see thanks @onbjerg is that the case even without the optimization pipeline?

@onbjerg
Copy link
Member

onbjerg commented Jun 30, 2022

I don't think so, but I'm not sure - this was reported once before in this issue: #1373 There is some additional context in there, but no clear solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants