On-Chain Execution Extension - Aspect Programming

May 14, 2024


ExEx - a framework for building off-chain infra as post-execution hooks.

Reth Execution Extensions(ExEx) are post-execution hooks for building off-chain infra. It can be used to implement high-performing and complex off-chain infra such as rollups, indexers, and MEV bots on Reth.

Motivated by the observation that Extract, Transform, Load (ETL) pattern also applied to off-chain infrastructure such as Ethereum indexers, rollups, MEV searchers, Paradigm and init4 team co-built Reth Execution Extensions (ExEx), aiming to be the ‘airflow’ for building Ethereum ETL infrastructure and job orchestration.

Execution Extensions (ExExes) are post-execution hooks for building real-time, high performance and zero-operations off-chain infrastructure on top of Reth.

According to Paradigm Research, ExEx is an off-chain module that derives its state from Reth's state. Developers can build reusable ExExes that compose with each other in a standardized way, similar to how Cosmos SDK modules or Substrate Pallets work. In the future, ExExes will be dynamically loaded from a ‘Docker Hub’ as plugins, making Reth the launchpad for performant off-chain infra.

Hook and extension improve the extensibility of infra

Infrastructure design cannot anticipate all user needs from the outset, making support for extensibility a crucial feature. This concept, known as infrastructure extensibility, allows platforms to accommodate user-defined functionality.

Blockchain extensibility refers to the ability to support user-defined functionality either through a built-in blockchain implementation or through extension mechanisms that allow developers to craft applications beyond the original intent of the platform.

Recent industry developments have demonstrated the power of hooks and extensions in enhancing extensibility.

  • Extending Off-Chain Nodes

    Reth's off-chain nodes needs extended functionality. Through ExEx, a standard node can be expanded to include indexers, MEV bots, and other customized services.

  • Extending On-Chain Application Protocols

    Uniswap's pool needs extended functionality. Through hooks, Uniswap evolves into a liquidity platform, allowing the standard pool to be extended for various purposes.

  • Extending On-Chain Base Layer

    • Arbitrum Nova introduces the concept of hooks, allowing Layer 2 to have customizable functionality.

    • Artela leverages hook and extension at L1 execution layer and enables VM-interoperability, allowing complex extensions to run on a separate, highly efficient VM.

On-Chain Extension - Aspect Programming

Artela has introduced a programmable module to function as the on-chain extension, named Aspect.

The name “Aspect” comes from “Aspect-oriented programming” — a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It is a technique for building common, reusable routines that can be applied applicationwide.

Aspect empowers developers to inject supplementary logic to process related transactions and blocks in the entire lifecycle of transactions and block processing.

Let's map to the ExEx's core idea:

  • High-performance runtime

    The Aspect runtime acts as a complementary ‘enhancement’ rather than a ‘replacement’ for the current EVM runtime. Its goal is to push the boundaries of EVM runtime capabilities beyond its original specification, while still maintaining EVM-equivalence. A dedicated WASM virtual machine serves as the execution environment for built-in Aspects. Developers to can choose their preferred programming languages in building on-chain ExEx.

  • Extension Hooks throughout the execution layer

    Aspect can be deployed and triggered to execute throughout the entire life cycle of transactions and block processing, with more context of transactions accessible than the smart contract.

  • Composable modular programs

    Aspect enables modular dApp building patterns for developers. DApps would no longer be a collection of tightly-knit codebases intertwined in complexity. Developers can build modular on-chain services by assembling the Lego of Aspects.

On Artela, we've developed a dedicated WASM runtime, named Aspect-Runtime, specifically for executing Aspects. The Aspect Runtime enables interactions between the Aspect and the core blockchain modules through a set of predefined host APIs. These APIs empower the Aspect with various abilities, such as reading the blockchain state, initiating calls to smart contracts, managing its own state, and more.

Aspect Programming Overview

The core principle of the Aspect Programming framework is the Join Point Model (JPM), which comprises three key components:

  • Join Point. This specifies where the Aspect can run. A join point represents a specific point in the transaction and block processing flow. It acts as a hook, allowing additional functional logic to be added at these points.

  • Aspect. This specifies the code to run on the join points. Aspects can access the runtime context and make system calls, enabling participation in transaction lifecycle management.

  • Binding. This specifies when the Aspect can run. Smart contract owners can bind Aspects to specific join points with their smart contracts. The bound Aspects are triggered when transaction processing steps reach these join points.

The Join Point serves as the hook point at the blockchain level, and allow users to infuse customized logic. Users can access specific contexts within each Join Point and employ system APIs to establish customized functionalities.

A simple example

