Skip to content

CORE 1557: Implement svm contract for on chain quotes#28

Open
bengtlofgren wants to merge 22 commits intomainfrom
bengt/CORE-1557
Open

CORE 1557: Implement svm contract for on chain quotes#28
bengtlofgren wants to merge 22 commits intomainfrom
bengt/CORE-1557

Conversation

@bengtlofgren
Copy link
Contributor

@bengtlofgren bengtlofgren commented Dec 3, 2025

Core-1557 ++

Note

Svm implementation of ExecutorQuoter - specifically the estimate_quote part. It borrows u256 math from orca's implementation, which is reportedly 5x cheaper than parity's implementation (used in many projects under various crate names).

Description

This PR implements the SVM (Solana) on-chain quoting functionality for the Executor system. It introduces ExecutorQuoter and ExecutorQuoterRouter programs using Pinocchio for minimal compute unit overhead, enabling integrators to obtain quotes and request executions entirely on-chain without requiring off-chain quote fetching.

Major Changes

SVM Implementation (Pinocchio)

  • executor-quoter program: Low-level Pinocchio-based program with:
    • no_std implementation for minimal compute unit usage
    • Orca U256 math implementation for price calculations
    • PDA-based state storage for ChainInfo and QuoteBody
    • Build-time configuration via environment variables for updater/payee addresses
    • Instructions: UpdateChainInfo, UpdateQuote, RequestQuote, RequestExecutionQuote
  • executor-quoter-router program: Router program providing:
    • UpdateQuoterContract: Registers quoters via secp256k1 signature verification
    • QuoteExecution: CPI-based quote retrieval
    • RequestExecution: Full execution flow with payment verification
  • Comprehensive Rust integration tests with Mollusk-SVM for compute unit benchmarking
  • TypeScript devnet tests in tests/executor-quoters.test.ts

Project Structure Changes

  • Reorganized SVM directory: moved Anchor project to svm/anchor/
  • Added new svm/pinocchio/ directory for low-level Solana programs
  • Added svm/modules/executor-requests/ for shared request serialization logic
  • Updated CI workflow for SVM to handle new project structure

Documentation

  • Updated design/02_On_Chain_Quotes.md with SVM implementation details

Files Modified

SVM Programs

  • svm/pinocchio/programs/executor-quoter/ - Quoter program (lib.rs, state.rs, error.rs, math/, instructions/)
  • svm/pinocchio/programs/executor-quoter-router/ - Router program (lib.rs, state.rs, error.rs, instructions/)

** SVM Tests**

  • svm/pinocchio/tests/executor-quoter-tests/ - Integration tests and benchmarks
  • svm/pinocchio/tests/executor-quoter-router-tests/ - Integration tests and benchmarks

** Shared Module**

  • svm/modules/executor-requests/ - Shared serialization module

SVM Configuration

  • svm/anchor/Anchor.toml - Moved from root svm/
  • svm/anchor/Cargo.toml - Moved from root svm/
  • svm/pinocchio/Cargo.toml - New workspace configuration
  • svm/pinocchio/README.md - Documentation for Pinocchio programs
  • svm/tests/executor-quoters.test.ts - TypeScript devnet tests

CI/Configuration

  • .github/workflows/svm.yml - Updated for new directory structure, added Pinocchio test job
  • .gitignore - Added SVM build artifacts
  • .prettierignore - Added SVM paths
  • cspell.json - Updated dictionary path
  • .cspell/custom-dictionary.txt - Added new terms
  • svm/rust-toolchain.toml - Updated Rust toolchain version

Additional Notes

  • The SVM implementation uses Pinocchio for minimal compute unit overhead, critical for Solana's resource constraints
  • Quoters are identified by their 20-byte EVM address (derived from secp256k1 public key) for cross-chain consistency
  • The EQ02 quote format is used for on-chain quote bodies
  • Governance messages include EG01 prefix with sender address verification for quoter registration
  • Devnet testing validates the full flow including Sepolia chain configuration

