Skip to main content

Introduction

This document provides a comprehensive reference for all metering points in Cowboy’s dual-gas system. Use this as a lookup table to understand exactly when and how much resources are consumed.
Consensus-Critical: All metering rules in this document are part of the consensus protocol. Any deviation will cause state forks.
Note: Names and code snippets shown here are conceptual and illustrative. The normative content is the metering points and costs (per CIP-3). Final SDK interfaces and naming may differ; always refer to the SDK and Developer Guide for usage.

Cycle Metering Points

Cycles are charged before each operation executes. If insufficient cycles remain, execution halts immediately.

Python Bytecode Operations

Operation TypeCycles Cost
Python Arithmetic Ops (+, -, *, /, %)1
Python Function Call10
Dictionary Get/Set3
List Append/Access2
String Operation (per character)1
Dynamic surcharges apply based on operand types and sizes (see Dynamic Typing Surcharges).

Host Function Categories (CIP-backed)

CategoryExample Costs (Cycles)Notes
Storage I/ORead: 10, Write: 50Cells charged by bytes moved
MessagingSend: 80Payload Cells metered separately
Timers (CIP‑1)Set/Cancel: 200/50Execution under block timer budget
CryptographyECDSA: 3,000; BLS: 8,000; Hash/32B: ~6Deterministic implementations
BlobsCommit per KiB: 40Content‑addressed data
ImportsFirst: 100 (+init), Cached: 5, Disallowed: 50Whitelist enforced

Built-in Functions (Selected, CIP-backed)

FunctionCycles (base)Notes
len(obj)5O(1) table lookup
sorted(iterable)20 + n×log₂(n)Size-dependent
sum(iterable)10 + (n−1)Plus element type costs
max/min(iterable)10 + (n−1)Plus comparison costs
str(obj)10 + len(result)Serialized size dependent
bytes(iterable)10 + nNumber of bytes
list(iterable)10 + n×2Element count based
set(iterable)15 + n×5Hashing cost included
dict(iterable)15 + n×8Pair count based

Dynamic Typing Surcharges

Operations have base cost + dynamic surcharge based on runtime types:
OperationBaseSurchargeExample
str + str1len(left) + len(right)"hello" + "world" = 11 cycles
str * int1len(str) × multiplier"ab" * 100 = 201 cycles
str == str1min(len(left), len(right))"abc" == "abd" = 4 cycles
str[i]20Constant time
str[i:j]2j - iProportional to slice

Exception Handling

OperationCyclesDescription
Enter try block5Set up exception handler
raise Exception()30Create and throw exception
Enter except block10Exception type matching
Enter finally block5Cleanup execution
Exception propagation8 per frameStack unwinding
Uncaught exception20Top-level error handling

Module Imports

OperationCyclesNotes
First import (whitelisted)100 + init_costLoad + execute module init
Cached import5From in-transaction cache
Failed import (not whitelisted)50Penalty cost + ImportError
Import alias (as)2Namespace binding

Cell Metering Points

Cells are charged at specific I/O boundaries, not on every instruction.

Transaction Intrinsic

When: Before VM execution begins
What: Transaction payload size
Charged immediately upon transaction submission based on payload size.

Memory Allocation

When: Object creation
What: Allocated memory size
Object TypeCells Cost (bytes)Notes
int (small −5..256)0Pre‑allocated
int (large)8 + ⌈bitlen/8⌉Header + value storage
float16Header + 8‑byte double
bool0Singleton
str24 + len(s)UTF‑8 bytes
list40 + 8×capacityHeader + pointer array
dict64 + 16×bucketsHeader + hash table
tuple24 + 8×lenFixed pointer array
set64 + 16×bucketsSimilar to dict

Quick Reference (Selected)

OperationCycles
Integer addition1
Function call10
Storage read10
Storage write50
Message send80
Set timer200
ECDSA verify3,000