fix(validator): SCALE-encode str args in _encode_args (#1374)#1376
fix(validator): SCALE-encode str args in _encode_args (#1374)#1376jakearmstrong59 wants to merge 1 commit into
Conversation
After entrius#1335, gitt issues register routes through _encode_args, which had no str branch and raised ValueError for every register_issue call before any extrinsic was submitted. Add a SCALE str encoder (compact-length prefix + UTF-8 bytes) and a module-level _scale_compact_length helper covering modes 0/1/2.
|
Can you show me the tests you ran to verify it worked. Local testnet subtensor with locally deployed contract is fine. |
|
Hi @anderdc how are you? Thanks for reviewing. I've tested locally against substrate-contracts-node --dev with a stub contract that has the same register_issue signature + same selector (0x5c056a24). I've run gitt issues register twice - once with a short URL, once with a long one to hit both compact-length branches the PR adds: gitt issues register --contract 5C9feb... --network local gitt issues register --contract 5C9feb... --network local Read back via cargo contract call get_last_registered → both decode byte-perfect: I used a stub, not the real contract, because the real one needs SubtensorExtension(5001) which stock substrate-contracts-node doesn't have. |
Summary
Fixes #1375
After #1335,
gitt issues registerroutes throughIssueCompetitionContractClient.register_issue→_exec_contract_raw→_encode_args._encode_argshad nostrbranch and raisedValueError: Unsupported type: str for arg github_urlon everyregister_issuecall, before any extrinsic was submitted.This PR adds SCALE encoding for
str: a compact-length prefix (modes 0/1/2 covered by a new_scale_compact_lengthhelper) followed by the UTF-8 bytes — matching howString/Vec<u8>are encoded in SCALE.Changes
gittensor/validator/issue_competitions/contract_client.py_scale_compact_length(n)covering SCALE compact integer modes 0 (n < 2⁶), 1 (n < 2¹⁴), and 2 (n < 2³⁰). Rejects negative input and values that would require big-integer mode 3 (not reachable for any payload sent by the client).'str'branch in_encode_args: type-checks, UTF-8 encodes, prepends compact length.tests/validator/test_contract_client_transactions.pyTestScaleCompactLength— parametrized boundary coverage for every mode (0/1/2) plus negative and oversize rejection.TestEncodeArgsStr— byte-level assertion of the fullregister_issueencoding: short URL (mode 0), long URL ≥64 bytes (mode 1), non-strrejected with a clear message, UTF-8 multibyte URL.Testing
pytest tests/→ 892 passed.pytest tests/validator/test_contract_client_transactions.py→ 43 passed (28 pre-existing + 15 new).fc503f9, succeeds after this change with a 70-byte payload whose layout is byte-checked in the new tests.ruff checkandruff format --checkclean repo-wide.Notes
_raw_contract_readhas an unrelated compact-length encoding branch (also flagged in fix: remove dead branches in _encode_args and compact length encoder #987/fix: remove dead branches in _encode_args and compact length encoder #988) that would overflow fordata_len ≥ 64. It's currently only fed 4-byte selectors so it never triggers; out of scope for this PR but a candidate for follow-up using the new_scale_compact_lengthhelper.register_issue'sgas_limit(proof_size=1_000_000) was set in Bump bittensor stack and drop substrate-interface #1335 and is unchanged here; this PR only fixes pre-submission encoding.