Add BigInt on top of the stack to a BigInt at `b` depth in the stack # Note This function consumes the BigInt on top of the stack while not consuming the referenced BigInt
(b: u32)
| 259 | /// This function consumes the BigInt on top of the stack while not consuming |
| 260 | /// the referenced BigInt |
| 261 | pub fn add_ref(b: u32) -> Script { |
| 262 | let b_depth = b * Self::N_LIMBS; |
| 263 | assert_ne!(b, 0); |
| 264 | script! { |
| 265 | { b_depth } OP_PICK |
| 266 | OP_ADD |
| 267 | |
| 268 | // OP_DEPTH OP_1SUB OP_PICK |
| 269 | { 1 << LIMB_SIZE } |
| 270 | OP_SWAP |
| 271 | |
| 272 | { limb_add_create_carry() } |
| 273 | OP_TOALTSTACK |
| 274 | |
| 275 | for _ in 0..Self::N_LIMBS - 2 { |
| 276 | OP_ROT |
| 277 | { b_depth + 2 } OP_PICK |
| 278 | OP_ADD |
| 279 | OP_ADD { limb_add_create_carry() } OP_TOALTSTACK |
| 280 | } |
| 281 | |
| 282 | OP_NIP |
| 283 | { b_depth + 1 } OP_PICK |
| 284 | OP_SWAP |
| 285 | { limb_add_with_carry_prevent_overflow(Self::HEAD_OFFSET) } |
| 286 | |
| 287 | for _ in 0..Self::N_LIMBS - 1 { |
| 288 | OP_FROMALTSTACK |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /// Add BigInt referenced by the integer (depth) on top of the stack to the BigInt at |
| 294 | /// the top the stack below the depth |
nothing calls this directly
no outgoing calls
no test coverage detected