Skip to content

Commit

Permalink
fix: simplify chiplets bus hasher chiplet (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer authored Oct 7, 2024
1 parent 5dc5c2e commit f92a463
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 58 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- Fixed the construction of the block hash table (#1506)
- Fixed a bug in the block stack table (#1511) (#1512)
- Fixed the construction of the chiplets virtual table (#1514)
- Fixed the construction of the chiplets bus (#1516)
- Fixed the construction of the chiplets bus (#1516) (#1525)

#### Fixes

Expand Down
65 changes: 8 additions & 57 deletions processor/src/chiplets/aux_trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,7 @@ fn build_hperm_request<E: FieldElement<BaseField = Felt>>(
main_trace.stack_element(11, row + 1),
];

let op_label = LINEAR_HASH_LABEL;
let op_label = if addr_to_hash_cycle(helper_0) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = LINEAR_HASH_LABEL + 16;

let sum_input = alphas[4..16]
.iter()
Expand All @@ -571,12 +566,7 @@ fn build_hperm_request<E: FieldElement<BaseField = Felt>>(
+ alphas[2].mul_base(helper_0)
+ sum_input;

let op_label = RETURN_STATE_LABEL;
let op_label = if addr_to_hash_cycle(helper_0 + Felt::new(7)) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = RETURN_STATE_LABEL + 32;

let sum_output = alphas[4..16]
.iter()
Expand Down Expand Up @@ -614,12 +604,7 @@ fn build_mpverify_request<E: FieldElement<BaseField = Felt>>(
main_trace.stack_element(9, row),
];

let op_label = MP_VERIFY_LABEL;
let op_label = if addr_to_hash_cycle(helper_0) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = MP_VERIFY_LABEL + 16;

let sum_input = alphas[8..12]
.iter()
Expand All @@ -633,12 +618,7 @@ fn build_mpverify_request<E: FieldElement<BaseField = Felt>>(
+ alphas[3].mul_base(s5)
+ sum_input;

let op_label = RETURN_HASH_LABEL;
let op_label = if (helper_0).as_int() % 8 == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = RETURN_HASH_LABEL + 32;

let sum_output = alphas[8..12]
.iter()
Expand Down Expand Up @@ -688,12 +668,7 @@ fn build_mrupdate_request<E: FieldElement<BaseField = Felt>>(
main_trace.stack_element(13, row),
];

let op_label = MR_UPDATE_OLD_LABEL;
let op_label = if addr_to_hash_cycle(helper_0) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = MR_UPDATE_OLD_LABEL + 16;

let sum_input = alphas[8..12]
.iter()
Expand All @@ -706,12 +681,7 @@ fn build_mrupdate_request<E: FieldElement<BaseField = Felt>>(
+ alphas[3].mul_base(s5)
+ sum_input;

let op_label = RETURN_HASH_LABEL;
let op_label = if addr_to_hash_cycle(helper_0 + s4.mul_small(8) - ONE) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = RETURN_HASH_LABEL + 32;

let sum_output = alphas[8..12]
.iter()
Expand All @@ -723,12 +693,7 @@ fn build_mrupdate_request<E: FieldElement<BaseField = Felt>>(
+ alphas[2].mul_base(helper_0 + s4.mul_small(8) - ONE)
+ sum_output;

let op_label = MR_UPDATE_NEW_LABEL;
let op_label = if addr_to_hash_cycle(helper_0 + s4.mul_small(8)) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = MR_UPDATE_NEW_LABEL + 16;
let sum_input = alphas[8..12]
.iter()
.rev()
Expand All @@ -740,12 +705,7 @@ fn build_mrupdate_request<E: FieldElement<BaseField = Felt>>(
+ alphas[3].mul_base(s5)
+ sum_input;

let op_label = RETURN_HASH_LABEL;
let op_label = if addr_to_hash_cycle(helper_0 + s4.mul_small(16) - ONE) == 0 {
op_label + 16
} else {
op_label + 32
};
let op_label = RETURN_HASH_LABEL + 32;

let sum_output = alphas[8..12]
.iter()
Expand Down Expand Up @@ -952,15 +912,6 @@ fn get_op_label(s0: Felt, s1: Felt, s2: Felt, s3: Felt) -> Felt {
s3.mul_small(1 << 3) + s2.mul_small(1 << 2) + s1.mul_small(2) + s0 + ONE
}

/// Returns the hash cycle corresponding to the provided Hasher address.
fn addr_to_hash_cycle(addr: Felt) -> usize {
let row = (addr.as_int() - 1) as usize;
let cycle_row = row % HASH_CYCLE_LEN;
debug_assert!(cycle_row == 0 || cycle_row == HASH_CYCLE_LEN - 1, "invalid address for hasher");

cycle_row
}

/// Computes a memory read or write request at `row` given randomness `alphas`, memory address
/// `addr` and value `value`.
fn compute_memory_request<E: FieldElement<BaseField = Felt>>(
Expand Down

0 comments on commit f92a463

Please sign in to comment.