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

Method add

bitvm/src/bigint/add.rs:37–64  ·  view source on GitHub ↗

Compute the sum of two BigInts

(a: u32, b: u32)

Source from the content-addressed store, hash-verified

35
36 /// Compute the sum of two BigInts
37 pub fn add(a: u32, b: u32) -> Script {
38 script! {
39 { Self::zip(a, b) }
40
41 { 1 << LIMB_SIZE }
42
43 // A0 + B0
44 limb_add_carry OP_TOALTSTACK
45
46 // from A1 + B1 + carry_0
47 // to A{N-2} + B{N-2} + carry_{N-3}
48 for _ in 0..Self::N_LIMBS - 2 {
49 OP_ROT
50 OP_ADD
51 OP_SWAP
52 limb_add_carry OP_TOALTSTACK
53 }
54
55 // A{N-1} + B{N-1} + carry_{N-2}
56 OP_NIP
57 OP_ADD
58 { limb_add_nocarry(Self::HEAD_OFFSET) }
59
60 for _ in 0..Self::N_LIMBS - 1 {
61 OP_FROMALTSTACK
62 }
63 }
64 }
65
66 /// add one
67 pub fn add1() -> Script {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected