Skip to content

feat(jlvm): hex_to_int opcode + conformance vectors#56

Merged
scasplte2 merged 1 commit into
Constellation-Labs:devfrom
ottobot-ai:feat/jlvm-hex-to-int
Jun 19, 2026
Merged

feat(jlvm): hex_to_int opcode + conformance vectors#56
scasplte2 merged 1 commit into
Constellation-Labs:devfrom
ottobot-ai:feat/jlvm-hex-to-int

Conversation

@ottobot-ai

@ottobot-ai ottobot-ai commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

New JLVM opcode hex_to_int in the canonical Scala evaluator. Sister PR for the Rust + TypeScript ports + shared vectors: Constellation-Labs/metakit-sdk#62 (branch feat/jlvm-hex-to-int).

Motivation: ecvrf_verify returns beta as a 0x hex string of verifiable randomness, but JLVM had no hex→number path (string coercion only parses decimal), so contracts could verify VRF output yet not use it. hex_to_int bridges it: {"%": [{"hex_to_int":[{"var":"beta"}]}, n]} → a deterministic, verifiable winner index. General-purpose (any crypto-op hex output → number).

Semantics: arity-1 string → reuse the shared HexBytes codec (0x + lowercase + even-length) → unsigned big-endian IntValue(BigInt(1, bytes)). "0x"→0, always non-negative; malformed / non-string / wrong-arity → JsonLogicException. (JLVM ints are arbitrary-precision BigInt, so a 512-bit beta converts losslessly; reduce with %.)

Changes

  • JsonLogicOp.scala (enum), JsonLogicSemantics.scala (dispatch + handler, modeled on handleModuloOp), ops/HexOps.scala (impl)
  • Gas: GasMetering.scala + JsonLogicGasEstimator.scalaGasCost(10) (= the modulo op)
  • test/.../HexOpsSuite.scala (23 cases) + synced cross-language conformance vectors (conformance/json_logic_test_vectors.json → 1.5.0) so Scala runs the same hex_to_int vectors as Rust + TS

Verification: 836 json_logic tests (23 new) + SharedVectorConformanceSuite [hex_to_int] 21/21; scalafmtCheckAll clean. (Pre-existing, unrelated: project/Dependencies.scala has scalafmt drift — left untouched.)

🤖 Generated with Claude Code

New JLVM opcode in the canonical Scala evaluator: parse a 0x-prefixed lowercase
hex string (reusing the shared HexBytes codec) as an unsigned big-endian,
arbitrary-precision integer (BigInt(1, bytes)). Bridges crypto-op hex outputs
(e.g. ecvrf_verify's beta) into the numeric domain for `% n` selection, etc.
Empty "0x" -> 0; always non-negative; malformed / non-string / wrong-arity ->
JsonLogicException. Gas = GasCost(10) (= the modulo op).

JsonLogicOp.scala (enum), JsonLogicSemantics.scala (dispatch + handler),
ops/HexOps.scala (impl), GasMetering.scala + JsonLogicGasEstimator.scala (gas),
test HexOpsSuite.scala (23 cases). Synced the cross-language conformance vectors
(src/test/resources/conformance/json_logic_test_vectors.json -> 1.5.0) so the
Scala evaluator runs the same hex_to_int vectors as Rust + TS.

Verified: 836 json_logic tests + SharedVectorConformanceSuite [hex_to_int] 21/21;
scalafmtCheckAll clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@scasplte2 scasplte2 merged commit ac6dfec into Constellation-Labs:dev Jun 19, 2026
1 check passed
@scasplte2 scasplte2 deleted the feat/jlvm-hex-to-int branch June 19, 2026 03:15
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.

2 participants