Computing Transaction Gas
Aptos transactions by default charge a base gas fee, regardless of market conditions.
For each transaction, this "base gas" amount is based on three conditions:
- Instructions.
- Storage.
- Payload.
The more function calls, branching conditional statements, etc. that a transaction requires, the more instruction gas it will cost.
Likewise, the more reads from and writes into global storage that a transaction requires, the more storage gas it will cost.
Finally, the more bytes in a transaction payload, the more it will cost.
As explained in the optimization principles section, storage gas has by far the largest effect on base gas. For background on the Aptos gas model, see The Making of the Aptos Gas Schedule.
Instruction gas​
Basic instruction gas parameters are defined at instr.rs
and include the following instruction types:
No-operation​
Parameter | Meaning |
---|
nop | A no-operation |
Control flow​
Parameter | Meaning |
---|
ret | Return |
abort | Abort |
br_true | Execute conditional true branch |
br_false | Execute conditional false branch |
branch | Branch |
Parameter | Meaning |
---|
pop | Pop from stack |
ld_u8 | Load a u8 |
ld_u16 | Load a u16 |
ld_u32 | Load a u32 |
ld_u64 | Load a u64 |
ld_u128 | Load a u128 |
ld_256 | Load a u256 |
ld_true | Load a true |
ld_false | Load a false |
ld_const_base | Base cost to load a constant |
ld_const_per_byte | Per-byte cost to load a constant |
Local scope​
Parameter | Meaning |
---|
imm_borrow_loc | Immutably borrow |
mut_borrow_loc | Mutably borrow |
imm_borrow_field | Immutably borrow a field |
mut_borrow_field | Mutably borrow a field |
imm_borrow_field_generic | |
mut_borrow_field_generic | |
copy_loc_base | Base cost to copy |
copy_loc_per_abs_val_unit | |
move_loc_base | Move |
st_loc_base | |
Calling​
Parameter | Meaning |
---|
call_base | Base cost for a function call |
call_per_arg | Cost per function argument |
call_per_local | Cost per local argument |
call_generic_base | |
call_generic_per_ty_arg | Cost per type argument |
call_generic_per_arg | |
call_generic_per_local | Cost generic per local argument |
Structs​
Parameter | Meaning |
---|
pack_base | Base cost to pack a struct |
pack_per_field | Cost to pack a struct , per field |
pack_generic_base | |
pack_generic_per_field | |
unpack_base | Base cost to unpack a struct |
unpack_per_field | Cost to unpack a struct , per field |
unpack_generic_base | |
unpack_generic_per_field | |
References​
Parameter | Meaning |
---|
read_ref_base | Base cost to read from a reference |
read_ref_per_abs_val_unit | |
write_ref_base | Base cost to write to a reference |
freeze_ref | Freeze a reference |
Casting​
Parameter | Meaning |
---|
cast_u8 | Cast to a u8 |
cast_u16 | Cast to a u16 |
cast_u32 | Cast to a u32 |
cast_u64 | Cast to a u64 |
cast_u128 | Cast to a u128 |
cast_u256 | Cast to a u256 |
Arithmetic​
Parameter | Meaning |
---|
add | Add |
sub | Subtract |
mul | Multiply |
mod_ | Modulo |
div | Divide |
Bitwise​
Parameter | Meaning |
---|
bit_or | OR : | |
bit_and | AND : & |
xor | XOR : ^ |
shl | Shift left: << |
shr | Shift right: >> |
Boolean​
Parameter | Meaning |
---|
or | OR : || |
and | AND : && |
not | NOT : ! |
Comparison​
Parameter | Meaning |
---|
lt | Less than: < |
gt | Greater than: > |
le | Less than or equal to: <= |
ge | Greater than or equal to: >= |
eq_base | Base equality cost: == |
eq_per_abs_val_unit | |
neq_base | Base not equal cost: != |
neq_per_abs_val_unit | |
Global storage