Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fact hash calculation for wrapped proofs #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading