#Create the Data. data: Data = Data(bytes(32), edPubKey.to_bytes()) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Verify it. verif: SignedVerification = SignedVerification(data.hash) verif.sign(0, blsPrivKey) #Generate another 6 Blocks. #Next block should have a packet. block: Block = Block( BlockHeader( 0, merit.blockchain.last(), BlockHeader.createContents([], [VerificationPacket(verif.hash, [0])]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(verif.hash, [0])]), 0, merit.blockchain.blocks[-1].header.time + 1200), BlockBody([VerificationPacket(verif.hash, [0])], [], verif.signature)) for _ in range(6): #Mine it. block.mine(blsPrivKey, merit.blockchain.difficulty()) #Add it. merit.add(block) print("Generated Invalid Competing Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Create the next Block.
toAggregate = [] for h in order[0]: for s in order[0][h]: if s not in packets: packets[s] = VerificationPacket(sends[s].hash, []) packets[s].holders.append(h) verif: SignedVerification = SignedVerification(sends[s].hash) verif.sign(h, blsPrivKeys[h]) toAggregate.append(verif.signature) block: Block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents(list(packets.values())), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), list(packets.values())), order[1], blockchain.blocks[-1].header.time + 1200), BlockBody(list(packets.values()), [], Signature.aggregate(toAggregate))) miner: Union[bytes, int] = order[1] if isinstance(miner, bytes): for k in range(len(blsPubKeys)): if miner == blsPubKeys[k].serialize(): block.mine(blsPrivKeys[k], blockchain.difficulty()) break else: block.mine(blsPrivKeys[miner], blockchain.difficulty()) blockchain.add(block)
for h in order[0]: for s in order[0][h]: if s not in packets: packets[s] = VerificationPacket(sends[s].hash, []) packets[s].holders.append(h) verif: SignedVerification = SignedVerification(sends[s].hash) verif.sign(h, blsPrivKeys[h]) toAggregate.append(verif.signature) block: Block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([], list(packets.values())), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), list(packets.values())), order[1], blockchain.blocks[-1].header.time + 1200 ), BlockBody(list(packets.values()), [], Signature.aggregate(toAggregate)) ) miner: Union[bytes, int] = order[1] if isinstance(miner, bytes): for k in range(len(blsPubKeys)): if miner == blsPubKeys[k].serialize(): block.mine(blsPrivKeys[k], blockchain.difficulty()) break
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key() #BLS Private Key. blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest()) #Create a Data for the VerificationPacket. data: Data = Data(bytes(32), edPubKey.to_bytes()) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Generate the VerificationPacket Block. block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([VerificationPacket(data.hash, [1])]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(data.hash, [1])]), blsPrivKey.toPublicKey().serialize(), blockchain.blocks[-1].header.time + 1200), BlockBody([VerificationPacket(data.hash, [1])], [], blsPrivKey.sign(b""))) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it to the vectors. blocks.append(block.toJSON()) print("Generated Hundred Six Block Elements VerificationPacket Block.") #Generate the SendDifficulty Block. elements: List[Element] = []
print("Generated Same Nonce Block " + str(len(blockchain.blocks)) + ".") #Create a DataDifficulty. dataDiff: SignedDataDifficulty = SignedDataDifficulty(3, 0) dataDiff.sign(0, blsPrivKey) #Create a conflicting DataDifficulty with the same nonce. dataDiffConflicting = SignedDataDifficulty(1, 0) dataDiffConflicting.sign(0, blsPrivKey) #Create a MeritRemoval out of the two of them. mr: SignedMeritRemoval = SignedMeritRemoval(dataDiff, dataDiffConflicting) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [mr]), 1, bytes(4), bytes(32), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([], [mr], mr.signature)) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Same Nonce Block " + str(len(blockchain.blocks)) + ".") result: Dict[str, Any] = { "blockchain": blockchain.toJSON(), "removal": mr.toSignedJSON(), } vectors: IO[Any] = open(
for v in range(2): verifs[-1][v].sign(v, blsPrivKeys[v]) #Create the packets. packets: List[SignedVerificationPacket] = [] for packet in verifs: packets.append( SignedVerificationPacket( packet[0].hash, [0, 1], Signature.aggregate([packet[0].signature, packet[1].signature]))) #Create Blocks containing these packets. for packet in packets: block = Block( BlockHeader(0, merit.blockchain.last(), BlockHeader.createContents([], [packet]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [packet]), 1, merit.blockchain.blocks[-1].header.time + 1200), BlockBody([packet], [], packet.signature)) block.mine(blsPrivKeys[1], merit.blockchain.difficulty()) merit.add(block) print("Generated Aggregated Claim Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Generate another 5 Blocks to close the Epochs. #Next block should have the packet. for _ in range(5): block = Block( BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 0, merit.blockchain.blocks[-1].header.time + 1200),
verifs: List[SignedVerification] = [] packets: List[VerificationPacket] = [] for data in datas: verifs.append(SignedVerification(data.hash, 0)) verifs[-1].sign(0, blsPrivKey) packets.append(VerificationPacket(data.hash, [0])) #Create a MeritRemoval out of the conflicting Verifications. mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2]) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([], packets, [mr]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 0, blockchain.blocks[-1].header.time + 1200 ), BlockBody( packets, [mr], Signature.aggregate( [ verifs[0].signature, verifs[1].signature, verifs[2].signature, mr.signature
#Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Partial Block " + str(len(blockchain.blocks)) + ".") #Create a DataDifficulty. dataDiff: SignedDataDifficulty = SignedDataDifficulty(bytes.fromhex("AA" * 32), 0) dataDiff.sign(0, blsPrivKey) #Generate a Block containing the DataDifficulty. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [], [dataDiff]), 1, bytes(4), bytes(32), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([], [dataDiff], dataDiff.signature)) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Partial Block " + str(len(blockchain.blocks)) + ".") #Create a conflicting DataDifficulty with the same nonce. dataDiffConflicting = SignedDataDifficulty( bytes.fromhex( "8888888888888888888888888888888888888888888888888888888888888888"), 0) dataDiffConflicting.sign(0, blsPrivKey)
firstVerif: SignedVerification = SignedVerification(first.hash) firstVerif.sign(0, blsPrivKey) secondVerif: SignedVerification = SignedVerification(second.hash) secondVerif.sign(0, blsPrivKey) packets: List[VerificationPacket] = [ VerificationPacket(first.hash, [0]), VerificationPacket(second.hash, [0]), ] #Generate another 6 Blocks. #Next block should have the packets. block: Block = Block( BlockHeader(0, merit.blockchain.last(), BlockHeader.createContents(packets), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 0, merit.blockchain.blocks[-1].header.time + 1200), BlockBody( packets, [], Signature.aggregate([firstVerif.signature, secondVerif.signature]))) for _ in range(6): #Mine it. block.mine(blsPrivKey, merit.blockchain.difficulty()) #Add it. merit.add(block) print("Generated Competing Finalized Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Create the next Block.
#Create Verifications for all 3. verifs: List[SignedVerification] = [] packets: List[VerificationPacket] = [] for data in datas: verifs.append(SignedVerification(data.hash, 0)) verifs[-1].sign(0, blsPrivKey) packets.append(VerificationPacket(data.hash, [0])) #Create a MeritRemoval out of the conflicting Verifications. mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2]) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents(packets, [mr]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 0, blockchain.blocks[-1].header.time + 1200), BlockBody( packets, [mr], Signature.aggregate([ verifs[0].signature, verifs[1].signature, verifs[2].signature, mr.signature ]))) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Verify Competing Block " + str(len(blockchain.blocks)) + ".")
str(len(blockchain.blocks)) + ".") #Create conflicting Data Difficulties. dataDiffs: List[SignedDataDifficulty] = [ SignedDataDifficulty(3, 0), SignedDataDifficulty(4, 0) ] dataDiffs[0].sign(0, blsPrivKey) dataDiffs[1].sign(0, blsPrivKey) #Create a MeritRemoval out of the conflicting Data Difficulties. mr: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[0], dataDiffs[1]) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [mr]), 1, bytes(4), bytes(32), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([], [mr], mr.signature)) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Hundred Twenty Three Swap Block " + str(len(blockchain.blocks)) + ".") #Create a MeritRemoval with the Elements swapped. swapped: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[1], dataDiffs[0]) #Generate a Block containing the swapped MeritRemoval.
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key() #BLS Private Key. blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest()) #Create a Data for the VerificationPacket. data: Data = Data(bytes(32), edPubKey.to_bytes()) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Generate the VerificationPacket Block. block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([], [VerificationPacket(data.hash, [1])]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(data.hash, [1])]), blsPrivKey.toPublicKey().serialize(), blockchain.blocks[-1].header.time + 1200), BlockBody([VerificationPacket(data.hash, [1])], [], blsPrivKey.sign(b""))) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it to the vectors. blocks.append(block.toJSON()) print("Generated Hundred Six Block Elements VerificationPacket Block.") #Generate the SendDifficulty Block. elements: List[Element] = []
#Add it. blockchain.add(block) print("Generated Hundred Twenty Block " + str(len(blockchain.blocks)) + ".") #Create a DataDifficulty. dataDiff: SignedDataDifficulty = SignedDataDifficulty(3, 0) dataDiff.sign(0, blsPrivKey) #Create a conflicting DataDifficulty with the same nonce. dataDiffConflicting = SignedDataDifficulty(1, 0) dataDiffConflicting.sign(0, blsPrivKey) #Generate a Block containing the competing Data difficulty. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [dataDiffConflicting]), 1, bytes(4), bytes(32), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([], [dataDiffConflicting], dataDiffConflicting.signature)) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Hundred Twenty Block " + str(len(blockchain.blocks)) + ".") result: Dict[str, Any] = { "blockchain": blockchain.toJSON(), "mempoolDataDiff": dataDiff.toSignedJSON(), "blockchainDataDiff": dataDiffConflicting.toJSON() }
bbFile.close() #BLS Keys. blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest()) blsPubKey: PublicKey = blsPrivKey.toPublicKey() #Create a DataDifficulty. dataDiff: SignedDataDifficulty = SignedDataDifficulty(bytes.fromhex("AA" * 32), 0) dataDiff.sign(0, blsPrivKey) #Generate a Block containing the DataDifficulty. block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([], [], [dataDiff]), 1, bytes(4), bytes(32), 0, blockchain.blocks[-1].header.time + 1200 ), BlockBody([], [dataDiff], dataDiff.signature) ) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated DataDifficulty Block " + str(len(blockchain.blocks)) + ".")
for data in datas: data.sign(edPrivKey) data.beat(spamFilter) #Create Verifications for all 3. verifs: List[SignedVerification] = [] for data in datas: verifs.append(SignedVerification(data.hash, 0)) verifs[-1].sign(0, blsPrivKey) #Create a MeritRemoval out of the conflicting Verifications. mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2]) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader(0, packetedChain.last(), BlockHeader.createContents([], [mr]), 1, bytes(4), bytes(32), 0, packetedChain.blocks[-1].header.time + 1200), BlockBody([], [mr], mr.signature)) #Mine it. block.mine(blsPrivKey, packetedChain.difficulty()) #Add it. packetedChain.add(block) print("Generated Hundred Twenty Three Packet Block 1 " + str(len(packetedChain.blocks)) + ".") #Create a MeritRemoval with random keys. packeted: SignedMeritRemoval = SignedMeritRemoval( SignedMeritRemovalVerificationPacket( SignedVerificationPacket(verifs[1].hash), [
data: Data = Data(bytes(32), edPubKey.to_bytes()) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Verify it. verif: SignedVerification = SignedVerification(data.hash) verif.sign(0, blsPrivKey) #Generate another 6 Blocks. #Next block should have a packet. block: Block = Block( BlockHeader( 0, merit.blockchain.last(), BlockHeader.createContents([], [VerificationPacket(verif.hash, [0])]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(verif.hash, [0])]), 0, merit.blockchain.blocks[-1].header.time + 1200 ), BlockBody([VerificationPacket(verif.hash, [0])], [], verif.signature) ) for _ in range(6): #Mine it. block.mine(blsPrivKey, merit.blockchain.difficulty()) #Add it. merit.add(block) print("Generated Claimed Mint Block " + str(len(merit.blockchain.blocks) - 1) + ".")
send: Send = Send( [(claim, 0), (claim, 0)], [(edPubKey.to_bytes(), Claim.fromTransaction(transactions.txs[claim]).amount * 2)]) send.sign(edPrivKey) send.beat(sendFilter) transactions.add(send) #Create a Verification/VerificationPacket for the Send. sv: SignedVerification = SignedVerification(send.hash) sv.sign(0, blsPrivKey) packet: VerificationPacket = VerificationPacket(send.hash, [0]) #Add a Block verifying it. block: Block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([packet]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [packet]), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([packet], [], sv.signature)) #Mine the Block. block.mine(blsPrivKey, blockchain.difficulty()) #Add the Block. blockchain.add(block) print("Generated Same Input Block " + str(len(blockchain.blocks) - 1) + ".") #Save the vector. result: Dict[str, Any] = { "blockchain": blockchain.toJSON(), "transactions": transactions.toJSON()
SignedMeritRemovalVerificationPacket( SignedVerificationPacket(verifs[1].hash), [ PrivateKey(blake2b( b'\1', digest_size=32).digest()).toPublicKey().serialize() ], PrivateKey(blake2b(b'\1', digest_size=32).digest()).sign( verifs[1].signatureSerialize())) ] #Create a MeritRemoval out of the conflicting Verifications. e1MR: SignedMeritRemoval = SignedMeritRemoval(verifs[1], packets[0], 0) e2MR: SignedMeritRemoval = SignedMeritRemoval(packets[1], verifs[2], 0) #Generate a Block containing the MeritRemoval for each chain. block = Block( BlockHeader(0, e1Chain.last(), BlockHeader.createContents([], [e1MR]), 1, bytes(4), bytes(32), 0, e1Chain.blocks[-1].header.time + 1200), BlockBody([], [e1MR], e1MR.signature)) block.mine(blsPrivKey, e1Chain.difficulty()) e1Chain.add(block) print("Generated Hundred Twenty Three Packet Block 1 " + str(len(e1Chain.blocks)) + ".") block = Block( BlockHeader(0, e2Chain.last(), BlockHeader.createContents([], [e2MR]), 1, bytes(4), bytes(32), 0, e2Chain.blocks[-1].header.time + 1200), BlockBody([], [e2MR], e2MR.signature)) block.mine(blsPrivKey, e2Chain.difficulty()) e2Chain.add(block) print("Generated Hundred Twenty Three Packet Block 2 " + str(len(e2Chain.blocks)) + ".")