feat(jlvm): hex_to_int opcode + conformance vectors#56
Merged
scasplte2 merged 1 commit intoJun 19, 2026
Conversation
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
approved these changes
Jun 19, 2026
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
New JLVM opcode
hex_to_intin the canonical Scala evaluator. Sister PR for the Rust + TypeScript ports + shared vectors:Constellation-Labs/metakit-sdk#62(branchfeat/jlvm-hex-to-int).Motivation:
ecvrf_verifyreturnsbetaas a0xhex 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_intbridges 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
HexBytescodec (0x+ lowercase + even-length) → unsigned big-endianIntValue(BigInt(1, bytes))."0x"→0, always non-negative; malformed / non-string / wrong-arity →JsonLogicException. (JLVM ints are arbitrary-precision BigInt, so a 512-bitbetaconverts losslessly; reduce with%.)Changes
JsonLogicOp.scala(enum),JsonLogicSemantics.scala(dispatch + handler, modeled onhandleModuloOp),ops/HexOps.scala(impl)GasMetering.scala+JsonLogicGasEstimator.scala—GasCost(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 samehex_to_intvectors as Rust + TSVerification: 836
json_logictests (23 new) +SharedVectorConformanceSuite [hex_to_int] 21/21;scalafmtCheckAllclean. (Pre-existing, unrelated:project/Dependencies.scalahas scalafmt drift — left untouched.)🤖 Generated with Claude Code