public void BDSerializationTest()
        {
            FieldZqElement     bigNum               = _parameters[0].FieldZq.GetElement(2056);
            PedersenCommitment bigNumCommit         = new PedersenCommitment(bigNum, _parameters[0]);
            int decompositionLength                 = 15;
            ProverBitDecompositionParameters prover = new ProverBitDecompositionParameters(
                bigNumCommit,
                decompositionLength,
                _parameters[0]);

            BitDecompositionProof proof = new BitDecompositionProof(prover);

            Assert.IsTrue(proof.Verify(prover), "original proof verification.");
            string jsonProof = CryptoSerializer.Serialize <BitDecompositionProof>(proof);
            // TODO: switch to using ip-based de-serialization; need to harmonize with U-Prove SDK code
            IssuerParameters ip = new IssuerParameters();

            ip.Gq = prover.Group;
            BitDecompositionProof deserializedProof = ip.Deserialize <BitDecompositionProof>(jsonProof);// CryptoSerializer.Deserialize<BitDecompositionProof>(jsonProof);

            Assert.IsTrue(deserializedProof.Verify(prover), "deserialized proof verfication");


            string jsonProver = CryptoSerializer.Serialize <ProverBitDecompositionParameters>(prover);
            ProverBitDecompositionParameters deserializedProver = CryptoSerializer.Deserialize <ProverBitDecompositionParameters>(jsonProver);

            Assert.IsTrue(deserializedProof.Verify(deserializedProver), "deserialized proof with deserialized prover.");

            BitDecompositionProof proof2 = new BitDecompositionProof(deserializedProver);

            Assert.IsTrue(proof2.Verify(deserializedProver), "proof2.verify(deserializedProver)");
            Assert.IsTrue(proof2.Verify(prover), "Proof2.verify(prover)");
        }
        public void BDBadProofTest()
        {
            FieldZqElement     bigNum       = _parameters[0].FieldZq.GetElement(30);
            PedersenCommitment bigNumCommit = new PedersenCommitment(bigNum, _parameters[0]);
            int decompositionLength         = 8;


            ProverBitDecompositionParameters proverParams = new ProverBitDecompositionParameters(
                bigNumCommit,
                decompositionLength,
                _parameters[0]);
            BitDecompositionProof proof         = new BitDecompositionProof(proverParams);
            PrivateObject         proofAccessor = new PrivateObject(proof);

            SetMembershipProof[] smProof    = (SetMembershipProof[])proofAccessor.GetField("bitCommitmentProof");
            SetMembershipProof[] badSmProof = smProof;
            SetMembershipProof   tmp        = smProof[1];

            badSmProof[1] = badSmProof[0];
            proofAccessor.SetFieldOrProperty("bitCommitmentProof", badSmProof);
            Assert.IsFalse(proof.Verify(proverParams), "bad set membeship proof.");
            proofAccessor.SetFieldOrProperty("bitCommitmentProof", smProof);
            smProof[1] = tmp;
            Assert.IsTrue(proof.Verify(proverParams), "good set membership proof.");

            EqualityProof eqProof         = (EqualityProof)proofAccessor.GetField("compositionProof");
            PrivateObject eqProofAccessor = new PrivateObject(eqProof);

            GroupElement [] b = (GroupElement[])eqProofAccessor.GetField("b");
            b[1] = b[0];
            eqProofAccessor.SetField("b", b);
            Assert.IsFalse(proof.Verify(proverParams), "bad equality proof");
        }
        public void BDBadProverTest()
        {
            ProverBitDecompositionParameters prover = new ProverBitDecompositionParameters(
                new PedersenCommitment(_parameters[2].FieldZq.GetElement(10), _parameters[2]),
                4,
                _parameters[2]);

            BitDecompositionProof proof          = new BitDecompositionProof(prover);
            PrivateObject         proverAccessor = new PrivateObject(prover);

            PedersenCommitment[] witnesses = (PedersenCommitment[] )proverAccessor.GetFieldOrProperty("Witnesses");
            witnesses[witnesses.Length - 1] = new PedersenCommitment(_parameters[2].FieldZq.GetElement(10), _parameters[2]);
            Assert.IsFalse(proof.Verify(prover));
        }
        public void BDEndToEnd()
        {
            FieldZqElement     bigNum       = _parameters[0].FieldZq.GetElement(2056);
            PedersenCommitment bigNumCommit = new PedersenCommitment(bigNum, _parameters[0]);
            int decompositionLength         = 15;


            ProverBitDecompositionParameters proverParams = new ProverBitDecompositionParameters(
                bigNumCommit,
                decompositionLength,
                _parameters[0]);

            BitDecompositionProof proof = new BitDecompositionProof(proverParams);

            Assert.IsTrue(proof.Verify(proverParams), "could not verify proof with prover params");

            VerifierBitDecompositionParameters verifierParams = new VerifierBitDecompositionParameters(
                proverParams.ClosedCommitment,
                proverParams.ClosedBitDecomposition(),
                proverParams);

            Assert.IsTrue(proof.Verify(verifierParams), "could not verify proof with verifier parameters");
        }