-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Feature] Introduce IdentifierLiteral
#3129
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
base: staging
Are you sure you want to change the base?
Conversation
| /// Reads the identifier literal from a buffer. | ||
| #[inline] | ||
| fn read_le<R: Read>(mut reader: R) -> IoResult<Self> { | ||
| // Read the number of content bytes. |
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.
Version byte?
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.
Existing Identifer doesn't have a version byte (link[https://github.com/ProvableHQ/snarkVM/blob/f8fd99469e73b30638f3f6b0cec461f58a5ea9cd/console/program/src/data/identifier/bytes.rs#L20]) and neither do most Literal variants.
Do we still want to throw it in?
Antonio95
left a comment
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.
Very cool feature. I've reviewed it paying special attention to the in-circuit checks of byte correctness (which are quite complex and seem correct to me). Left only a couple of minor comments, none of them critical.
|
ProgramID's are all lowercase alphanumeric ( |
It does not. The target of a dynamic call is resolved here. |
Motivation
The existing
Identifiertype has value-dependent bit representation in circuits—itsto_bitsoutput length varies based on the identifier's string length. This makes it unsuitable as a literal type where deterministic, fixed-size circuit behavior is required for consistent constraint counts across all valid inputs.This PR introduces
IdentifierLiteral, a new literal type with a fixed 31-byte (248-bit) representation that can be used safely in circuits.What's New
Type:
IdentifierLiteral<E>/identifier'identifier_name'(single-quoted, no type suffix)[a-zA-Z][a-zA-Z0-9_]*(must start with a letter)Console Layer (
console/types/string/src/identifier_literal/):ToBits,FromBits,ToField,FromFieldCircuit Layer (
circuit/types/string/src/identifier_literal/):Integration:
Literalenum withIdentifiervariantLiteralType::IdentifierandPlaintextTypesupportidentifierto/fromfield(and throughfieldto other types)rand.chachaandhashdestination types (cannot generate random identifiers)Usage in Aleo Programs
Declaring inputs/outputs:
Using literals in instructions:
Passing as input (CLI/SDK):
In structs and mappings:
Test Plan
Unit Tests (72 total)
Console layer (
cargo test -p snarkvm-console-types-string --lib identifier_literal):Circuit layer (
cargo test -p snarkvm-circuit-types-string --lib identifier_literal):Integration Test
synthesizer/src/vm/tests/test_v14.rs::test_identifier_literal_migration:ConsensusVersion::V14Documentation
The following documentation should be updated:
identifierto the list of literal types with syntax'name'[a-zA-Z][a-zA-Z0-9_]*Backwards Compatibility
Consensus Gating
This feature is gated behind
ConsensusVersion::V14:Syntax Detection:
contains_v14_syntax()extended to detect:Operand::Literalwhere literal type isIdentifieridentifiertype in function/closure inputs and outputsidentifiertype in finalize inputsidentifiertype in struct members, record entries, and mapping keys/valuesKeyword Restriction:
"identifier"added toRESTRICTED_KEYWORDSfor V14+, preventing its use as a user-defined identifier in programs deployed at or after V14.Deployment Validation: Programs using identifier literals or the
identifiertype will fail deployment before the V14 activation height.No Breaking Changes