Skip to content

Tolk silently accepts invalid hex digits in stringAddressToSlice, corrupting address literals #1680

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

Open
Gusarich opened this issue May 20, 2025 · 0 comments

Comments

@Gusarich
Copy link

The Tolk compiler incorrectly accepts invalid hexadecimal characters (g-z, G-Z) in the stringAddressToSlice function during constant folding. Instead of reporting an error, it silently generates a corrupted address literal by incorrectly mapping invalid letters beyond f to out-of-range values.

Example Input:

fun onInternalMessage(): slice {
    return stringAddressToSlice("0:gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
}

Incorrect Optimized Output:

onInternalMessage PROC:<{
  // 
  x{8002020202020202020202020202020202020202020202020202020202020202021_} PUSHSLICE
}>

Cause:

  • parse_raw_address interprets letters above f (such as g) as hex digits (16, 17, …) without range checking.
  • These invalid values overflow the 4-bit nibble, corrupting the resulting address.

Impact:
Malformed address literals silently compile into corrupted constants, causing contracts to behave unexpectedly and potentially leading to severe logical and financial errors at runtime.

Expected Behavior:
The compiler must reject invalid hexadecimal literals beyond f explicitly, providing clear compile-time errors instead of silently corrupting address constants.


LLM Fuzzing discovery (see tact-lang/tact#3123)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant