-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
feat[lang]: add blobhash()
builtin
#3962
Merged
Merged
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9f78bea
feat[lang]: add `blobhash(uint256)`
pcaversaccio 84739d2
format
pcaversaccio 227c466
remove CodeQL warning
pcaversaccio 0a148a9
black
pcaversaccio 836867f
fix `isort`
pcaversaccio c741612
fix gas for `BLOBHASH`
pcaversaccio 69a2362
fix typo
pcaversaccio ab08210
remove unnecessary test
pcaversaccio a64250a
lint
pcaversaccio 98d4088
add further assert in test
pcaversaccio ea40cde
not sure this will work...
pcaversaccio 9800b81
obviously skill issue
pcaversaccio 65f646b
I HATE YOU, flake8
pcaversaccio d9e665d
Merge branch 'master' into feat/blobhash
pcaversaccio 92d4aec
refactor
pcaversaccio 26d6fdb
chore[test]: modify `blobhash` test (#1)
tserg 03d041f
Merge branch 'master' into feat/blobhash
pcaversaccio de73a7a
fix merge conflict
pcaversaccio 0a3deb4
fix[test]: blob hash tests without eth_tester (#2)
DanielSchiavini 28b21f3
clean up the blobhash test
charles-cooper 8f38e6b
update assembly tests -- test round trip via opcodes_runtime
charles-cooper d71dd48
update blobhash test
charles-cooper 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 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 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 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 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 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,78 @@ | ||
import pytest | ||
|
||
from vyper import compiler | ||
|
||
valid_list = [ | ||
""" | ||
@external | ||
@view | ||
def foo() -> bytes32: | ||
return blobhash(0) | ||
""", | ||
""" | ||
@external | ||
@view | ||
def foo() -> bytes32: | ||
a: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000005 | ||
a = blobhash(2) | ||
return a | ||
""", | ||
""" | ||
@external | ||
@view | ||
def foo() -> bytes32: | ||
a: bytes32 = blobhash(0) | ||
assert a != empty(bytes32) | ||
return a | ||
""", | ||
""" | ||
@external | ||
@view | ||
def foo() -> bytes32: | ||
a: bytes32 = blobhash(1337) | ||
assert a == empty(bytes32) | ||
return a | ||
""", | ||
] | ||
|
||
|
||
@pytest.mark.requires_evm_version("cancun") | ||
@pytest.mark.parametrize("good_code", valid_list) | ||
def test_blobhash_success(good_code): | ||
assert compiler.compile_code(good_code) is not None | ||
assembly = compiler.compile_code(good_code, output_formats=["asm"])["asm"].split(" ") | ||
assert "BLOBHASH" in assembly | ||
|
||
|
||
@pytest.mark.requires_evm_version("cancun") | ||
def test_get_blobhashes(env, get_contract, tx_failed): | ||
code = """ | ||
x: public(bytes32) | ||
@external | ||
def set_blobhash(i: uint256): | ||
self.x = blobhash(i) | ||
""" | ||
c = get_contract(code) | ||
|
||
# to get the expected versioned hashes: | ||
# | ||
# from eth_account._utils.typed_transactions import BlobTransaction | ||
# blob_transaction = BlobTransaction.from_bytes(HexBytes(signed.rawTransaction)) | ||
# print(blob_transaction.blob_data.versioned_hashes) | ||
expected_versioned_hash = "0x0168dea5bd14ec82691edc861dcee360342a921c1664b02745465f6c42239f06" | ||
|
||
def _send_tx_with_blobs(num_blobs, input_idx): | ||
env.blob_hashes = [bytes.fromhex(expected_versioned_hash[2:])] * num_blobs | ||
c.set_blobhash(input_idx) | ||
|
||
c.set_blobhash(0) | ||
assert c.x() == b"\x00" * 32 | ||
|
||
_send_tx_with_blobs(1, 0) | ||
assert "0x" + c.x().hex() == expected_versioned_hash | ||
|
||
_send_tx_with_blobs(6, 5) | ||
assert "0x" + c.x().hex() == expected_versioned_hash | ||
|
||
_send_tx_with_blobs(1, 1) | ||
assert c.x() == b"\x00" * 32 |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
"signextend", | ||
"chainid", | ||
"basefee", | ||
"blobhash", | ||
"blobbasefee", | ||
"timestamp", | ||
"blockhash", | ||
|
This file contains 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 |
---|---|---|
|
@@ -97,6 +97,7 @@ | |
"delegatecall", | ||
"codesize", | ||
"basefee", | ||
"blobhash", | ||
"blobbasefee", | ||
"prevrandao", | ||
"difficulty", | ||
|
Oops, something went wrong.
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.
this is a nit but i'm not a huge fan of importing things that are only used in type signatures, i am starting to prefer guarding these with
if TYPE_CHECKING