Skip to content

feat(vara.eth/gear): syscall interface for cryptographic host calls - #5582

Draft
grishasobol wants to merge 12 commits into
masterfrom
gsobol/ethexe/crypto-syscalls
Draft

feat(vara.eth/gear): syscall interface for cryptographic host calls#5582
grishasobol wants to merge 12 commits into
masterfrom
gsobol/ethexe/crypto-syscalls

Conversation

@grishasobol

Copy link
Copy Markdown
Contributor

Closes #5456

Summary

Adds the ethexe-only gr_crypto syscall: programs forward cryptographic operations to the host instead of bundling crypto into their Wasm binary.

  • ABI (gsys): one generic syscall gr_crypto(op, input_ptr, input_len, output_ptr, output_len, err_ptr) with an append-only CryptoOp enum: Keccak256, Sha256, Blake2b256, Bls12381Verify (min-pk, BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_ — same DST as the Vara builtin), Bls12381AggregateG1. Fixed per-op output sizes.
  • Instrumentation (gear-wasm-instrument): SyscallName::Crypto is the first ethexe-only syscall — is_vara() now excludes it, the Vara backend env count assert is fixed accordingly.
  • Backend / costs: handler validates op + output capacity and charges op-dependent CostToken::Crypto(op, input_bytes) (base + per-byte; placeholder weights, TODO #5456: benchmark). Vara Ext rejects with Unsupported (the syscall is never linked there).
  • Host execution (ethexe): Externalities::cryptoRuntimeInterface::cryptoext_crypto_version_1 wasmtime host fn → native sha3/sha2/blake2 + arkworks BLS12-381. Malformed input maps to new error code ExecutionError::CryptoInputInvalid = 109. RUNTIME_ID / CODES_INSTRUMENTATION_VERSION bumped (syscall set changed).
  • Program API: typed wrappers in gcore::crypto, re-exported as gstd::crypto under the ethexe feature. Note: the issue says "ethexe-sdk", but that crate is the client-side SDK — program authors use gstd, so the wrappers live there.
  • wasm-builder: programs opting into their own ethexe feature are now validated against the ethexe syscall set (CARGO_FEATURE_ETHEXE), instead of being forced to Vara validation by the workspace-hack heuristic.

Test plan

  • Unit: native ops pinned to NIST/keccak reference vectors; BLS verify roundtrip + malformed-input rejection (incl. identity pubkey); aggregation vs scalar sum
  • Integration (ethexe-processor): demo-crypto-ethexe end-to-end through the full syscall path — digests match native impl; BLS verify accepts valid / rejects forged / errors on garbage
  • Proptests: execute never panics on arbitrary input and respects declared output sizes; G1 aggregation is order-independent
  • Instrumentation tests updated: gr_crypto present in the Eth set, absent from Vara
  • Broad sweep: 725/730 passed (5 failures = known Anvil flaky set, all pass in isolation); doc tests clean
  • fmt / clippy / shear / hakari clean

Known limitations

  • Crypto weights are placeholders pending benchmarks (TODO #5456: benchmark).
  • protocol/core/src/gas_metering/schedule.rs is generated from the Vara pallet schedule; the crypto fields added there would be dropped by a future regeneration (compile error would flag it) — needs a decision on where ethexe-only weights should live long-term.

🤖 Generated with Claude Code

grishasobol and others added 5 commits June 11, 2026 23:09
Ethexe-only syscall forwarding cryptographic operations (keccak256,
sha256, blake2b-256, BLS12-381 verify/aggregate) to the host. CryptoOp
ids and buffer layouts live in gsys; the syscall is excluded from the
Vara instrumentable set (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Backend handler validates op and output capacity, charges op-dependent
CostToken::Crypto (base + per-byte), and dispatches Externalities::crypto.
Vara Ext rejects with Unsupported — the syscall is never linked there;
ethexe delegates to the stub until host forwarding lands (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Forward crypto ops from the runtime Ext through RuntimeInterface and the
ext_crypto_version_1 host fn into native implementations (sha3/sha2/
blake2, BLS12-381 via arkworks, same ciphersuite DST as the Vara
builtin). Malformed input maps to the new CryptoInputInvalid error code.
RUNTIME_ID and CODES_INSTRUMENTATION_VERSION are bumped: the syscall set
changed (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
keccak256 / sha256 / blake2b256 / bls12_381_verify /
bls12_381_aggregate_g1 under the ethexe feature; the verify input is
assembled on the stack buffer to keep gcore alloc-free (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
demo-crypto-ethexe exercises every CryptoOp from program code; processor
integration tests assert syscall-path digests match the native impl and
BLS verify accepts/rejects end-to-end. Proptests pin no-panic and
output-size invariants plus G1 aggregation order independence.
wasm-builder now picks the ethexe syscall set when the program's own
`ethexe` feature is on (CARGO_FEATURE_ETHEXE), instead of forcing Vara
validation for all in-tree programs (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@grishasobol grishasobol added type: feat New functionality or user-visible improvement scope: vara.eth Vara Ethereum application layer (L2) ai-generated Created entirely by an AI agent without direct human authorship labels Jun 11, 2026
grishasobol and others added 7 commits June 12, 2026 00:24
Move native gr_crypto implementations into ethexe-runtime-common
(std-gated crypto_ops) so both ethexe-processor and the gtest ethexe
runtime use one implementation; cover SyscallName::Crypto in the
pallet-gear syscall integrity bench match (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Linking gear-wasm-builder/ethexe from the demo flipped the builder's
global SYSCALL_KIND to Eth for every program in --all-features
workspace builds, rejecting Vara-only imports in unrelated demos. The
per-crate CARGO_FEATURE_ETHEXE detection is sufficient and precise.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
process_costs_are_same requires the pallet and gas-metering schedules
to agree; keeping the crypto placeholders only on the gas-metering side
broke it (and a weight-dump regeneration would have dropped them). The
weights are constants — the syscall is never linked on Vara — pending
ethexe benchmarks (#5456).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ring

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- charge unknown crypto ops by declared input length with the most
  expensive per-byte coefficients — the buffer is read before rejection
  (codex P1 + opus)
- raise BLS placeholder weights: verify base to 1.5ms-equivalent
  (pairing + hash-to-curve + subgroup checks), aggregation per-byte to
  cover subgroup-checked point deserialization (~150us/48B point) — the
  old per-byte rate under-priced attacker-supplied points by orders of
  magnitude (opus high)
- replace the global CARGO_FEATURE_ETHEXE heuristic in wasm-builder
  with an explicit `build_ethexe()` build.rs entry point, so external
  crates with an unrelated `ethexe` feature keep Vara validation
- reject identity BLS signatures up front per the IETF spec
- pin the exact gr_crypto signature shape in wasm-instrument tests
- regenerate gsdk metadata for the new weight values

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Created entirely by an AI agent without direct human authorship scope: vara.eth Vara Ethereum application layer (L2) type: feat New functionality or user-visible improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add syscall interface for cryptographic host calls in ethexe programs

1 participant