1.  class SecurityAspect extends Aspect {
3.      @joinpoint
				/*serves as an entry, triggered once transaction execution completes*/
4.      postTxExecute(jpCtx: JPContext) {
				/***JPContext** represents the runtime context, containing original transaction context and APIs for interaction.*/
5.          if jpCtx.currentCall().methodName() == "withdraw" { // check whether "withdraw" of the smart contract is invoked
6.              let mintAmount = jpCtx.currentCall().params()[1];	// retrieve the expect minting amount from the transaction parameters		
7.              let actualVaultEtherFlow = jpCtx.stateChange(jpCtx.tx.to()).ether().diff(); // retrieve the actual funds flow of the vault from the runtime context
9.              if (amount !=  actualVaultEtherFlow) { // if the actual funds’ flow does not match the mint amount, indicating a discrepancy potentially resulting from coding errors or a cyberattack
10.                jpCtx.txControl().revert(); // negating its execution
11.             }
12.         }
13.     }

The sample Aspect monitors and verifies any deposit changes in the vault. It is triggered post smart contract execution. If an unexpected fund flow occurs during runtime, the Aspect will revert the suspicious transaction.

Explore on-chain extensions built by community - Aspect Hub

Innovators have harnessed Aspect Programming to unlock groundbreaking on-chain extension use cases never been possible before. Below are some standout innovative cases and tools developed by the Artela community. For more innovations, visit Aspect Hub.

Use cases built by community

Runtime Protection Aspect

Runtime Protection Aspect can work seamlessly with your DeFi smart contract during runtime, analyzing real-time on-chain behavior to thwart potential attacks, including reentrancy attacks.

Github: https://github.com/artela-network/example/tree/main/curve_reentrance

Blog: https://artela.network/blog/eliminate-reentrancy-attacks-with-on-chain-runtime-protection

Session Key Aspect

Session-Key Aspect allows EoA to extend several sub-keys, standing in for EoA private key to sign a specific transaction. Session-Key Aspect is used to achieve ‘one-click trading’ for swaps.

KYT Aspect

The KYT(Know Your Transaction) Aspect offers on-chain real-time transaction security analysis capabilities for dApps, including detecting flash loan attacks, arbitrage, and money laundering. By integrating this Aspect, a dApp can tailor its security risk control strategy to enhance protection.

Github: KYTAspect

Demo: Presentation

Demo Video: KYT Demo Video

Pacman with AI-agent Aspect

Utilize Aspect as an on-chain coprocessor to realize a fully on-chain "Pac-Man". It implements an AI agent enabling automatic battles between players and ghosts on-chain, and demonstrates great playability. The Ai-agent battle module was originally implemented off-chain in Java.

Github: https://github.com/Artela-Community/pac-man-artela-aspect

Demo: https://artela.cellula.fun/

Demo Video: https://www.youtube.com/watch?v=TvCKMQw2hys

Throttle Aspect for Artela

Throttle Aspect is an on-chain middleware that enables contracts to limit the frequency of invocation. dApp can use it to limit the per-address claim frequency for airdrop or protect from DDoS.

Github: https://github.com/ShiningRay/artela-throttle-aspect

Demo Video: https://www.youtube.com/watch?v=BCwjtLo6UsQ


A decentralized AI model training platform based on Artela, which utilizes off-chain model training and Aspect for on-chain weight aggregation.

Github: https://github.com/onehumanbeing/linklearner

Demo: https://linklearner.vercel.app/

Demo Video: https://www.loom.com/share/65caa326a82a49d68f8a861a58081104?sid=d1a552e2-4ba8-42b6-89bf-7575173bc25e

Public goods built by community

Hardhat for Aspect

A hardhat plugin to help builders build Aspect and Solidity dApp easily with hardhat. With this plugin, developers can build, deploy, bind Aspects easily in automatic hardhat scripts.

Github: https://github.com/BuidlerHouse/artela-hardhat-plugin

Aspect Marketplace

Description: Aspect Marketplace is a react-based web application that enables users to connect their Ethereum wallets and manage Aspects, and bind Aspects using contract addresses and ABI files.

Github: https://github.com/srivatsav01/aspect-marketplace

Demo: aspect-alpha.vercel.app

Solide Aspect IDE

Solide is an IDE for Aspect and solidity development. It functions as a building hub for smart contracts and Aspect where developers can share with the open-source community.

Github: https://github.com/solide-project

Demo: https://solidewidget.azurewebsites.net/aspect

Demo Video: https://www.youtube.com/watch?v=gITlPUQWmVU&feature=youtu.be

What’s next for Aspect Programming?

Currently, Aspect Programming is a specialized framework designed for building on-chain services on the Artela blockchain.

We aim to evolve Aspect Programming into a universal framework, making it flexible enough to integrate into various blockchains and L2s for general on-chain execution extensions.

Since launching the testnet version of Aspect Programming, we have received tremendous feedback from the developer community. Over 200 developers are now actively building Aspects on Artela. This is just the beginning. We hope to revolutionize the way people think about constructing high-performance on-chain services.