diff --git a/README.md b/README.md index ca25b1c7..a604b317 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ There are also few utility function for calculating hashes: - `get_verification_hash(fact_hash: felt252, verifier_config_hash: felt252, security_bits: u32) -> felt252` - calculates verification hash for given `fact_hash`, `verifier_config_hash` and `security_bits`. - `calculate_fact_hash(program_hash: felt256, output: Span) -> felt252` - calculates fact hash for given `program_hash` and `output` array. - `calculate_bootloaded_fact_hash(bootloader_program_hash: felt252, child_program_hash: felt252, child_output: Span) -> felt252` - calculates fact hash for program that was bootloaded with standard bootloader. +- `calculate_wrapped_bootloaded_fact_hash(wrapper_program_hash: felt252, bootloader_program_hash: felt252, child_program_hash: felt252, child_output: Span) -> felt252` - calculates fact hash for a wrapped and bootloaded with the standard bootloader. Available constants are: diff --git a/src/lib_utils.cairo b/src/lib_utils.cairo index a8e9f12d..43d3dc17 100644 --- a/src/lib_utils.cairo +++ b/src/lib_utils.cairo @@ -123,6 +123,8 @@ const SHARP_BOOTLOADER_PROGRAM_HASH: felt252 = 0x5ab580b04e3532b6b18f81cfa654a05e29dd8e2352d88df1e765a84072db07; const STONE_BOOTLOADER_PROGRAM_HASH: felt252 = 0x40519557c48b25e7e7d27cb27297300b94909028c327b385990f0b649920cc3; +const CAIRO_VERIFIER_PROGRAM_HASH: felt252 = + 0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0; fn calculate_bootloaded_fact_hash( bootloader_program_hash: felt252, child_program_hash: felt252, child_output: Span @@ -139,3 +141,27 @@ fn calculate_bootloaded_fact_hash( .update(bootloader_output.finalize()) .finalize() } + +fn calculate_wrapped_bootloaded_fact_hash( + wrapper_program_hash: felt252, bootloader_program_hash: felt252, child_program_hash: felt252, child_output: Span +) -> felt252 { + let mut bootloader_output = PoseidonImpl::new() + .update(0x1) + .update(child_output.len().into() + 2) + .update(child_program_hash); + for x in child_output { + bootloader_output = bootloader_output.update(*x); + }; + + let mut wrapper_output = PoseidonImpl::new() + .update(0x1) + .update(0x4) + .update(wrapper_program_hash) + .update(bootloader_program_hash) + .update(bootloader_output.finalize()); + + PoseidonImpl::new() + .update(bootloader_program_hash) + .update(wrapper_output.finalize()) + .finalize() +} \ No newline at end of file