def test_commitment() -> None: ec = secp256k1 hf = sha256 r1 = 0x1 v1 = 0x2 # r1*G + v1*H C1 = pedersen.commit(r1, v1, ec, hf) assert pedersen.open(r1, v1, C1, ec, hf) r2 = 0x3 v2 = 0x4 # r2*G + v2*H C2 = pedersen.commit(r2, v2, ec, hf) assert pedersen.open(r2, v2, C2, ec, hf) # Pedersen Commitment is additively homomorphic # Commit(r1, v1) + Commit(r2, v2) = Commit(r1+r2, v1+r2) R = pedersen.commit(r1 + r2, v1 + v2, ec, hf) assert ec.add(C1, C2) == R # commit does not open (with catched exception) assert not pedersen.open((r1, r1), v1, C2, ec, hf) # type: ignore with pytest.raises(TypeError, match="not an Integer"): pedersen.commit((r1, r1), v1, ec, hf) # type: ignore
def test_commitment(self): ec = secp256k1 hf = sha256 r1 = 0x1 v1 = 0x2 # r1*G + v1*H C1 = pedersen.commit(r1, v1, ec, hf) self.assertTrue(pedersen.open(r1, v1, C1, ec, hf)) r2 = 0x3 v2 = 0x4 # r2*G + v2*H C2 = pedersen.commit(r2, v2, ec, hf) self.assertTrue(pedersen.open(r2, v2, C2, ec, hf)) # Pedersen Commitment is additively homomorphic # Commit(r1, v1) + Commit(r2, v2) = Commit(r1+r2, v1+r2) R = pedersen.commit(r1 + r2, v1 + v2, ec, hf) self.assertTrue(ec.add(C1, C2), R) # commit does not open (with catched exception) self.assertFalse(pedersen.open((r1, r1), v1, C2, ec, hf))