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

Function NMUL

bitvm/src/pseudo.rs:156–169  ·  view source on GitHub ↗
(n: u32)

Source from the content-addressed store, hash-verified

154}
155
156pub fn NMUL(n: u32) -> Script {
157 let n_bits = u32::BITS - n.leading_zeros();
158 let bits = (0..n_bits).map(|i| 1 & (n >> i)).collect::<Vec<_>>();
159 script! {
160 if n_bits == 0 { OP_DROP 0 }
161 else {
162 for i in 0..bits.len()-1 {
163 if bits[i] == 1 { OP_DUP }
164 { crate::pseudo::OP_2MUL() }
165 }
166 for _ in 1..bits.iter().sum() { OP_ADD }
167 }
168 }
169}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected