-
Notifications
You must be signed in to change notification settings - Fork 6.3k
EIP-7939 CLZ for Osaka #16122
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
Merged
Merged
EIP-7939 CLZ for Osaka #16122
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| contract C { | ||
| function f() public view returns (bytes32 ret) { | ||
| assembly { | ||
| ret := clz(0) | ||
| } | ||
| } | ||
|
|
||
| function g() public view returns (bytes32 ret) { | ||
| assembly { | ||
| ret := clz(1) | ||
| } | ||
| } | ||
|
|
||
| function h() public view returns (bytes32 ret) { | ||
| assembly { | ||
| ret := clz(0x4000000000000000000000000000000000000000000000000000000000000000) | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: >=osaka | ||
| // ---- | ||
| // f() -> 256 | ||
| // g() -> 255 | ||
| // h() -> 1 |
21 changes: 21 additions & 0 deletions
21
test/libsolidity/semanticTests/inlineAssembly/clz_pre_osaka.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| contract C { | ||
| function f() public pure returns (uint ret) { | ||
| assembly { | ||
| let clz := 1 | ||
| ret := clz | ||
| } | ||
| } | ||
| function g() public pure returns (uint ret) { | ||
| assembly { | ||
| function clz() -> r { | ||
| r := 1000 | ||
| } | ||
| ret := clz() | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: <osaka | ||
| // ---- | ||
| // f() -> 1 | ||
| // g() -> 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| contract C { | ||
| function f(uint256 x) public pure returns (bytes32 ret) { | ||
| assembly { | ||
| ret := clz(x) | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: >=osaka | ||
| // ---- |
12 changes: 12 additions & 0 deletions
12
test/libsolidity/syntaxTests/inlineAssembly/clz_pre_osaka.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| contract C { | ||
| function f(uint256 x) public pure returns (bytes32 ret) { | ||
| assembly { | ||
| ret := clz(x) | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: =prague | ||
| // ---- | ||
| // TypeError 4948: (113-116): The "clz" instruction is only available for Osaka-compatible VMs (you are currently compiling for "prague"). | ||
| // DeclarationError 8678: (106-119): Variable count for assignment to "ret" does not match number of values (1 vs. 0) |
14 changes: 14 additions & 0 deletions
14
test/libsolidity/syntaxTests/inlineAssembly/clz_reserved_osaka.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| contract C { | ||
| function f() public pure returns (uint ret) { | ||
| assembly { | ||
| function clz() -> r { | ||
| r := 1000 | ||
| } | ||
| ret := clz() | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: >=osaka | ||
| // ---- | ||
| // ParserError 5568: (103-106): Cannot use builtin function name "clz" as identifier name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| sstore(0, clz(0)) | ||
| sstore(1, clz(1)) | ||
| sstore(2, clz(0xff)) | ||
| } | ||
| // ==== | ||
| // EVMVersion: >=osaka | ||
| // ---- | ||
| // Trace: | ||
| // Memory dump: | ||
| // Storage dump: | ||
| // 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000100 | ||
| // 0000000000000000000000000000000000000000000000000000000000000001: 00000000000000000000000000000000000000000000000000000000000000ff | ||
| // 0000000000000000000000000000000000000000000000000000000000000002: 00000000000000000000000000000000000000000000000000000000000000f8 | ||
| // Transient storage dump: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| { | ||
| let clz := 1 | ||
| } | ||
|
|
||
| { | ||
| function clz() {} | ||
| clz() | ||
| } | ||
| } | ||
|
|
||
| // ==== | ||
| // EVMVersion: >=osaka | ||
| // ---- | ||
| // ParserError 5568: (20-23): Cannot use builtin function name "clz" as identifier name. | ||
| // ParserError 5568: (59-62): Cannot use builtin function name "clz" as identifier name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| { | ||
| let clz := 1 | ||
| } | ||
|
|
||
| { | ||
| function clz() {} | ||
| clz() | ||
| } | ||
| } | ||
|
|
||
| // ==== | ||
| // EVMVersion: <osaka | ||
| // ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLZhas the same gas cost asADD, which is in theTier::VeryLow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was updated. Also it is
5in geth. Plus in the EIP it mentions:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linked EIP still mentions a gas cost similar to
ADD, and as @Vectorized pointed out, it is indeed 3, i.e.Tier::VeryLow. Which is also the same used by evmone. Do you have the source for the change to 5, @Saw-mon-and-Natalie?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see that in the PR it was actually indeed changed to 5: https://github.com/ipsilon/evmone/pull/1264/files#diff-d47e4d7f522e531f3080bb99145762aef9857717b9e9218a0e90e09e58fa865eR176
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the execution spec that should be the source of truth for us here.
count_leading_zeros()usesGAS_LOW, so that's the right value.But note that it matters whether it's
LOWor independently defined as 5. If it was the latter and it had its own constant, we would have to introduce a distinct tier for it. Technically, a future repricing could change the values assigned to those tiers. The cost of CLZ should change in such a case only if it is explicitly defined as a part of such a tier.