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

Method push_u32_le

bitvm/src/bigint/std.rs:47–94  ·  view source on GitHub ↗
(v: &[u32])

Source from the content-addressed store, hash-verified

45 }
46
47 pub fn push_u32_le(v: &[u32]) -> Script {
48 let mut bits = vec![];
49 for elem in v.iter() {
50 for i in 0..32 {
51 bits.push((elem & (1 << i)) != 0);
52 }
53 }
54 // make sure most significant 1 lies inside the limits
55 let ms_one = if bits.len() > 0 {
56 let mut ms_one = bits.len() - 1;
57 while !bits[ms_one] {
58 if ms_one != 0 {
59 ms_one -= 1;
60 } else {
61 break;
62 }
63 }
64 ms_one
65 } else {
66 0
67 };
68 assert!(ms_one < Self::N_BITS as usize);
69 bits.resize(N_BITS as usize, false);
70
71 let mut limbs = vec![];
72 for chunk in bits.chunks(LIMB_SIZE as usize) {
73 let mut chunk_vec = chunk.to_vec();
74 chunk_vec.resize(LIMB_SIZE as usize, false);
75
76 let mut elem = 0u32;
77 for (i, chunk_i) in chunk_vec.into_iter().enumerate() {
78 if chunk_i {
79 elem += 1 << i;
80 }
81 }
82
83 limbs.push(elem);
84 }
85
86 limbs.reverse();
87
88 script! {
89 for limb in &limbs {
90 { *limb }
91 }
92 { push_to_stack(0,Self::N_LIMBS as usize - limbs.len()) }
93 }
94 }
95
96 pub fn read_u32_le(mut witness: Vec<Vec<u8>>) -> Vec<u32> {
97 assert_eq!(witness.len() as u32, Self::N_LIMBS);

Callers

nothing calls this directly

Calls 3

lenMethod · 0.80
resizeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected