Abstract:
This post provides a deep dive into recent Bonsol framework improvements aimed at revolutionizing verifiable compute on Solana. Key enhancements include a new I Ching sample dApp demonstrating end-to-end ZK application flow, comprehensive RISC0_DEV_MODE
integration for a faster development lifecycle, and custom S3 URL support for greater artifact management flexibility.
Estimated reading time: 7 minutes
The Bonsol framework aims to unlock the next generation of decentralized applications on Solana by making complex, off-chain computations verifiable. Recent contributions, primarily during the first half of March 2025, have significantly advanced this mission, making the platform more robust, developer-friendly, and versatile. This work was highlighted in a collaboration announcement by Bonsol Labs. This post dives into three pivotal improvements: the creation of an illustrative I Ching sample program, the integration of RISC0_DEV_MODE
for a streamlined development lifecycle, and the added flexibility of custom S3 URL support for program artifacts.
Further details and the specific code contributions can be explored on GitHub: Bonsol - I Ching Sample Feature Branch
1. The I Ching Oracle: A Tangible Showcase of Verifiable Off-Chain Compute
To demonstrate Bonsol’s practical power, a sophisticated I Ching (Book of Changes) oracle sample program was developed. This isn’t just a toy example; it showcases a complete end-to-end workflow of a zero-knowledge powered application on Solana.
Core Components & Innovations:
-
Guest Program (RISC0 zkVM):
- Secure Pseudo-Randomness: The guest program meticulously generates pseudo-random numbers within the ZK environment to simulate the traditional yarrow stalk or coin toss method for determining I Ching hexagram lines. This ensures that while the outcome is deterministic given an input seed, it’s unpredictable without it.
- Probabilistic Accuracy: It correctly implements the specific probabilities for each type of line (Old Yin, Young Yin, Old Yang, Young Yang), crucial for an authentic I Ching reading.
- Rich, Structured Output: The program doesn’t just output raw data. It generates a well-defined byte array containing:
- The SHA256 digest of the initial input seed (32 bytes).
- A marker byte (
0xAA
) for integrity checking. - The six numerical values representing the hexagram lines (6 bytes).
- A human-readable ASCII art representation of the hexagram (47 bytes, with each of the 6 lines being exactly 7 characters wide).
- Comprehensive Logging & Dev Mode Awareness: Includes detailed logging for easier debugging and is aware of
RISC0_DEV_MODE
for faster test cycles.
-
Callback Program (Solana On-Chain):
- Persistent Storage: A Solana program was created to receive the ZK-proven output from the guest. It utilizes Program Derived Addresses (PDAs) to create unique storage accounts for each generated hexagram reading, associated with the requester’s public key and an execution ID.
- Data Structuring & Validation: The callback program expects the specific output format from the guest. It parses this data and stores it in a structured way on-chain (
HexagramData
struct: lines, ASCII art, timestamp, initialization flag). It performs essential validation, including checking the marker byte and expected data lengths. - Timestamping & Initialization Logic: Each stored reading is timestamped, and an
is_initialized
flag prevents accidental overwrites or misuse of uninitialized accounts.
Significance: The I Ching sample program serves as a powerful blueprint. It demonstrates how developers can:
- Execute complex, stateful logic off-chain within a RISC0 ZK environment.
- Generate rich, structured, and verifiable outputs.
- Seamlessly integrate these ZK computations with Solana on-chain programs for persistent storage and dApp interaction.
- Handle non-trivial data like ASCII art, proving that ZK outputs can be more than just simple numerical results.
2. Supercharging Developer Workflow with RISC0_DEV_MODE
One of the significant hurdles in ZK development can be the time taken for full proof generation. To address this and dramatically improve the developer experience, comprehensive support for RISC0_DEV_MODE
was integrated throughout the Bonsol workflow.
Implementation Highlights:
- Environment-Wide Detection: The
RISC0_DEV_MODE=1
environment variable is now consistently detected across guest programs, host-side CLI tools, and SDK interactions usingoption_env!("RISC0_DEV_MODE").is_some()
. - Conditional Proof Generation:
- In guest programs, this allows for specific logging or behavior tailored to development.
- Crucially, for the host/prover side, when
RISC0_DEV_MODE
is active, the system bypasses the computationally intensive real proof generation. Instead, it typically relies on mock proofs or direct execution of the guest without proving, while still emulating the rest of the workflow.
- Script & Tooling Integration: Build scripts (
01-build.sh
), deployment scripts (02-deploy.sh
), and execution scripts (04-execute.sh
) were updated to recognize and utilizeRISC0_DEV_MODE
. This ensures that developers can easily switch between fast iteration in dev mode and full proving for production or staging. - Client-Side Handling: SDK components, such as
get_execution_request_v1
, were refined to correctly interpret outcomes in dev mode. For instance, anExitCode::ProvingError
from the RISC0 runtime (which can occur if a real proof is skipped) is correctly treated as a successful execution path whenRISC0_DEV_MODE
is active.
Impact on Developer Experience:
- Rapid Iteration: Developers can now test their guest program logic, input/output handling, and integration with callback programs in seconds or minutes, rather than waiting for potentially lengthy proof generation times.
- Reduced Costs: During the development phase, this avoids the computational costs associated with running ZK provers repeatedly.
- Simplified Debugging: It’s easier to isolate issues. Bugs in the guest logic can be identified and fixed quickly without the added complexity of the proving system. Once the core logic is sound, developers can then switch to full proving mode.
- Lower Barrier to Entry: This makes Bonsol and ZK development more accessible, especially for those new to the field, as they can achieve results and test their ideas much faster.
3. Enhanced Flexibility: Support for Custom S3 URLs
To provide users with greater control over their artifacts and integrate more smoothly with existing infrastructure, Bonsol was enhanced to support custom S3 URLs.
Functionality & Benefits:
- User-Defined Storage: Developers can now specify their own S3 bucket names, URLs, or prefixes for storing and retrieving critical artifacts, particularly the compiled RISC-V ELF files (guest programs). This was likely achieved by adding configuration options to
Bonsol.toml
, CLI flags, or SDK parameters. - Greater Control & Data Sovereignty: Users are no longer tied to a default S3 structure. They can manage their guest program binaries within their own S3 infrastructure, aligning with their organization’s security, access control, and data retention policies.
- Cost Management: Leveraging existing S3 buckets and configurations allows users to potentially optimize storage costs based on their AWS agreements and chosen storage classes.
- Seamless CI/CD Integration: This feature facilitates easier integration with existing CI/CD pipelines or asset management systems that are already configured to work with specific S3 locations. Deployment scripts and client-side logic were updated to respect these custom URLs.
Significance: This enhancement moves Bonsol towards a more enterprise-ready and customizable solution, recognizing that different users and organizations have varied operational requirements for managing their compiled assets.
In conclusion, these collective improvements—the illustrative I Ching dApp, the transformative RISC0_DEV_MODE
, and the flexible custom S3 URL support—mark significant strides for Bonsol. They not only showcase the framework’s expanding capabilities for verifiable compute on Solana but also underscore a commitment to providing a powerful, efficient, and developer-centric platform. This work paves the way for more complex and innovative decentralized applications to be built on Solana, leveraging the combined power of on-chain execution and verifiable off-chain computation.