Todo list before opening up for review

  • delete the comparison programs - pinnochio clearly won this fight
  • finish the svm/TODO.md
  • figure out idl strategy
  • Fix the prettier test and ask if we can update the github workflow to use a modern version of rust ..

@bengtlofgren bengtlofgren marked this pull request as draft December 3, 2025 20:33
@bengtlofgren bengtlofgren changed the title Bengt/core 1557 CORE 1557: Implement svm math for estimate_quote Dec 3, 2025
@bengtlofgren bengtlofgren changed the base branch from main to bengt/adding-tests December 3, 2025 20:34
@bengtlofgren
Copy link
Contributor Author

Running scripts/compare-cu.sh gives you the CU savings across program implementations

Stopping any existing validator...
Starting validator...
Waiting for validator to start...
Waiting for fees to stabilize 1...
Waiting for fees to stabilize 2...
Waiting for fees to stabilize 3...
Running comparison tests...

=== Gas Comparison (Compute Units) ===
| Instruction            | Anchor CU | Pinocchio CU | Difference | Savings % |
|------------------------|-----------|--------------|------------|-----------|
| initialize             |     11819 |         3386 |       8433 |     71.4% |
| updateChainInfo        |     10285 |         1986 |       8299 |     80.7% |
| updateQuote            |     14867 |         1995 |      12872 |     86.6% |
| requestQuote           |     10971 |         4003 |       6968 |     63.5% |
| requestExecutionQuote  |     10993 |         4049 |       6944 |     63.2% |
=== Binary Size Comparison ===
| Program    | Size (bytes) |
|------------|--------------|
| Anchor     |       277600 |
| Pinocchio  |        56176 |
| Difference |       221424 |
| Savings    |        79.8% |

I also switched to the ethereum_types_solana and got the following results:

U256 Implementation Compute Unit Comparison

  | Instruction           | Anchor    | Pinocchio + primitive-types | Pinocchio + Custom U256 |
  |-----------------------|-----------|-----------------------------|-------------------------|
  | requestQuote          | 10,971 CU | 13,719 CU                   | 4,003 CU                |
  | requestExecutionQuote | 10,993 CU | 13,765 CU                   | 4,049 CU                |

@bengtlofgren
Copy link
Contributor Author

Compute Units Comparison

Instruction Anchor CU Native CU Pinocchio CU Pino vs Anchor Pino vs Native
initialize 11,819 5,708 3,386 71.4% savings 40.7% savings
updateChainInfo 10,285 4,754 1,986 80.7% savings 58.2% savings
updateQuote 14,867 4,765 1,995 86.6% savings 58.1% savings
requestQuote 10,971 4,806 4,003 63.5% savings 16.7% savings
requestExecutionQuote 10,993 4,863 4,049 63.2% savings 16.7% savings

Binary Size Comparison

Program Size (bytes) vs Pinocchio
Anchor 277,728 5.32x larger
Native 113,504 2.17x larger
Pinocchio 52,224 baseline

@socket-security
Copy link

socket-security bot commented Dec 5, 2025

@bengtlofgren
Copy link
Contributor Author

Current benchmarks:

executor-quoter:

Instruction CU
update_chain_info (create) 4,899
update_chain_info (update) 226
update_quote (create) 3,397
update_quote (update) 229
request_quote (250k gas) 4,203
request_quote (500k gas + 1ETH) 4,966
request_execution_quote 4,240

executor-quoter-router:

Instruction CU
update_quoter_contract (create) 30,546
update_quoter_contract (update) 25,880

@bengtlofgren bengtlofgren force-pushed the bengt/adding-tests branch 2 times, most recently from 89cae71 to e5eb2eb Compare December 12, 2025 16:53
Base automatically changed from bengt/adding-tests to main December 12, 2025 17:04
@bengtlofgren bengtlofgren changed the title CORE 1557: Implement svm math for estimate_quote CORE 1557: Implement svm contract for on chain quotes Dec 17, 2025
@bengtlofgren bengtlofgren marked this pull request as ready for review December 17, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants