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

Function u4_add_nibble_stack

bitvm/src/hash/sha256_u4_stack.rs:250–289  ·  view source on GitHub ↗
(
    stack: &mut StackTracker,
    carry: &mut StackVariable,
    number_count: u32,
    is_last: bool,
    quotient_table: StackVariable,
    modulo_table: StackVariable,
)

Source from the content-addressed store, hash-verified

248}
249
250pub fn u4_add_nibble_stack(
251 stack: &mut StackTracker,
252 carry: &mut StackVariable,
253 number_count: u32,
254 is_last: bool,
255 quotient_table: StackVariable,
256 modulo_table: StackVariable,
257) -> StackVariable {
258 if !carry.is_null() {
259 stack.move_var(*carry);
260 stack.op_add();
261 }
262
263 if modulo_table.is_null() || quotient_table.is_null() {
264 if !is_last {
265 let output_vars = vec![(1, "add_no_table".into()), (1, "carry_no_table".into())];
266 let out = stack.custom_ex(u4_add_carry_nested(0, number_count), 1, output_vars, 0);
267 *carry = out[1];
268 out[0]
269 } else {
270 {
271 let output_vars = vec![(1, "add_no_table".into())];
272 stack.custom_ex(u4_add_nested(0, number_count), 1, output_vars, 0)[0]
273 }
274 }
275 } else {
276 if !is_last {
277 stack.op_dup();
278 }
279 let var = stack.get_value_from_table(modulo_table, None);
280
281 //we don't care about the last carry
282 if !is_last {
283 stack.op_swap();
284 //obtain the quotinent to be used as carry for the next addition
285 *carry = stack.get_value_from_table(quotient_table, None);
286 }
287 var
288 }
289}
290
291pub fn sha256_stack(
292 stack: &mut StackTracker,

Callers 1

sha256_stackFunction · 0.85

Calls 2

u4_add_carry_nestedFunction · 0.85
u4_add_nestedFunction · 0.85

Tested by

no test coverage detected