Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jun 5, 2024
1 parent 0715655 commit e2fe775
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 72 deletions.
54 changes: 18 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,32 @@ To set up the project environment and run the bootloader, follow these steps:

4. **Running the Bootloader**: Start the bootloader with `python run.py`, which will load and execute the compiled Cairo1 contract within the Cairo0 environment.

5. **Preparing bootloader_input.json (Optional)**:
- Run `Scarb build` in the contract folder.
- Use `starknet-sierra-compile INPUT OUTPUT --add-pythonic-hints`.
- Add a return footer at the end of the contract's bytecode (increase the bytecode segment size by one).
- Supply `bootloader_input.json` with new contract sierra class json.

---

This example showcases merge of Cairo0 host provable environment and a Cairo1 developer frendly language:

```cairo
#[starknet::interface]
pub trait IHelloBootloader<TContractState> {
fn main(ref self: TContractState, input: Array<felt252>) -> Array<felt252>;
}
#[starknet::contract]
mod HelloBootloader {
#[derive(Drop, Serde)]
struct Input {
a: u32,
b: u32,
c: u32,
}
#[derive(Drop, Serde)]
struct Output {
a_2: u32,
b_2: u32,
c_2: u32,
}
mod Factorial {
use starknet::{ContractAddress, SyscallResult, SyscallResultTraitImpl};
use starknet::syscalls::call_contract_syscall;
#[storage]
struct Storage {}
#[abi(embed_v0)]
impl HelloBootloaderImpl of super::IHelloBootloader<ContractState> {
fn main(ref self: ContractState, input: Array<felt252>) -> Array<felt252> {
let mut input_span = input.span();
let input = Serde::<Input>::deserialize(ref input_span).unwrap();
let a_2 = input.a * input.a;
let b_2 = input.b * input.b;
let c_2 = input.c * input.c;
assert(a_2 + b_2 == c_2, 'invalid value');
let mut output = array![];
Output { a_2, b_2, c_2, }.serialize(ref output);
output
}
struct Storage{}
#[external(v0)]
fn main(ref self: ContractState, address: ContractAddress) -> Span<felt252> {
// call_contract_syscall is modified POC syscall to just return calldata it received
let value: Span<felt252> = call_contract_syscall(
address, 0x1, array![0xa, 0xb, 0xc, 0xe].span(),
).unwrap_syscall();
value
}
}
```
Expand Down
48 changes: 12 additions & 36 deletions contract/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
#[starknet::interface]
pub trait IHelloBootloader<TContractState> {
fn main(ref self: TContractState, input: Array<felt252>) -> Array<felt252>;
}

#[starknet::contract]
mod HelloBootloader {
#[derive(Drop, Serde)]
struct Input {
a: u32,
b: u32,
c: u32,
}

#[derive(Drop, Serde)]
struct Output {
a_2: u32,
b_2: u32,
c_2: u32,
}
mod Factorial {
use starknet::{ContractAddress, SyscallResult, SyscallResultTrait};
use starknet::syscalls::call_contract_syscall;

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl HelloBootloaderImpl of super::IHelloBootloader<ContractState> {
fn main(ref self: ContractState, input: Array<felt252>) -> Array<felt252> {
let mut input_span = input.span();
let input = Serde::<Input>::deserialize(ref input_span).unwrap();

let a_2 = input.a * input.a;
let b_2 = input.b * input.b;
let c_2 = input.c * input.c;
assert(a_2 + b_2 == c_2, 'invalid value');
struct Storage{}

let mut output = array![];
Output { a_2, b_2, c_2, }.serialize(ref output);
output
}
#[external(v0)]
fn main(ref self: ContractState, address: ContractAddress) -> Span<felt252> {
// call_contract_syscall is modified POC syscall to just return calldata it received
let value: Span<felt252> = call_contract_syscall(
address, 0x1, array![0xa, 0xb, 0xc, 0xe].span(),
).unwrap_syscall();
value
}
}
}

0 comments on commit e2fe775

Please sign in to comment.