Skip to main content

Opcode and host I/O pricing

This reference provides the latest gas and ink costs for specific WASM opcodes and host I/Os when using Stylus. For a conceptual introduction to Stylus gas and ink, see Gas and ink (Stylus).

ALPHA RELEASE, PUBLIC PREVIEW DOCS

Stylus is currently tagged as a release-candidate. The code has been audited, and testing in production environments is underway. Caution should be taken when used in production scenarios. This documentation is currently in public preview.

To provide feedback, click the Request an update button at the top of this document, join the Arbitrum Discord, or reach out to our team directly by completing this form.

Opcode costs

The Stylus VM charges for WASM opcodes according to the following table, which was determined via a conservative statistical analysis and is expected to change as Stylus matures. Prices may fluctuate across upgrades as our analysis evolves and optimizations are made.

HexOpcodeInkGasNotes
0x00Unreachable10.0001
0x01Nop10.0001
0x02Block10.0001
0x03Loop10.0001
0x04If24000.24
0x05Else10.0001
0x0bEnd10.0001
0x0cBr24000.24
0x0dBrIf24000.24
0x0eBrTable2400 + 325x0.24 + 0.0325xCost varies with table size
0x0fReturn10.0001
0x10Call137501.375
0x11CallIndirect13610 + 650x1.361 + 0.065xCost varies with no. of args
0x1aDrop10.0001
0x1bSelect40000.4Large optimization opportunity
0x20LocalGet2000.02
0x21LocalSet3750.0375
0x22LocalTee2000.02
0x23GlobalGet3000.03
0x24GlobalSet9900.099
0x28I32Load22000.22
0x29I64Load27500.275
0x2cI32Load8S22000.22
0x2dI32Load8U22000.22
0x2eI32Load16S22000.22
0x2fI32Load16U22000.22
0x30I64Load8S27500.275
0x31I64Load8U27500.275
0x32I64Load16S27500.275
0x33I64Load16U27500.275
0x34I64Load32S27500.275
0x35I64Load32U27500.275
0x36I32Store24000.24
0x37I64Store31000.31
0x3aI32Store824000.24
0x3bI32Store1624000.24
0x3cI64Store831000.31
0x3dI64Store1631000.31
0x3eI64Store3231000.31
0x3fMemorySize135001.35
0x40MemoryGrow10.0001
0x41I32Const10.0001
0x42I64Const10.0001
0x45I32Eqz5700.057
0x46I32Eq5700.057
0x47I32Ne5700.057
0x48I32LtS5700.057
0x49I32LtU5700.057
0x4aI32GtS5700.057
0x4bI32GtU5700.057
0x4cI32LeS5700.057
0x4dI32LeU5700.057
0x4eI32GeS5700.057
0x4fI32GeU5700.057
0x50I64Eqz7600.076
0x51I64Eq7600.076
0x52I64Ne7600.076
0x53I64LtS7600.076
0x54I64LtU7600.076
0x55I64GtS7600.076
0x56I64GtU7600.076
0x57I64LeS7600.076
0x58I64LeU7600.076
0x59I64GeS7600.076
0x5aI64GeU7600.076
0x67I32Clz7500.075
0x68I32Ctz7500.075
0x69I32Popcnt5000.05
0x6aI32Add2000.02
0x6bI32Sub2000.02
0x6cI32Mul5500.055
0x6dI32DivS25000.25
0x6eI32DivU25000.25
0x6fI32RemS25000.25
0x70I32RemU25000.25
0x71I32And2000.02
0x72I32Or2000.02
0x73I32Xor2000.02
0x74I32Shl2000.02
0x75I32ShrS2000.02
0x76I32ShrU2000.02
0x77I32Rotl2000.02
0x78I32Rotr2000.02
0x79I64Clz7500.075
0x7aI64Ctz7500.075
0x7bI64Popcnt7500.075
0x7cI64Add2000.02
0x7dI64Sub2000.02
0x7eI64Mul5500.055
0x7fI64DivS29000.29
0x80I64DivU29000.29
0x81I64RemS29000.29
0x82I64RemU29000.29
0x83I64And2000.02
0x84I64Or2000.02
0x85I64Xor2000.02
0x86I64Shl2000.02
0x87I64ShrS2000.02
0x88I64ShrU2000.02
0x89I64Rotl2000.02
0x8aI64Rotr2000.02
0xa7I32WrapI642000.02
0xacI64ExtendI32S2000.02
0xadI64ExtendI32U2000.02
0xc0I32Extend8S2000.02
0xc1I32Extend16S2000.02
0xc2I64Extend8S2000.02
0xc3I64Extend16S2000.02
0xc4I64Extend32S2000.02
0xfc0aMemoryCopy3100 + 125x0.31 + 0.0125xCost varies with no. of bytes
0xfc0bMemoryFill3100 + 125x0.31 + 0.0125xCost varies with no. of bytes

Host I/O costs

Certain operations require suspending WASM execution so that the Stylus VM can perform tasks natively in the host. This costs about 1.25 gas to do. Though we’ll publish a full specification later, the following table details the costs of simple operations that run in the host.

Note that the values in this table were determined via a conservative statistical analysis and are expected to change as Stylus matures. Prices may fluctuate across upgrades as our analysis evolves and optimizations are made.

Host I/OInkGasNotes
read_args12513 + 18287b1.2513 + 1.8287bb = bytes after first 32
write_result12513 + 40423b1.2513 + 4.0423bb = bytes after first 32
keccak281040 + 41920w28.104 + 4.192wDue to a pricing mistake, keccak will soon be ~8 gas cheaper! w = EVM words
block_basefee221372.2137
block_coinbase221372.2137
block_gas_limit125131.2513
block_number125131.2513
block_timestmap125131.2513
chain_id125131.2513
contract_address221372.2137
evm_gas_left125131.2513
evm_ink_left125131.2513
msg_reentrant125131.2513
msg_sender221372.2137
msg_value221372.2137
return_data_size125131.2513
tx_ink_price125131.2513
tx_gas_price221372.2137
tx_origin221372.2137
console_log_text00debug-only
console_log00debug-only
console_tee00debug-only
null_host00debug-only

For some opcodes, the value in the table may be larger than its EVM equivalent. In the vast majority of real-world cases, the Stylus VM will still perform better. For example, getting the raw msg::value costs 0.2137 more gas in Stylus than it does in the EVM. But the moment one takes that value and does anything with it, Stylus becomes much cheaper. Recall that a single EVM ADD instruction costs 3 gas, during which 150 WASM ADD instructions may run.

See also