From 224314fa641ac6f74de9ca530646bd3d668cb1a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira Date: Thu, 26 Dec 2024 13:22:03 -0300 Subject: [PATCH] Replaces decode_u32_le by pop_front_u32_le in the risc0_sample_app cairo contract --- .../fibonacci_sequencer/src/lib.cairo | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/contracts/risc0_sample_app/fibonacci_sequencer/src/lib.cairo b/src/contracts/risc0_sample_app/fibonacci_sequencer/src/lib.cairo index 0fc25e79..8fd14f05 100644 --- a/src/contracts/risc0_sample_app/fibonacci_sequencer/src/lib.cairo +++ b/src/contracts/risc0_sample_app/fibonacci_sequencer/src/lib.cairo @@ -38,10 +38,10 @@ mod FibonacciSequencer { assert(optional_journal != Option::None, 'Invalid proof'); // parses the public inputs and output from the journal - let journal = optional_journal.unwrap(); - let l = decode_u32_le(journal, 0); - let u = decode_u32_le(journal, 4); - let fib_n = decode_u32_le(journal, 8); + let mut journal = optional_journal.unwrap(); + let l = pop_front_u32_le(ref journal); + let u = pop_front_u32_le(ref journal); + let fib_n = pop_front_u32_le(ref journal); // performs the necessary state update check, updates the state, // and emits an event with the new fibnoacci number submitted @@ -57,11 +57,12 @@ mod FibonacciSequencer { } } - fn decode_u32_le(bytes: Span, i: usize) -> u32 { - let b0: u32 = (*bytes[i]).into(); - let b1: u32 = (*bytes[i + 1]).into(); - let b2: u32 = (*bytes[i + 2]).into(); - let b3: u32 = (*bytes[i + 3]).into(); + fn pop_front_u32_le(ref bytes: Span) -> u32 { + let [b0, b1, b2, b3] = (*bytes.multi_pop_front::<4>().unwrap()).unbox(); + let b0: u32 = b0.into(); + let b1: u32 = b1.into(); + let b2: u32 = b2.into(); + let b3: u32 = b3.into(); b0 + 256 * (b1 + 256 * (b2 + 256 * b3)) }