Skip to content

Tolk: stringHexToSlice() accepts 1024-bit slice constants and emits invalid Fift x{...} PUSHSLICE #2039

Description

@Gusarich

stringHexToSlice("<256 hex digits>") (1024 bits / 128 bytes) is accepted by the compiler, but the generated .fif contains a slice literal x{...} PUSHSLICE that Fift rejects at include-time with Invalid hex bitstring constant. This produces un-runnable output for a program that should have been rejected at compile time.

Reproduction

Create /tmp/tolk_stringHexToSlice_1024bits.tolk:

tolk 1.0

fun onInternalMessage() { return 0; }

// 256 hex digits = 1024 bits (does not fit into a single-cell slice literal).
const S: slice = stringHexToSlice("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

@method_id(100)
fun bitsCount(): int {
    return S.remainingBitsCount();
}

Compile:

./artifacts/tolk /tmp/tolk_stringHexToSlice_1024bits.tolk > /tmp/tolk_stringHexToSlice_1024bits.fif

Create /tmp/tolk_stringHexToSlice_1024bits_runner.fif:

"/tmp/tolk_stringHexToSlice_1024bits.fif" include <s constant code
100 code 1 runvmx .s cr { drop } depth 1- times

Run:

./artifacts/fift -I artifacts/lib /tmp/tolk_stringHexToSlice_1024bits_runner.fif

Observed output

Fift fails while interpreting the generated .fif:

Error interpreting file `/tmp/tolk_stringHexToSlice_1024bits_runner.fif`:
...: x{:Invalid hex bitstring constant

Expected behavior

The compiler should reject stringHexToSlice() results that can’t be represented as a slice literal in the generated .fif (or otherwise lower them in a way that produces valid code). In particular, 1024-bit slice constants should not compile into an unassemblable x{...}.

Codegen evidence

The generated .fif contains:

x{0000...0000} PUSHSLICE    // 1024-bit literal (128 bytes) -> invalid in Fift

Metadata

Metadata

Assignees

No one assigned

    Labels

    TolkRelated to Tolk Language / compiler / toolingllm-fuzzing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions