Fix assignment of string literals to felt252 type in error messages #1238
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.
This update addresses an issue where string literals (such as
'Account: invalid caller'
) were incorrectly assigned to constants of typefelt252
. The typefelt252
is intended for numeric values, not string literals. This resulted in a type mismatch, asfelt252
cannot directly store strings.To resolve this, the string literals have been replaced with their corresponding hashes using the Poseidon hash function. This ensures the values are correctly represented as
felt252
, which is the appropriate type for error messages in Cairo.Importance:
This fix is critical as it prevents runtime errors and ensures that error messages are correctly represented within the Cairo contract environment. Without this change, the contract would fail when attempting to use string literals as
felt252
, potentially leading to unexpected behavior or reverts during execution.Here is the corrected code:
By using
Poseidon
for string hashing, the error constants are now correctly represented and can be used without issues.