-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
The compile-time address() builtin accepts a raw 64-hex string without a workchain: prefix and (in current artifacts) treats it as workchain 0, making it equal to address("0:<hex>"). However, Fift’s runtime address parser ($>smca) treats the same no-prefix string as invalid (workchain = -2147483648, workchainInvalid). This makes address constants depend on a non-standard/ambiguous input format. Additionally, the CTFE implementation appears to leave workchain unassigned for the no-prefix case, so the compiled workchain value is effectively undefined.
Reproduction
Create /tmp/tolk_address_no_workchain_prefix.tolk:
tolk 1.0
fun onInternalMessage() { return 0; }
const A0: address = address("0:527964d55cfa6eb731f4bfc07e9d025098097ef8505519e853986279bd8400d8");
const A_no_wc: address = address("527964d55cfa6eb731f4bfc07e9d025098097ef8505519e853986279bd8400d8");
@method_id(100)
fun wc_with_prefix(): int {
return A0.getWorkchain();
}
@method_id(101)
fun wc_without_prefix(): int {
return A_no_wc.getWorkchain();
}
@method_id(102)
fun eq_with_prefix(): int {
return (A0 == A_no_wc) as int;
}
Compile:
./artifacts/tolk /tmp/tolk_address_no_workchain_prefix.tolk > /tmp/tolk_address_no_workchain_prefix.fifCreate /tmp/tolk_address_no_workchain_prefix_runner.fif:
"/tmp/tolk_address_no_workchain_prefix.fif" include <s constant code
100 code 1 runvmx .s cr { drop } depth 1- times
101 code 1 runvmx .s cr { drop } depth 1- times
102 code 1 runvmx .s cr { drop } depth 1- times
// Compare with Fift’s runtime address parser:
"0:527964d55cfa6eb731f4bfc07e9d025098097ef8505519e853986279bd8400d8" $>smca .s cr { drop } depth 1- times
"527964d55cfa6eb731f4bfc07e9d025098097ef8505519e853986279bd8400d8" $>smca .s cr { drop } depth 1- times
Run:
./artifacts/fift -I artifacts/lib /tmp/tolk_address_no_workchain_prefix_runner.fifObserved output
From Tolk-compiled constants:
0 // wc_with_prefix()
0 // wc_without_prefix()
-1 // eq_with_prefix() == true
From Fift runtime parsing ($>smca):
0 ... -1 // "0:<hex>" parses with wc=0
-2147483648 ... -1 // "<hex>" parses with wc=workchainInvalid
Expected behavior
The compiler should either:
- reject the no-prefix raw-hex format as invalid, or
- define and implement it explicitly (without relying on undefined behavior), and keep it consistent with runtime address parsers.