Exemple #1
0
transactions.add(claim)

#Verify the Claim.
verif = SignedVerification(claim.hash)
verif.sign(0, blsPrivKey)

#Create a Send using the same input as the Claim.
send: Send = Send([(merit.mints[0].hash, 0)], [(edPubKey.to_bytes(), 1)])
transactions.add(send)

#Verify the Send.
competingVerif: SignedVerification = SignedVerification(send.hash)
competingVerif.sign(0, blsPrivKey)

#Create a MeritRemoval out of the conflicting Verifications.
mr: SignedMeritRemoval = SignedMeritRemoval(verif, competingVerif)

#Generate a Block containing the MeritRemoval.
block = Block(
    BlockHeader(0, merit.blockchain.last(),
                BlockHeader.createContents([], [], [mr]), 1, bytes(4),
                BlockHeader.createSketchCheck(bytes(4), []), 0,
                merit.blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [mr], mr.signature))
#Mine it.
block.mine(blsPrivKey, merit.blockchain.difficulty())

#Add it.
merit.blockchain.add(block)
print("Generated Invalid Competing Block " +
      str(len(merit.blockchain.blocks)) + ".")
Exemple #2
0
#Create the initial Data and two competing Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
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)) + ".")
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
    data.sign(edPrivKey)
    data.beat(spamFilter)

#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,
Exemple #4
0
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
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] = {
Exemple #5
0
#Load a Multiple Block and load their MeritRemoval.
snFile: IO[Any] = open(
    "PythonTests/Vectors/Consensus/MeritRemoval/SameNonce.json", "r")
snVectors: Dict[str, Any] = json.loads(snFile.read())

blockchain.add(Block.fromJSON(snVectors["blockchain"][0]))

removal1: SignedMeritRemoval = SignedMeritRemoval.fromJSON(
    snVectors["removal"])

snFile.close()

#Create a second MeritRemoval.
sv: SignedVerification = SignedVerification(b'\1' * 48)
sv.sign(privKey, 0)
removal2: SignedMeritRemoval = SignedMeritRemoval(
    removal1.se1, SignedElement.fromElement(sv))

#Add the second MeritRemoval to Consensus.
consensus.add(removal2)

#Generate a Block with the second MeritRemoval.
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, -1)])),
    BlockBody([(pubKey, 0, consensus.getMerkle(pubKey, 0))]))
#Mine it.
block.mine(blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Multiple Block " + str(block.header.nonce) + ".")
Exemple #6
0
#Add it.
blockchain.add(block)
print("Generated Hundred Twenty Three Swap Block " +
      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)) + ".")
Exemple #7
0
        Data(edPrivKey.get_verifying_key().to_bytes().rjust(48, b'\0'),
             bytes()))
    datas[-1].sign(edPrivKey)
    datas[-1].beat(consensus.dataFilter)

#Create 1 Verification per Data.
verifs: List[SignedVerification] = []
for d in range(len(datas)):
    verifs.append(SignedVerification(datas[d].hash))
    verifs[-1].sign(privKey, d)
    consensus.add(verifs[-1])

#Create a MeritRemoval off the last one.
sv: SignedVerification = SignedVerification(b'\0' * 48)
sv.sign(privKey, 5)
removal: SignedMeritRemoval = SignedMeritRemoval(
    SignedElement.fromElement(verifs[5]), SignedElement.fromElement(sv))
consensus.add(removal)

#Generate a Block with the Verifications.
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, 5)])),
    BlockBody([(pubKey, 5, consensus.getMerkle(pubKey, 0, 5))]))
#Mine it.
block.mine(blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Pending Actions Block " + str(block.header.nonce) + ".")

#Generate 4 more Blocks.
Exemple #8
0
blockchain.add(Block.fromJSON(blocks[0]))
bbFile.close()

#Create a Data to verify.
data: Data = Data(edPubKey.to_bytes().rjust(48, b'\0'), bytes())
data.sign(edPrivKey)
data.beat(consensus.dataFilter)

#Create two Verifications with the same nonce, yet for the different Datas.
sv1: SignedVerification = SignedVerification(data.hash)
sv1.sign(privKey, 0)

sv2: SignedVerification = SignedVerification(b'\0' * 48)
sv2.sign(privKey, 0)

removal: SignedMeritRemoval = SignedMeritRemoval(
    SignedElement.fromElement(sv1), SignedElement.fromElement(sv2))
consensus.add(removal)

#Generate another Block.
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, -1)])),
    BlockBody([(pubKey, 0, consensus.getMerkle(pubKey, 0))]))
#Mine it.
block.mine(blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Same Nonce Block " + str(block.header.nonce) + ".")

result: Dict[str, Any] = {
Exemple #9
0
            PrivateKey(blake2b(
                b'\1', digest_size=32).digest()).toPublicKey().serialize()
        ],
        PrivateKey(blake2b(b'\1', digest_size=32).digest()).sign(
            verifs[1].signatureSerialize())),
    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),
Exemple #10
0
#Generate a Block containing the partial MeritRemoval.
block = Block(
    BlockHeader(0, blockchain.last(),
                BlockHeader.createContents([], [partial]), 1, bytes(4),
                bytes(32), 0, blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [partial], partial.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Hundred Twenty Three Partial Block " +
      str(len(blockchain.blocks)) + ".")

#Create a MeritRemoval which isn't partial.
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 Partial Block " +
      str(len(blockchain.blocks)) + ".")
Exemple #11
0
data.sign(edPrivKey)
data.beat(SpamFilter(5))

#Create a Verification.
verif: SignedVerification = SignedVerification(data.hash)
verif.sign(0, blsPrivKey)

#Create a MeritRemovalVerificationPacket verifying the same Transaction as the Verification.
packet: SignedMeritRemovalVerificationPacket = SignedMeritRemovalVerificationPacket(
    SignedVerificationPacket(data.hash),
    [blsPubKey.serialize()],
    verif.signature
)

#Create the three MeritRemovals.
sendDiffMR: SignedMeritRemoval = SignedMeritRemoval(sendDiff, sendDiff)
dataDiffMR: SignedMeritRemoval = SignedMeritRemoval(dataDiff, dataDiff)
verifMR: SignedMeritRemoval = SignedMeritRemoval(verif, packet)

result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "removals": [
        sendDiffMR.toSignedJSON(),
        dataDiffMR.toSignedJSON(),
        verifMR.toSignedJSON()
    ],
    "data": data.toJSON()
}
vectors: IO[Any] = open("PythonTests/Vectors/Consensus/MeritRemoval/SameElement.json", "w")
vectors.write(json.dumps(result))
vectors.close()