Ejemplo n.º 1
0
 def test_l3block_signing_hashing_v2(self):
     block = make_l3_block_v2()
     sig = crypto.sign_l3_block(blake2b, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIGz8Tx1KZs386w9aTr/jtB8fVkprMzv8TW2A4Wc45FSjAiBBzgx9z0n/IcvSYTF/ZHpSlTyL6Xgacf+VsSWUO2JnQQ=="
     )
     sig = crypto.sign_l3_block(sha256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEUCIQCqPf3Y0lpNpCDA0m3AvPXbsMDtx3+xiWSOdWOGUHkwsQIgbeDyddkKuUsEC8zCcIFsdgPUy58X5GmCpVrGwkWg+I8="
     )
     sig = crypto.sign_l3_block(sha3_256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIFfPjZK5tSVVps4YqdHxD0n/ypkFVaHWyw+lDYPX+HUrAiBB7zoPt8Xd5SpTPcu4YpKl5Z4ff7Ibh2PGhbbWbtcbfw=="
     )
     block_hash, nonce = crypto.pow_l3_block(blake2b, block)
     self.assertEqual(block_hash,
                      "AILgeOkQNYDjaT47dnyYOV8CcCtHJPkxBZLdgOCiUMA=")
     self.assertEqual(nonce, 351)
     block_hash, nonce = crypto.pow_l3_block(sha256, block)
     self.assertEqual(block_hash,
                      "ABWOslEpGB4jRibC0cxHGUrHRTBjOxHhUsANM1f03R0=")
     self.assertEqual(nonce, 7)
     block_hash, nonce = crypto.pow_l3_block(sha3_256, block)
     self.assertEqual(block_hash,
                      "ALOKQPxF0tx99mZP+UZVPotGcT9Oss3mx9sHs2eMA54=")
     self.assertEqual(nonce, 498)
Ejemplo n.º 2
0
 def test_l3block_signing_hashing(self):
     block = make_l3_block()
     sig = crypto.sign_l3_block(blake2b, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIBx+i31vFfaXjlyvAYlTyVw+AuGcKnqL55AjuKO5UwwfAiA2+Rf6dde2mpXpK/OrSycQNuiksL8Y1DTc6zz4B+dCqA=="
     )
     sig = crypto.sign_l3_block(sha256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIEnH0caGprg13H0q4x803dgVo7xcGyf/i2M+6tCe0aKRAiBvNlcXeJD9yRVT6g8cZ0MM6tJBc/OWx9Kbq1qsCOo/7w=="
     )
     sig = crypto.sign_l3_block(sha3_256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEUCIQDPuuxO4PcPKNYMogl58ZF9an/FU7cO3jf2VdjRKLXjKwIgVz64rFKrs1GQ/AVFOSYNP8nM8mcZs5hRoveo4SGeby0="
     )
     block_hash, nonce = crypto.pow_l3_block(blake2b, block)
     self.assertEqual(block_hash,
                      "AKNA21rqNqaWeKglP6QGDe09k+SWZfEmVvHjJxI9w/c=")
     self.assertEqual(nonce, 231)
     block_hash, nonce = crypto.pow_l3_block(sha256, block)
     self.assertEqual(block_hash,
                      "AFFPeRLW3Y/zdfd9QRI6IQD32Hdt2BmzmotwFq0+3WU=")
     self.assertEqual(nonce, 205)
     block_hash, nonce = crypto.pow_l3_block(sha3_256, block)
     self.assertEqual(block_hash,
                      "ABQlIssL2qpK8iPI7lKu5rtEmnv8i7tMLy8sz4LcFH0=")
     self.assertEqual(nonce, 339)
Ejemplo n.º 3
0
 def test_l3block_pow_verifying_v2(self):
     block = make_l3_block_v2()
     block_hash, nonce = crypto.pow_l3_block(blake2b, block)
     block.proof = block_hash
     block.nonce = nonce
     block.scheme = "work"
     self.assertTrue(crypto.verify_l3_block_pow(blake2b, block))
     valid_block = copy.deepcopy(block)
     block.dc_id = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.block_id = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.timestamp = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.prev_proof = "forged=="
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.l1_dc_id = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.l1_block_id = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.l1_proof = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.ddss = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.l2_count = "forged"
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.regions = ["forged", "stuff"]
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.clouds = ["forged"]
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.proof = "47DEQpj8HBSa+/FORGEDJCeuQeRkm5NMpJWZG3hSuFU="
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
     block = copy.deepcopy(valid_block)
     block.nonce = 0
     self.assertFalse(crypto.verify_l3_block_pow(blake2b, block))
Ejemplo n.º 4
0
 def pow_block(self, signable_block: "model.BlockModel") -> Tuple[str, int]:
     """Do proof of work on a block
     Args:
         block: BlockModel to do proof of work on
     Returns:
         Tuple where index 0 is a Base64 encoded string of the generated hash and index 1 is the nonce
     Raises:
         exceptions.InvalidNodeLevel when invalid level on self
     """
     if self.level == 1:
         return crypto.pow_l1_block(
             self.hash, cast("l1_block_model.L1BlockModel", signable_block))
     elif self.level == 2:
         return crypto.pow_l2_block(
             self.hash, cast("l2_block_model.L2BlockModel", signable_block))
     elif self.level == 3:
         return crypto.pow_l3_block(
             self.hash, cast("l3_block_model.L3BlockModel", signable_block))
     elif self.level == 4:
         return crypto.pow_l4_block(
             self.hash, cast("l4_block_model.L4BlockModel", signable_block))
     else:
         raise exceptions.InvalidNodeLevel(
             f"Node level {self.level} not implemented yet")