MCPcopy Create free account
hub / github.com/docknetwork/crypto / get_sumset_parameters

Function get_sumset_parameters

smc_range_proof/src/cls_range_proof/util.rs:117–146  ·  view source on GitHub ↗

Pre-requisites of applying sumset protocol Returns number of digits, sumset boundaries (G), randomness multiple and digits of the adapted value.

(
    value: u64,
    min: u64,
    max: u64,
    base: u16,
)

Source from the content-addressed store, hash-verified

115/// Pre-requisites of applying sumset protocol
116/// Returns number of digits, sumset boundaries (G), randomness multiple and digits of the adapted value.
117pub fn get_sumset_parameters(
118 value: u64,
119 min: u64,
120 max: u64,
121 base: u16,
122) -> (u32, Vec<u128>, u16, Vec<u16>) {
123 // The protocol works for the range [0, H], so change `value` and set range accordingly.
124 // New value becomes value - min
125 // New max becomes max-1 because the implemented protocol is asking for the proof in range [min, max) and
126 // sumset protocol in the paper is described for range [0, max], i.e. upper bound is inclusive in the paper,
127 // but it's not in the implementation
128 let (range, randomness_multiple) = get_range_and_randomness_multiple(base, min, max - 1);
129 let mut value = (value - min) as u128;
130 if randomness_multiple != 1 {
131 // range had to be artificially increased so increase the value accordingly. This won't overflow as original value is a u64
132 value = value * (base - 1) as u128;
133 }
134
135 let l = find_number_of_digits(range, base);
136 let G = find_sumset_boundaries(range, base, l);
137 let digits = decompose_for_sumset(value, &G, base);
138 // Following is only for debugging
139 // let mut expected = 0_u64;
140 // for j in 0..digits.len() {
141 // assert!(digits[j] < base);
142 // expected += digits[j] as u64 * G[j];
143 // }
144 // assert_eq!(expected, value);
145 (l, G, randomness_multiple, digits)
146}
147
148#[cfg(test)]
149mod tests {

Callers 3

init_given_baseMethod · 0.85
init_given_baseMethod · 0.85
init_given_baseMethod · 0.85

Calls 4

find_number_of_digitsFunction · 0.85
find_sumset_boundariesFunction · 0.85
decompose_for_sumsetFunction · 0.85

Tested by

no test coverage detected