Skip to content

Commit

Permalink
cairo-vm output array reqirement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed May 26, 2024
1 parent 456f686 commit 84639c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
use_poseidon=use_poseidon,
);

let output = cast(builtin_ptrs.output - Output.SIZE, Output*);
let output = cast(builtin_ptrs.output - Output.SIZE - Input.SIZE - 1, Output*);
%{
print(ids.output.a_2)
print(ids.output.b_2)
Expand Down
3 changes: 3 additions & 0 deletions cairo1/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[cairo]
enable-gas = false

[dependencies]
15 changes: 7 additions & 8 deletions cairo1/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ struct Input {
c: u32,
}

#[derive(Drop, Serde)]
struct Output {
a_2: u32,
b_2: u32,
c_2: u32,
}

fn main(input: Array<felt252>) -> Output {
fn main(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');
assert(a_2 + b_2 == c_2, 'invalid value');

Output {
a_2,
b_2,
c_2,
}
}
let mut output = array![];
Output { a_2, b_2, c_2, }.serialize(ref output);
output
}

0 comments on commit 84639c7

Please sign in to comment.