def test_commitment(self): Alice = web3.eth.accounts[1] contract = deploy(web3, 'CommitHere') # Observer sets monitor parameters for Alice, observer = Observer(web3, contract) target_a, target_b, target_c, shuffle, _ = observer.set_monitor_parameters( Alice) # and sends them to Alice # Alice makes a commitment to a value val = randsn() C, r = pedersen_c(val) # Alice prepares her hint values x = submodn(target_a, val) X = multiply(G1, x) Y = multiply(H, submodn(target_b, r)) z = mulmodn(invmodn(x), target_c) # Alice prepares the update commitment T, _ = pedersen_c(target_a, target_b) u, e, A, T_ = dh_create(G1, T, shuffle) # Alice publicly broadcasts her commitment and hint tx_hash = contract.functions.storeCommitment( pasint(C), pasint(X) + pasint(Y), z, u, e, pasint(T_)).transact({'from': Alice}) receipt = web3.eth.waitForTransactionReceipt(tx_hash) nonce = 0 C_ = contract.functions.getCommitment(Alice).call() self.assertEqual(C[0], C_[0]) self.assertEqual(C[1], C_[1]) monitor_params = contract.functions.getMonitorParameters(Alice).call() self.assertTrue(monitor_params[0], T_[0]) self.assertTrue(monitor_params[1], T_[1]) # Observer extracts value as; val_ = observer.extract_value(Alice, z, nonce) self.assertEqual(val, val_) # Alice makes a commitment to another value val = randsn() C, r = pedersen_c(val) # Alice prepares her hint values target_a = mulmodn(target_a, shuffle) target_b = mulmodn(target_b, shuffle) x = submodn(target_a, val) X = multiply(G1, x) Y = multiply(H, submodn(target_b, r)) z = mulmodn(invmodn(x), target_c) # Alice prepares the update commitment T, _ = pedersen_c(target_a, target_b) u, e, A, T_ = dh_create(G1, T, shuffle) # Alice publicly broadcasts her commitment and hint tx_hash = contract.functions.storeCommitment( pasint(C), pasint(X) + pasint(Y), z, u, e, pasint(T_)).transact({'from': Alice}) receipt = web3.eth.waitForTransactionReceipt(tx_hash) nonce = 1 C_ = contract.functions.getCommitment(Alice).call() self.assertEqual(C[0], C_[0]) self.assertEqual(C[1], C_[1]) # Observer extracts value as; val_ = observer.extract_value(Alice, z, nonce) self.assertEqual(val, val_)