gnatprove #4

Merged
vimacs merged 7 commits from wehack-dev/ssh_protocol-ada:dev into main 2026-10-19 02:43:40 +00:00
Contributor
No description provided.
Add Can_Encode_Bytes_To_Buffer and
Can_Encode_Byte_Array_As_String_To_Buffer, plus contract versions of
Encode_Bytes and Encode_Byte_Array_As_String with offset postconditions.

Relax the Encode_String contract so that callers no longer need
S'First = 1: the string copy now works for any Positive index range, and
an empty value no longer builds an out-of-range null slice.

Harmonize Can_Encode_String_To_Buffer with the encode procedures by
taking an Extended_Packet_Byte_Idx offset and checking the lower bound.
The status-returning overloads are kept temporarily for migration.
Remove the Status-returning Encode_String, Encode_Bytes and
Encode_Byte_Array_As_String overloads. Callers now check capacity with
Can_Encode_*_To_Buffer and then call the contract version, whose Pre
requires the check and whose Post records the offset advance.

The Can_Encode_* helpers take Buffer'Last instead of the buffer object
so they can be used on uninitialized out buffers without reading
undefined contents.

Upper-level Build_* procedures keep their Buffer_Status interface for
now: they map a failed capacity check to Buffer_Too_Small and set
Success explicitly on the success path (previously the last status
encode call did that).

Delete the duplicate local SSH-string encoders in Authentication and
Transport.Kex in favour of the unified primitives. Update unit tests to
the contract API and cover the new capacity predicates.
Strengthen contracts and loop invariants so all checks are proved at
proof level 2:

- Accept null-array bounds via Integer Buffer_Last in capacity queries.
- Add lower-bound preconditions to encode primitives.
- Remove the nested String_To_Bytes helper and write Encode_String's
  conversion loop directly.
- Add loop invariants for Encode_String and Decode_String.
- Reject offsets below Buffer'First in Decode_Bytes.

Add tests for null-buffer capacity checks and invalid Decode_Bytes
offsets. Record the work in doc/develop.md.
The success case of Decode_String now guarantees Length <= Value'Length.  This is needed to prove the decoded prefixes returned by Parse_Disconnect fit in the caller's output buffers.

Verified with: alr gnatprove -P ssh_protocol.gpr -u ssh_protocol-message_format.ads -j0 --level=2 --output=oneline --output-header
Add pre/postconditions to Build_Disconnect and Parse_Disconnect, use Extended_Packet_Byte_Idx for cursor offsets, and add assertions needed to discharge the length and decoded-prefix postconditions.  Parse_Disconnect output strings are marked Relaxed_Initialization since Decode_String only guarantees the decoded prefix.

Proof: alr gnatprove -P ssh_protocol.gpr -u ssh_protocol-disconnect.adb -j0 --steps=500000 --output=oneline --output-header
Result: Build_Disconnect 9/9 checks, Parse_Disconnect 15/15 checks.
Document the contracts added to SSH_Protocol.Disconnect, the Decode_String postcondition needed by Parse_Disconnect, the proof command with its step limit, and the test results.
wehack-dev changed title from gnatprove message format to gnatprove 2026-10-17 15:10:00 +00:00
vimacs approved these changes 2026-10-19 02:43:06 +00:00
Dismissed
vimacs approved these changes 2026-10-19 02:43:19 +00:00
vimacs merged commit 2e157cc916 into main 2026-10-19 02:43:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
vimacs/ssh_protocol-ada!4
No description provided.