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

Function decompose_for_sumset

smc_range_proof/src/cls_range_proof/util.rs:96–113  ·  view source on GitHub ↗

Returns digits of `value` when expressed in sumset notation give sumset boundaries, i.e. `G`

(value: u128, G: &[u128], base: u16)

Source from the content-addressed store, hash-verified

94
95/// Returns digits of `value` when expressed in sumset notation give sumset boundaries, i.e. `G`
96pub fn decompose_for_sumset(value: u128, G: &[u128], base: u16) -> Vec<u16> {
97 let mut deomposition = vec![0; G.len()];
98 let mut target = value;
99 for (i, g_i) in G.iter().enumerate() {
100 // For each g_i, check if target >= (base-1) * g_i. If it is then digit corresponding to g_i is (base-1) and new
101 // target is target - (base-1) * g_i. Else check if target >= (base-2) * g_i and so on.
102 for u_i in (1..base).rev() {
103 let g_u = *g_i * u_i as u128;
104 if target >= g_u {
105 deomposition[i] = u_i;
106 target -= g_u;
107 break;
108 }
109 }
110 }
111 debug_assert_eq!(target, 0);
112 deomposition
113}
114
115/// Pre-requisites of applying sumset protocol
116/// Returns number of digits, sumset boundaries (G), randomness multiple and digits of the adapted value.

Callers 2

get_sumset_parametersFunction · 0.85
sumsets_checkFunction · 0.85

Calls 1

iterMethod · 0.45

Tested by 1

sumsets_checkFunction · 0.68