Skip to content

Commit

Permalink
feat: add fact hash calculation for wrapped bootloaded programs
Browse files Browse the repository at this point in the history
  • Loading branch information
petscheit committed Dec 11, 2024
1 parent 4e7ca6e commit a2256ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>) -> 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>) -> 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>) -> felt252` - calculates fact hash for a wrapped and bootloaded with the standard bootloader.

Available constants are:

Expand Down
26 changes: 26 additions & 0 deletions src/lib_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252>
Expand All @@ -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>
) -> 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()
}

0 comments on commit a2256ea

Please sign in to comment.