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

Function test_limb_to_be_bits

bitvm/src/bigint/bits.rs:207–279  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205
206 #[test]
207 fn test_limb_to_be_bits() {
208 println!(
209 "limb_to_be_bits(29): {:?} bytes",
210 script! { {limb_to_be_bits(29)} }.len()
211 );
212 let mut prng = ChaCha20Rng::seed_from_u64(0);
213
214 for _ in 0..100 {
215 let mut a: u32 = prng.gen();
216 a %= 1 << 29;
217
218 let mut bits = vec![];
219 let mut cur = a;
220 for _ in 0..29 {
221 bits.push(cur % 2);
222 cur /= 2;
223 }
224
225 let script = script! {
226 { a }
227 { limb_to_be_bits(29) }
228 for i in 0..29 {
229 { bits[28 - i] }
230 OP_EQUALVERIFY
231 }
232 OP_TRUE
233 };
234 run(script);
235 }
236
237 for _ in 0..100 {
238 let mut a: u32 = prng.gen();
239 a %= 1 << 15;
240
241 let mut bits = vec![];
242 let mut cur = a;
243 for _ in 0..15 {
244 bits.push(cur % 2);
245 cur /= 2;
246 }
247
248 let script = script! {
249 { a }
250 { limb_to_be_bits(15) }
251 for i in 0..15 {
252 { bits[14 - i as usize] }
253 OP_EQUALVERIFY
254 }
255 OP_TRUE
256 };
257
258 run(script);
259 }
260
261 for a in 0..4 {
262 let script = script! {
263 { a }
264 { limb_to_be_bits(2) }

Callers

nothing calls this directly

Calls 2

runFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected