Compute the sum of two BigInts
(a: u32, b: u32)
| 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 { |
nothing calls this directly
no outgoing calls
no test coverage detected