MCPcopy Create free account
hub / github.com/BitVM/BitVM / g

Function g

bitvm/src/hash/blake3_utils.rs:248–317  ·  view source on GitHub ↗
(
    stack: &mut StackTracker,
    var_map: &mut HashMap<u8, StackVariable>,
    a: u8,
    b: u8,
    c: u8,
    d: u8,
    mut m_two_i: StackVariable,
    mut m_two_i_plus_one: StackVariable,
    t

Source from the content-addressed store, hash-verified

246/// Applies the G function (same notation as the paper) with the given parameters to the variables
247#[allow(clippy::too_many_arguments)]
248fn g(
249 stack: &mut StackTracker,
250 var_map: &mut HashMap<u8, StackVariable>,
251 a: u8,
252 b: u8,
253 c: u8,
254 d: u8,
255 mut m_two_i: StackVariable,
256 mut m_two_i_plus_one: StackVariable,
257 tables: &TablesVars,
258 last_round: bool,
259) {
260 //adds a + b + mx
261 //consumes a and mx and copies b
262 let vb = var_map[&b];
263 let mut va = var_map.get_mut(&a).unwrap();
264
265 if last_round {
266 u4_add_direct(stack, vec![vb], vec![&mut va, &mut m_two_i], tables);
267 } else {
268 u4_add_direct(stack, vec![vb, m_two_i], vec![&mut va], tables);
269 }
270
271 //stores the results in a
272 *va = stack.from_altstack_joined(8, &format!("state_{}", a));
273
274 // right rotate d xor a ( consumes d and copies a)
275 let ret =
276 xor_and_rotate_right_by_multiple_of_4(stack, var_map, d, a, 16, tables.use_full_tables);
277 // saves in d
278 var_map.insert(d, ret);
279
280 let vd = var_map[&d];
281 let mut vc = var_map.get_mut(&c).unwrap();
282 u4_add_direct(stack, vec![vd], vec![&mut vc], tables);
283 *vc = stack.from_altstack_joined(8, &format!("state_{}", c));
284
285 let ret =
286 xor_and_rotate_right_by_multiple_of_4(stack, var_map, b, c, 12, tables.use_full_tables);
287 var_map.insert(b, ret);
288
289 let vb = var_map[&b];
290 let mut va = var_map.get_mut(&a).unwrap();
291 if last_round {
292 u4_add_direct(
293 stack,
294 vec![vb],
295 vec![&mut va, &mut m_two_i_plus_one],
296 tables,
297 );
298 } else {
299 u4_add_direct(stack, vec![vb, m_two_i_plus_one], vec![&mut va], tables);
300 }
301
302 *va = stack.from_altstack_joined(8, &format!("state_{}", a));
303
304 let ret =
305 xor_and_rotate_right_by_multiple_of_4(stack, var_map, d, a, 8, tables.use_full_tables);

Callers 2

roundFunction · 0.85
test_gFunction · 0.85

Calls 3

u4_add_directFunction · 0.85

Tested by 1

test_gFunction · 0.68