Beispiel #1
0
 def fromJSON(
     json: Dict[str, Any]
 ) -> Any:
     return Block(
         BlockHeader.fromJSON(json["header"]),
         BlockBody.fromJSON(json)
     )
Beispiel #2
0
    def __init__(
        self
    ) -> None:
        self.genesis: bytes = b"MEROS_DEVELOPER_NETWORK".rjust(32, b'\0')

        self.upcomingKey: bytes = self.genesis
        setRandomXKey(self.upcomingKey)

        self.blockTime: int = 60

        self.difficulties: List[int] = [100]

        self.blocks: List[Block] = [
            Block(
                BlockHeader(
                    0,
                    self.genesis,
                    bytes(32),
                    0,
                    bytes(4),
                    bytes(32),
                    PublicKey().serialize(),
                    0
                ),
                BlockBody()
            )
        ]

        self.keys: Dict[bytes, int] = {}
Beispiel #3
0
 def fromJSON(
     keys: Dict[bytes, int],
     json: Dict[str, Any]
 ) -> Any:
     return Block(
         BlockHeader.fromJSON(json["header"]),
         BlockBody.fromJSON(keys, json)
     )
Beispiel #4
0
#BLS Keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#SpamFilter.
spamFilter: SpamFilter = SpamFilter(5)

#Blockchain.
blockchain: Blockchain = Blockchain()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Verify Competing Block " + str(len(blockchain.blocks)) + ".")

#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)
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.
    block = Block(
        BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4),
                    bytes(32),
                    0, merit.blockchain.blocks[-1].header.time + 1200),
Beispiel #6
0
#BLS Keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#SpamFilter.
spamFilter: SpamFilter = SpamFilter(5)

#Blockchains.
packetedChain: Blockchain = Blockchain()
reorderedChain: Blockchain = Blockchain()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, packetedChain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(),
                packetedChain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
block.mine(blsPrivKey, packetedChain.difficulty())

#Add it.
packetedChain.add(block)
reorderedChain.add(block)
print("Generated Hundred Twenty Three Packet Block 1/2 " +
      str(len(packetedChain.blocks)) + ".")

#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)
Beispiel #7
0
#BLS Keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#SpamFilter.
spamFilter: SpamFilter = SpamFilter(5)

#Blockchains.
e1Chain: Blockchain = Blockchain()
e2Chain: Blockchain = Blockchain()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, e1Chain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(), e1Chain.blocks[-1].header.time + 1200),
    BlockBody())
#Mine it.
block.mine(blsPrivKey, e1Chain.difficulty())

#Add it.
e1Chain.add(block)
e2Chain.add(block)
print("Generated Hundred Thirty Three Block 1/2 " + str(len(e1Chain.blocks)) +
      ".")

#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)
Beispiel #8
0
from hashlib import blake2b

#JSON standard lib.
import json

#Blockchain.
blockchain: Blockchain = Blockchain()

#Miner Private Key.
privKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())

#Create the Block.
block: Block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                privKey.toPublicKey().serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())

#Generate blocks.
for i in range(1, 26):
    #Mine the Block.
    block.mine(privKey, blockchain.difficulty())

    #Add it locally.
    blockchain.add(block)
    print("Generated Blank Block " + str(i) + ".")

    #Create the next Block.
    block = Block(
        BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 0,
                    blockchain.blocks[-1].header.time + 1200), BlockBody())
Beispiel #9
0
data.beat(dataFilter)

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

#Create packets out of the Verification.
packets: List[VerificationPacket] = [VerificationPacket(data.hash, [0])]

#Generate another Block.
block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([],
                                                                 packets), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 0,
                blockchain.blocks[-1].header.time + 1200),
    BlockBody(packets, [], sv.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Parsable Block " + str(len(blockchain.blocks)) + ".")

result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "data": data.toJSON()
}
vectors: IO[Any] = open(
    "PythonTests/Vectors/Consensus/Verification/Parsable.json", "w")
vectors.write(json.dumps(result))
vectors.close()
Beispiel #10
0
#Ed25519 keys.
edPrivKey1: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey1: ed25519.VerifyingKey = edPrivKey1.get_verifying_key()
edPubKey2: ed25519.VerifyingKey = ed25519.SigningKey(b'\1' * 32).get_verifying_key()

#BLS keys.
blsPrivKey1: blspy.PrivateKey = blspy.PrivateKey.from_seed(b'\0')
blsPubKey1: blspy.PublicKey = blsPrivKey1.get_public_key()
blsPrivKey2: blspy.PrivateKey = blspy.PrivateKey.from_seed(b'\1')
blsPubKey2: blspy.PublicKey = blsPrivKey2.get_public_key()

#Give the second key pair Merit.
block: Block = Block(
    BlockHeader(13, blockchain.last(), int(time())),
    BlockBody([], [(blsPubKey2, 100)])
)
block.mine(blockchain.difficulty())
blockchain.add(block)
print("Generated Competing Block " + str(block.header.nonce) + ".")

#Grab the claim hash.
claim: bytes = Verification.fromElement(consensus.holders[blsPubKey1.serialize()][1]).hash

#Create two competing Sends.
send1: Send = Send(
    [(claim, 0)],
    [(
        edPubKey1.to_bytes(),
        Claim.fromTransaction(transactions.txs[claim]).amount
    )]
Beispiel #11
0
#JSON standard lib.
import json

#Blockchain.
blockchain: Blockchain = Blockchain()

#BLS Keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
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)
Beispiel #12
0
#JSON standard lib.
import json

#Blockchain.
blockchain: Blockchain = Blockchain()

#BLS Keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#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)
Beispiel #13
0
    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.
for i in range(3, 7):
    block = Block(BlockHeader(i, blockchain.last(), int(time())), BlockBody())
    #Mine it.
    block.mine(blockchain.difficulty())

    #Add it.
    blockchain.add(block)
Beispiel #14
0
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)) + ".")

#Mine 24 more Blocks until there's a vote.
for _ in range(24):
    block = Block(
        BlockHeader(
            0,
            blockchain.last(),
            bytes(32),
Beispiel #15
0
 def blockBody(self, body: BlockBody) -> bytes:
     res: bytes = (MessageType.BlockBody.toByte() + body.serialize())
     self.send(res)
     return res
Beispiel #16
0
    PrivateKey(blake2b(b'\0', digest_size=32).digest()),
    PrivateKey(blake2b(b'\1', digest_size=32).digest())
]
blsPubKeys: List[PublicKey] = [
    blsPrivKeys[0].toPublicKey(), blsPrivKeys[1].toPublicKey()
]

#Add 4 Blank Blocks.
for i in range(4):
    merit.add(Block.fromJSON(merit.blockchain.keys, blankBlocks[i]))

#Add a 5th Block to another verifier.
block: Block = Block(
    BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKeys[1].serialize(),
                merit.blockchain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
block.mine(blsPrivKeys[1], merit.blockchain.difficulty())

#Add it.
merit.add(block)
print("Generated Aggregated Claim Block " +
      str(len(merit.blockchain.blocks) - 1) + ".")

#Create the Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[-1].hash, bytes(1)))
datas.append(Data(datas[-1].hash, bytes(1)))
datas.append(Data(datas[-1].hash, bytes(1)))
for data in datas:
    data.sign(edPrivKey)
Beispiel #17
0
#Blockchain.
blockchain: Blockchain = Blockchain()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(
        0,
        blockchain.last(),
        bytes(32),
        1,
        bytes(4),
        bytes(32),
        blsPubKey.serialize(),
        blockchain.blocks[-1].header.time + 1200
    ),
    BlockBody()
)
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Verify Competing Block " + str(len(blockchain.blocks)) + ".")

#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)
Beispiel #18
0
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#Create a DataDifficulty.
dataDiffs: List[SignedDataDifficulty] = [
    SignedDataDifficulty(3, 0),
    SignedDataDifficulty(1, 1)
]
for dataDiff in dataDiffs:
    dataDiff.sign(0, blsPrivKey)

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

#Add it.
blockchain.add(block)
print("Generated DataDifficulty Block " + str(len(blockchain.blocks)) + ".")

#Mine 24 more Blocks until there's a vote.
for _ in range(24):
    block = Block(
        BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 0,
                    blockchain.blocks[-1].header.time + 1200), BlockBody())
    block.mine(blsPrivKey, blockchain.difficulty())
    blockchain.add(block)
    print("Generated DataDifficulty Block " + str(len(blockchain.blocks)) +
Beispiel #19
0
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] = []
elements.append(SendDifficulty(0, 0, 1))
block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([],
                                                                 elements), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), []),
                blsPrivKey.toPublicKey().serialize(),
Beispiel #20
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)
    print("Generated Fifty Block " + str(len(blockchain.blocks) - 1) + ".")

#Generate another 5 Blocks.
for _ in range(5):
Beispiel #21
0
#Blockchains.
main: Blockchain = Blockchain()
alt: Blockchain = Blockchain()

#Miner Private Keys.
privKeys: List[PrivateKey] = [
    PrivateKey(blake2b(b'\0', digest_size=32).digest()),
    PrivateKey(blake2b(b'\1', digest_size=32).digest())
]

#Create the Block to the first miner.
block: Block = Block(
    BlockHeader(0, main.last(), bytes(32), 1, bytes(4), bytes(32),
                privKeys[0].toPublicKey().serialize(),
                main.blocks[-1].header.time + 1200), BlockBody())
block.mine(privKeys[0], main.difficulty())
main.add(block)
alt.add(block)
print("Generated Reorganizations Depth One Block 1.")

#Create the Block to the second miner.
block = Block(
    BlockHeader(0, main.last(), bytes(32), 1, bytes(4), bytes(32),
                privKeys[1].toPublicKey().serialize(),
                main.blocks[-1].header.time + 1200), BlockBody())
block.mine(privKeys[1], alt.difficulty())
main.add(block)
alt.add(block)
print("Generated Reorganizations Depth One Block 2.")
#Generate an alternative fifteen Blocks.
for i in range(1, 15):
    #Create the next Block.
    block = Block(
        BlockHeader(
            0,
            alt.last(),
            bytes(32),
            1,
            bytes(4),
            bytes(32),
            0,
            alt.blocks[-1].header.time + 1201 #Use a slightly different time to ensure a different hash.
        ),
        BlockBody()
    )

    #Mine the Block.
    block.mine(privKey, alt.difficulty())

    #Add it locally.
    alt.add(block)
    print("Generated Longer Chain, More Work Block " + str(i) + ".")

vectors: IO[Any] = open("PythonTests/Vectors/Merit/Reorganizations/LongerChainMoreWork.json", "w")
vectors.write(json.dumps({
    "main": main.toJSON(),
    "alt": alt.toJSON()
}))
vectors.close()
Beispiel #23
0
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

#BLS keys.
blsPrivKeys: List[PrivateKey] = [
    PrivateKey(blake2b(b'\0', digest_size=32).digest()),
    PrivateKey(blake2b(b'\1', digest_size=32).digest())
]
blsPubKeys: List[PublicKey] = [
    blsPrivKeys[0].toPublicKey(), blsPrivKeys[1].toPublicKey()
]

#Give the first key Merit.
block: Block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKeys[0].serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())

#Mine it.
block.mine(blsPrivKeys[0], blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Hundred Forty Two Block " + str(len(blockchain.blocks)) + ".")

#Give the second key Merit.
block: Block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKeys[1].serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())
block.mine(blsPrivKeys[1], blockchain.difficulty())
blockchain.add(block)
Beispiel #24
0
blockchain.add(Block.fromJSON(vectors["blockchain"][0]))

consensus.add(SignedVerification.fromJSON(vectors["removal"]["elements"][0]))
removal: PartiallySignedMeritRemoval = PartiallySignedMeritRemoval.fromJSON(
    vectors["removal"])
removal.nonce = 1
consensus.add(removal)

snFile.close()

#Generate a Block with a verif and a Block with the removal.
for i in range(2):
    block: Block = Block(
        BlockHeader(i + 2, blockchain.last(), int(time()),
                    consensus.getAggregate([(pubKey, i, i)])),
        BlockBody([(pubKey, i, consensus.getMerkle(pubKey, i, i))]))

    #Mine it.
    block.mine(blockchain.difficulty())

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

result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "data": vectors["data"],
    "removal": removal.toSignedJSON()
}
partialFile: IO[Any] = open(
    "PythonTests/Vectors/Consensus/MeritRemoval/Partial.json", "w")
Beispiel #25
0
            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)
    print("Generated Fifty Block " + str(len(blockchain.blocks) - 1) + ".")

#Generate another 5 Blocks.
Beispiel #26
0
blsPrivKeys: List[PrivateKey] = [
    PrivateKey(blake2b(b'\0', digest_size=32).digest()),
    PrivateKey(blake2b(b'\1', digest_size=32).digest())
]
blsPubKeys: List[PublicKey] = [
    blsPrivKeys[0].toPublicKey(), blsPrivKeys[1].toPublicKey()
]

#Grab the claim hash.
claim: bytes = blockchain.blocks[-1].body.packets[0].hash

#Give the second key pair Merit.
block: Block = Block(
    BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKeys[1].serialize(),
                blockchain.blocks[-1].header.time + 1200), BlockBody())

#Mine it.
block.mine(blsPrivKeys[1], blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Competing Block " + str(len(blockchain.blocks)) + ".")

#Create two competing Sends.
packets: List[VerificationPacket] = []
toAggregate: List[Signature] = []
verif: SignedVerification
for i in range(2):
    send: Send = Send(
        [(claim, 0)],
Beispiel #27
0
#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.
    block = Block(
        BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4),
                    bytes(32),
                    0, merit.blockchain.blocks[-1].header.time + 1200),
        BlockBody())
Beispiel #28
0
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) + ".")

result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "data": snVectors["data"],
    "removal1": removal1.toSignedJSON(),
    "removal2": removal2.toSignedJSON()
}
vectors: IO[Any] = open(
    "PythonTests/Vectors/Consensus/MeritRemoval/Multiple.json", "w")
Beispiel #29
0
      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()
}
vectors: IO[Any] = open("PythonTests/Vectors/Transactions/SameInput.json", "w")
vectors.write(json.dumps(result))
Beispiel #30
0
    sends.append(
        Send([(sends[-1].hash, 0)],
             [(edPubKey.to_bytes(), sends[-1].outputs[0][1])]))

#Verify 0 and 1 in order.
order: List[int] = [0, 1]
verif: SignedVerification
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block: Block = Block(
    BlockHeader(13, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 2, -1)])),
    BlockBody([(blsPubKey1, 3, consensus.getMerkle(blsPubKey1, 2))]))
block.mine(blockchain.difficulty())
blockchain.add(block)
print("Generated Fifty Block " + str(block.header.nonce) + ".")

#Verify 3, and then 2, while giving Merit to a second Merit Holder.
order = [3, 2]
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block = Block(
    BlockHeader(14, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 4, -1)])),
    BlockBody([(blsPubKey1, 5, consensus.getMerkle(blsPubKey1, 4))],