Fix v1 Autolykos zero pow_distance serialization to match sigma JVM#872
Open
mwaddip wants to merge 1 commit into
Open
Fix v1 Autolykos zero pow_distance serialization to match sigma JVM#872mwaddip wants to merge 1 commit into
mwaddip wants to merge 1 commit into
Conversation
AutolykosSolution::serialize_bytes wrote the v1 PoW distance via BigUint::to_bytes_be(), which returns [0] for zero. The JVM's sigma/crypto/BigIntegers.scala asUnsignedByteArray drops BouncyCastle's length-1 guard, so it encodes zero as an EMPTY array. The Rust path emitted 01 00 where the JVM emits 00, diverging on the serialized header bytes (hence header id) and Global.serialize cost. Mirror asUnsignedByteArray exactly: empty bytes for zero, minimal big-endian otherwise (identical to to_bytes_be for all positive values). A real PoW distance is never zero, so this is an adversarial/degenerate edge with no mainnet impact, but a genuine consensus divergence in the serializer. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
AutolykosSolution::serialize_bytesencodes a v1 PoW distance of0as01 00(viaBigUint::to_bytes_be()→[0]), while the sigma JVM emits00.Sigma's
BigIntegers.asUnsignedByteArrayreimplements BouncyCastle but drops the&& bytes.length != 1guard, so a zero value strips to an empty array. The mismatch diverges on serialized header bytes (hence header id) andGlobal.serialize[Header]cost — a consensus split on the degenerate path.Fix: mirror
asUnsignedByteArray— empty for zero, minimal big-endian otherwise (identical toto_bytes_befor positived). A real PoW distance is never zero, so no mainnet impact; this closes the adversarial edge. Adds a regression test.