Skip to content

compiler: preserve bool[N] in validateOutputState state encoding - #171

Open
oskrcl wants to merge 1 commit into
kaspanet:masterfrom
oskrcl:fix/vos-bool-array-encoding
Open

compiler: preserve bool[N] in validateOutputState state encoding#171
oskrcl wants to merge 1 commit into
kaspanet:masterfrom
oskrcl:fix/vos-bool-array-encoding

Conversation

@oskrcl

@oskrcl oskrcl commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Adds bool[N] arm to fixed_type_size in the VOS state encoder, preserving correct byte-width for bool arrays in validateOutputState round-trip.

Motivation

Without this patch, fixed_type_size returns None for bool[N] types, meaning the VOS encoder cannot determine the serialized size of bool array fields. This breaks state encoding round-trip for any covenant contract using bool[N] in VOS bodies (e.g., cov_cash.sil).

Changes

  • silverscript-lang/src/compiler/compile.rs (+19 lines):

    • fixed_type_size: add is_bool() arm returning Some(size as i64) — 1 byte per bool element (vs 8 bytes per int)
    • fixed_type_size_accepts_bool_array unit test: bool[2]Some(2), bool[4]Some(4), scalar boolSome(1)
  • silverscript-lang/tests/compiler_tests.rs (+22 lines):

    • compiles_validate_output_state_with_bool_array_field — integration test: bool[2] field in VOS compiles

Verification

  • cargo build --release -p silverscript-lang
  • cargo test -p silverscript-lang --release — 497 passed, 0 failed ✅
  • Branch based on 2a3961c (upstream master HEAD at time of branch)

Encoding Correctness

fixed_type_size determines serialized byte width for fixed-size arrays in state encoding:

  • int[N]Some(N * 8) (8 bytes per int)
  • bool[N]Some(N) (1 byte per bool) ← this PR
  • byte[N]Some(N) (existing)

Bool encoding uses OpNum2Bin(1) per element — same mechanism as byte[N], only the type inference path differs.

Functional Dependency

Depends on #170 (Expr::bool_array + From<Vec<bool>>) — that PR enables constructing bool[N] values; this PR enables encoding them correctly. Both needed for full VOS round-trip.

fixed_type_size in compile.rs handles arrays for byte[] and int[]
but not bool[], causing fixed_state_payload_len to return None for
bool[N] fields. This propagates to compile_encoded_state_object and
compile_encoded_flat_state_fields, rejecting bool[N] in
validateOutputState/validateNextState.

Fix by adding is_bool() branch: bool is 1 byte per element, same
layout as byte[N].

Adds:
- Unit test fixed_type_size_accepts_bool_array in compile.rs
- Integration test compiles_validate_output_state_with_bool_array_field
  in compiler_tests.rs
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

Successfully merging this pull request may close these issues.

1 participant