compiler: preserve bool[N] in validateOutputState state encoding - #171
Open
oskrcl wants to merge 1 commit into
Open
compiler: preserve bool[N] in validateOutputState state encoding#171oskrcl wants to merge 1 commit into
oskrcl wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
bool[N]arm tofixed_type_sizein the VOS state encoder, preserving correct byte-width for bool arrays invalidateOutputStateround-trip.Motivation
Without this patch,
fixed_type_sizereturnsNoneforbool[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 usingbool[N]in VOS bodies (e.g.,cov_cash.sil).Changes
silverscript-lang/src/compiler/compile.rs(+19 lines):fixed_type_size: addis_bool()arm returningSome(size as i64)— 1 byte per bool element (vs 8 bytes per int)fixed_type_size_accepts_bool_arrayunit test:bool[2]→Some(2),bool[4]→Some(4), scalarbool→Some(1)silverscript-lang/tests/compiler_tests.rs(+22 lines):compiles_validate_output_state_with_bool_array_field— integration test:bool[2]field in VOS compilesVerification
cargo build --release -p silverscript-lang✅cargo test -p silverscript-lang --release— 497 passed, 0 failed ✅2a3961c(upstream master HEAD at time of branch)Encoding Correctness
fixed_type_sizedetermines 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 PRbyte[N]→Some(N)(existing)Bool encoding uses
OpNum2Bin(1)per element — same mechanism asbyte[N], only the type inference path differs.Functional Dependency
Depends on #170 (
Expr::bool_array+From<Vec<bool>>) — that PR enables constructingbool[N]values; this PR enables encoding them correctly. Both needed for full VOS round-trip.