Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix v1 Autolykos zero pow_distance serialization to match sigma JVM#872

Open
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/autolykos-v1-zero-distance
Open

Fix v1 Autolykos zero pow_distance serialization to match sigma JVM#872
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/autolykos-v1-zero-distance

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 3, 2026

Copy link
Copy Markdown

AutolykosSolution::serialize_bytes encodes a v1 PoW distance of 0 as 01 00 (via BigUint::to_bytes_be()[0]), while the sigma JVM emits 00.

Sigma's BigIntegers.asUnsignedByteArray reimplements BouncyCastle but drops the && bytes.length != 1 guard, so a zero value strips to an empty array. The mismatch diverges on serialized header bytes (hence header id) and Global.serialize[Header] cost — a consensus split on the degenerate path.

Fix: mirror asUnsignedByteArray — empty for zero, minimal big-endian otherwise (identical to to_bytes_be for positive d). A real PoW distance is never zero, so no mainnet impact; this closes the adversarial edge. Adds a regression test.

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]>
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