This project is an arithmetic circuit compiler written in Rust, for educational purposes only. It parses arithmetic expressions, builds a corresponding circuit, evaluates the circuit with given inputs, and generates Solidity smart contract code to verify the circuit.
- Parse arithmetic expressions.
- Build arithmetic circuits from parsed expressions.
- Evaluate circuits with given input values.
- Generate Solidity smart contract code for circuit verification.
- nom for parsing arithmetic expressions.
- Rust programming language and Cargo.
Clone the repository:
git clone https://github.com/luishsr/rust-arith-circuit.git
cd rust-arith-circuit
To build the project, run:
cargo build
To run the project, use:
cargo run
This will parse the expression x + y, evaluate it with x = 2 and y = 5, and generate the corresponding Solidity smart contract.
Example Output The expected output should be:
Result: 7
pragma solidity ^0.8.0;
contract ArithmeticCircuit {
function verify(int256[] memory x, int256[] memory y) public pure returns (int256) {
return x[0] + y[1];
}
}
src/main.rs: Entry point of the application. src/circuit.rs: Contains the definition of the arithmetic circuit, parsing logic, evaluation, and Solidity code generation.
Modify the expression in main.rs to your desired arithmetic expression. Run the project to see the evaluated result and generated Solidity code.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details.