use crate::enforcement::{ContentFingerprint, GenericImpossibilityWitness};
use crate::witness_scaffolds::{MintDisjointnessWitness, MintDisjointnessWitnessInputs};
use crate::HostTypes;
fn fingerprint_for_inputs(chunks: &[&[u8]]) -> ContentFingerprint {
let mut buf = [0u8; 32];
let mut global: usize = 0;
let mut chunk_idx = 0;
while chunk_idx < chunks.len() {
let chunk = chunks[chunk_idx];
let mut i = 0;
while i < chunk.len() {
let pos = global % 32;
#[allow(clippy::cast_possible_truncation)]
let salt = global as u8;
buf[pos] ^= chunk[i].wrapping_add(salt);
i += 1;
global += 1;
}
let pos = global % 32;
buf[pos] ^= 0xFFu8;
global += 1;
chunk_idx += 1;
}
ContentFingerprint::from_buffer(buf, 32u8)
}
pub fn verify_effect_disjointness_witness<H: HostTypes + 'static>(
inputs: MintDisjointnessWitnessInputs<H>,
) -> Result<MintDisjointnessWitness, GenericImpossibilityWitness> {
if inputs.disjointness_left.fingerprint.is_zero()
|| inputs.disjointness_right.fingerprint.is_zero()
{
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/FX_4",
));
}
if inputs.disjointness_left.fingerprint == inputs.disjointness_right.fingerprint {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/FX_4",
));
}
let left_bytes = inputs.disjointness_left.fingerprint.as_bytes();
let right_bytes = inputs.disjointness_right.fingerprint.as_bytes();
let fp = fingerprint_for_inputs(&[b"https://uor.foundation/op/FX_4", left_bytes, right_bytes]);
Ok(MintDisjointnessWitness::from_fingerprint(fp))
}