Skip to main content

Gas Cost Reference

Each confidential precompile has a base gas cost plus, in most cases, a per-byte cost that scales with input size. This page provides the current values so you can budget accordingly.

Values may change

Gas costs are subject to change in runtime upgrades. The values below are current best estimates; consult the runtime source or perform empirical measurements for critical budgeting.

Cost table

FunctionApprox. base gasPer-byte inputComparable EVM op
Sapphire.randomBytes~10,000+~50/byte~2x sha256
Sapphire.encrypt~15,000+~10/byte~5x sha256
Sapphire.decrypt~15,000+~10/byte~5x sha256
Sapphire.deriveSymmetricKey~20,000~7x ecrecover
Sapphire.generateSigningKeyPair~50,000~15x ecrecover
Sapphire.sign (Ed25519)~30,000+~20/byte~10x ecrecover
Sapphire.sign (Secp256k1)~30,000+~20/byte~10x ecrecover
Sapphire.verify (Ed25519)~30,000+~20/byte~10x ecrecover
Sapphire.verify (Secp256k1)~30,000+~20/byte~10x ecrecover

These numbers are approximate — measure your actual usage in a test environment before shipping gas-sensitive code.

Cost comparison in context

A confidential ERC-20 transfer:

  • Base ERC-20 transfer cost on Ethereum: ~50,000 gas
  • OXN adds encryption of calldata (~5,000) + encryption of return data + encrypted event emission (~10,000)
  • Total: ~65,000–70,000 gas

Slight overhead but negligible for typical usage.

A sealed-bid auction submission:

  • 1x SSTORE of encrypted bid: ~22,000 gas (standard SSTORE, encrypted transparently)
  • 1x Sapphire.randomBytes for nonce: ~11,600
  • Total: ~40,000 gas

A signed attestation (contract signs a claim):

  • Sapphire.sign on 100-byte claim: ~32,000 gas
  • 1x SSTORE to log: ~22,000 gas
  • Total: ~55,000 gas

Budgeting rules of thumb

  • A confidential contract call is roughly 20–50k more expensive than the equivalent plain call.
  • A single precompile invocation is cheap — comparable to a few sha256 calls.
  • Signature operations dominate if used heavily — sign / verify are the most expensive precompiles per call.
  • Batch operations if possible. Multiple Sapphire.encrypt calls with the same key are cheaper than multiple with different keys, because key setup dominates one-shot cost.

Measuring exact costs

For your specific use case, measure directly:

const receipt = await tx.wait();
console.log("Gas used:", receipt.gasUsed.toString());

Run the same call with and without a precompile to isolate the precompile's contribution. Do this on OXN Testnet — local Hardhat network does not model the precompile costs.

Setting gasLimit

Given the added overhead, set gasLimit generously:

Call profileSuggested gasLimit
Encrypted transfer on a confidential ERC-20500_000n
Sealed-bid auction submission (state + random)500_000n
Contract sign of a 200-byte message800_000n
Encrypted key derivation + encrypt round trip500_000n
Complex composed call1_000_000n

Unused gas is refunded, so overshooting is safe.

Next steps