feat[lang]: add native hex string literals#4271
Merged
charles-cooper merged 24 commits intovyperlang:masterfrom Oct 11, 2024
Merged
feat[lang]: add native hex string literals#4271charles-cooper merged 24 commits intovyperlang:masterfrom
charles-cooper merged 24 commits intovyperlang:masterfrom
Conversation
vyper/ast/pre_parser.py
Outdated
|
|
||
|
|
||
| class ForParserState(enum.Enum): | ||
| class CustomParserState(enum.Enum): |
Member
|
please add docs! |
vyper/ast/parse.py
Outdated
|
|
||
| byte_val = bytes.fromhex(node.value) | ||
|
|
||
| node.ast_type = "Bytes" |
Member
There was a problem hiding this comment.
i am not a huge fan of fusing it into the Bytes type, since we lose information in the AST. let's make a new VyperNode AST type, maybe XBytes or HexBytes?
This reverts commit dbb8f47.
| return ast_dict | ||
|
|
||
| @property | ||
| def s(self): |
Member
There was a problem hiding this comment.
i wonder what would happen if we removed all of these 🤔
out of scope for this PR but we should check if that is still needed, since it was basically originally introduced for backwards compatibility
vyper/ast/parse.py
Outdated
Comment on lines
+345
to
+347
| node.ast_type = self._pre_parse_result.modification_offsets[ | ||
| (node.lineno, node.col_offset) | ||
| ] |
Member
There was a problem hiding this comment.
let's try to avoid the multi-line formatting
Suggested change
| node.ast_type = self._pre_parse_result.modification_offsets[ | |
| (node.lineno, node.col_offset) | |
| ] | |
| key = (node.lineno, node.col_offset) | |
| node.ast_type = self._pre_parse_result.modification_offsets[key] |
vyper/ast/pre_parser.py
Outdated
| return True | ||
|
|
||
|
|
||
| class NativeHexParser: |
Member
There was a problem hiding this comment.
Suggested change
| class NativeHexParser: | |
| class HexStringParser: |
Member
charles-cooper
left a comment
There was a problem hiding this comment.
looking good. just a couple ideas about naming, and let's try to keep multiline statements to a minimum
charles-cooper
approved these changes
Oct 11, 2024
pcaversaccio
added a commit
to pcaversaccio/snekmate
that referenced
this pull request
Oct 18, 2024
### 🕓 Changelog Vyper has introduced support for native hex string literals, such as `x"a1b9"` (see PR [#4271](vyperlang/vyper#4271)). This update refactors the 🐍 snekmate contracts—`base64` and `message_hash_utils`—to take advantage of the new syntax. However, the `internal` function `_to_eth_signed_message_hash` remains unchanged, as its current implementation with `\x19` provides better clarity. Moreover, the `external` function `eip712Domain` in the `eip712_domain_separator` contract has been simplified to utilise a `bytes1` literal. Additionally, all submodules have been updated to their latest commits, and the latest Vyper `master` commit is now once again applied in all `venom`-based tests, following the resolution of issue [#4288](vyperlang/vyper#4288) through this [commit](vyperlang/vyper@b3ea663). --------- Signed-off-by: Pascal Marco Caversaccio <[email protected]>
willbrown84
added a commit
to willbrown84/snekmate
that referenced
this pull request
Sep 23, 2025
### 🕓 Changelog Vyper has introduced support for native hex string literals, such as `x"a1b9"` (see PR [#4271](vyperlang/vyper#4271)). This update refactors the 🐍 snekmate contracts—`base64` and `message_hash_utils`—to take advantage of the new syntax. However, the `internal` function `_to_eth_signed_message_hash` remains unchanged, as its current implementation with `\x19` provides better clarity. Moreover, the `external` function `eip712Domain` in the `eip712_domain_separator` contract has been simplified to utilise a `bytes1` literal. Additionally, all submodules have been updated to their latest commits, and the latest Vyper `master` commit is now once again applied in all `venom`-based tests, following the resolution of issue [#4288](vyperlang/vyper#4288) through this [commit](vyperlang/vyper@b3ea663). --------- Signed-off-by: Pascal Marco Caversaccio <[email protected]>
void-rider5560p
added a commit
to void-rider5560p/snekmate
that referenced
this pull request
Sep 28, 2025
### 🕓 Changelog Vyper has introduced support for native hex string literals, such as `x"a1b9"` (see PR [#4271](vyperlang/vyper#4271)). This update refactors the 🐍 snekmate contracts—`base64` and `message_hash_utils`—to take advantage of the new syntax. However, the `internal` function `_to_eth_signed_message_hash` remains unchanged, as its current implementation with `\x19` provides better clarity. Moreover, the `external` function `eip712Domain` in the `eip712_domain_separator` contract has been simplified to utilise a `bytes1` literal. Additionally, all submodules have been updated to their latest commits, and the latest Vyper `master` commit is now once again applied in all `venom`-based tests, following the resolution of issue [#4288](vyperlang/vyper#4288) through this [commit](vyperlang/vyper@b3ea663). --------- Signed-off-by: Pascal Marco Caversaccio <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What I did
Resolves #4206
How I did it
Add a custom parser to watch for
STRINGtokens whenever there is aNAMEtokens of "x" value, store the location of these hex literals, and transform them to byte values during transformation of the python ast to vyper ast.How to verify it
See new tests.
Commit message
Description for the changelog
Cute Animal Picture