Input Format Guide
A practical guide to formatting inputs for Bonsol ZK programs, covering common pitfalls and working solutions for different input scenarios.
Overview
When creating execution requests for Bonsol ZK programs, proper input formatting is crucial for successful execution. This guide covers the practical aspects of formatting inputs that work with your ZK program's expectations.
Understanding Input Format Mismatch
One of the most common issues developers face is input format mismatch between:
The manifest file's
inputOrderspecificationThe execution request JSON format
What the ZK program actually expects to read
Common Error: InputError (0x3)
If you encounter custom program error: 0x3 during execution, this indicates an InputError. Common causes include:
Wrong byte count: ZK program expects 8-byte arrays but receives different sizes
Wrong input count: Manifest specifies 1 input but you're sending multiple inputs
String vs. byte mismatch: Sending string data when ZK program expects binary data
Working Input Formats
Single Combined Byte Input
Best Practice: When your ZK program reads multiple values using env::read_slice(), combine all values into a single input.
Example: Calculator program that reads 3 i64 values
Corresponding Rust client code:
Manifest alignment:
String Inputs (Limited Support)
Caution: String inputs may work for transaction submission but fail during ZK execution.
What doesn't work:
Why it fails: The ZK program expects 8-byte arrays, but strings produce variable-length byte arrays.
Debugging Input Issues
Enable Debug Output
Add debug printing to your client to understand exactly what's being sent:
Check Transaction vs. Execution
Transaction success + execution failure: Input format accepted by Bonsol but incompatible with ZK program
Transaction failure: Input format rejected by Bonsol interface
Monitor Bonsol Logs
Watch for these error patterns in the prover logs:
Best Practices
1. Align with ZK Program Expectations
Do: Format inputs to match exactly what your ZK program reads
2. Use Single Combined Inputs
Do: When reading multiple values sequentially, combine them into one input
Don't: Send separate inputs when ZK program expects sequential reads from one input
3. Match Manifest Input Count
Ensure your inputOrder in the manifest matches your actual input usage:
4. Test with Known Working Formats
Start with the byte format that matches your ZK program's expectations, then experiment with convenience formats.
Example: Working Calculator Client
This example shows a complete working implementation:
Result: ✅ Transaction succeeds + ZK execution succeeds
Troubleshooting Checklist
Further Reading
Bonsol Input Types - Overview of available input types
Tutorial: Simple Program - Complete example with JSON inputs
CLI Commands - Bonsol CLI reference
Last updated