-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode.cairo
More file actions
57 lines (46 loc) · 1.62 KB
/
node.cairo
File metadata and controls
57 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%builtins output pedersen range_check bitwise poseidon
from objects import NodeClaim, NodeResult, ApplicativeResult, applicative_result_serialize
from starkware.cairo.common.memcpy import memcpy
from starkware.cairo.common.registers import get_fp_and_pc
func main{
output_ptr: felt*,
pedersen_ptr: felt*,
range_check_ptr: felt*,
bitwise_ptr: felt*,
poseidon_ptr: felt*,
}() {
alloc_locals;
let (__fp__, _) = get_fp_and_pc();
local fibonacci_claim: NodeClaim*;
%{
from objects import NodeClaim
ids.fibonacci_claim = segments.gen_arg(vars(NodeClaim.Schema().load(program_input)).values())
%}
let (a_end, b_end) = fib(fibonacci_claim.a_start, fibonacci_claim.b_start, fibonacci_claim.n);
local node_result: NodeResult = NodeResult(
a_start=fibonacci_claim.a_start,
b_start=fibonacci_claim.b_start,
n=fibonacci_claim.n,
a_end=a_end,
b_end=b_end,
);
local applicative_result: ApplicativeResult = ApplicativeResult(
path_hash=0, node_result=&node_result
);
// Output the applicative result.
memcpy(
dst=output_ptr,
src=applicative_result_serialize(obj=&applicative_result),
len=ApplicativeResult.SIZE + NodeResult.SIZE - 1,
);
let output_ptr = &output_ptr[ApplicativeResult.SIZE + NodeResult.SIZE - 1];
return ();
}
func fib(first_element: felt, second_element: felt, n: felt) -> (felt, felt) {
if (n == 0) {
return (first_element, second_element);
}
return fib(
first_element=second_element, second_element=first_element + second_element, n=n - 1
);
}