ERGO

Just-In-Time Costing (JITC)

Introduction

Discussions about transaction efficiency, scalability, and costing are common in the cryptocurrency space. For a blockchain technology to achieve long-term viability and widespread adoption, adaptability and scalability are crucial. Ergo's Protocol Reference Client 5.0.0 introduced significant advancements, offering substantial benefits to miners, developers, and users across the ecosystem, particularly regarding script execution costing.

Key Concepts

Scalability refers to a blockchain's capacity to handle an increasing number of transactions. As a platform grows, transaction volume typically increases. Without effective scaling mechanisms, the network can become congested, leading to longer confirmation times.

Costing refers to the computational expense associated with validating transactions and smart contracts. In Proof-of-Work blockchains like Ergo, every transaction incurs a fee, partly determined by its computational cost.

Historical Context

Historically, this cost has been estimated using either Ahead-of-Time (AOT) or Just-In-Time (JIT) methods. Until version 5.0.0, Ergo primarily used AOT costing, which estimates costs before script execution to prevent excessively resource-intensive scripts from overwhelming the network.

Ahead-of-Time (AOT)

  • Costs estimated before script execution
  • Prevents resource-intensive scripts
  • Used in Ergo before v5.0.0
  • Conservative approach

Just-In-Time (JIT)

  • Costs calculated during execution
  • More accurate cost measurement
  • Introduced in Ergo v5.0.0
  • Efficient approach

Ergo Protocol Reference Client 5.0.0 and Hybrid Costing

The release of Reference Client 5.0.0 introduced several network improvements, including a more efficient hybrid costing model (EIP-39). This enhances the network's user experience (UX) by allowing more efficient transaction processing within blocks, benefiting miners, developers, and users.

As mentioned, Ergo previously relied mainly on AOT costing. Reference Client 5.0.0 introduced a hybrid model combining AOT and JIT costing. For a detailed explanation, refer to the blog post: "Ergo's Hybrid Method for Counting Costs".

Two-Stage Validation Process

The hybrid costing model operates in two stages during transaction validation:

1

Reduction Stage (JIT Costing)

Each input's guarding script (ErgoTree) is reduced to its final sigma proposition (a cryptographic condition like proveDlog(pk) or atLeast(2, Coll(pk1, pk2, pk3))). The cost of this reduction phase is calculated using Just-In-Time (JIT) costing, meaning the cost is determined based on the actual operations performed during reduction.

2

Cryptographic Verification Stage (AOT Costing)

Once all input scripts are reduced to sigma propositions, the cost of verifying the required cryptographic proofs (e.g., signature checks) is calculated using Ahead-of-Time (AOT) costing. AOT costing for crypto operations is simple, fast, and predictable.

Cost Aggregation and Block Validation

The costs from both stages are aggregated to determine the final cost of the transaction. This transaction cost is then added to the cumulative cost of the block being validated. A block is only valid if its total accumulated cost remains within the maximum allowed block budget.

Security Benefits

Cryptographic operations are significantly more resource-intensive than reduction operations, typically consuming around 80% of the verification time. Using AOT costing for the cryptographic stage ensures that denial-of-service attacks based on expensive crypto operations remain infeasible.

The JIT costing applied during the reduction stage provides a more accurate measure of the actual computational work performed during script execution.

Benefits of Hybrid Costing

This two-part costing method enables more efficient and accurate cost estimation compared to relying solely on AOT costing.

For Users

  • Potentially faster script execution times
  • More accurate cost reflection
  • Better transaction throughput
  • Improved user experience

For Developers

  • More efficient block space utilization
  • Better cost predictability
  • Enhanced script optimization
  • Improved network scalability

Network Impact

As a result of these improvements in Reference Client 5.0.0, users and developers benefit from potentially faster script execution times (as costs more accurately reflect actual work) and more efficient utilization of block space. This allows blocks to potentially accommodate more transactions, thereby increasing network throughput.

Technical Implementation

JIT Costing Process

  1. Script reduction to sigma propositions
  2. Real-time cost calculation
  3. Actual operation measurement
  4. Accurate cost reflection

AOT Costing Process

  1. Cryptographic proof verification
  2. Pre-calculated cost estimation
  3. Security-focused approach
  4. DoS attack prevention

Key Features Summary

Efficiency

More accurate cost estimation leads to better resource utilization and improved transaction throughput.

Security

AOT costing for cryptographic operations prevents DoS attacks while maintaining network security.

Scalability

Hybrid approach allows blocks to accommodate more transactions, increasing overall network capacity.