import ed25519

from e2e.Classes.Transactions.Transactions import Data, Transactions

from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

transactions: Transactions = Transactions()
dataFilter: SpamFilter = SpamFilter(5)

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

proto: PrototypeChain = PrototypeChain(1, keepUnlocked=False)

#Create the Data and a successor.
first: Data = Data(bytes(32), edPubKey.to_bytes())
first.sign(edPrivKey)
first.beat(dataFilter)
transactions.add(first)

second: Data = Data(first.hash, bytes(1))
second.sign(edPrivKey)
second.beat(dataFilter)
transactions.add(second)

proto.add(packets=[
    VerificationPacket(first.hash, [0]),
    VerificationPacket(second.hash, [0])
import json

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

alt: PrototypeChain = PrototypeChain(380, keepUnlocked=False)
alt.timeOffset = alt.timeOffset + 1
for _ in range(30):
    alt.add()

with open("e2e/Vectors/Merit/RandomX/ChainReorgDifferentKey.json",
          "w") as vectors:
    vectors.write(
        json.dumps({
            "main": PrototypeChain(400, keepUnlocked=False).toJSON(),
            "alt": alt.toJSON()
        }))
Exemple #3
0
import ed25519
from e2e.Libs.BLS import PrivateKey

from e2e.Classes.Transactions.Claim import Claim
from e2e.Classes.Transactions.Send import Send
from e2e.Classes.Transactions.Transactions import Transactions

from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Classes.Merit.Merit import Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

merit: Merit = PrototypeChain.withMint()
transactions: Transactions = Transactions()

sendFilter: SpamFilter = SpamFilter(3)

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKeys: List[ed25519.VerifyingKey] = [
    edPrivKey.get_verifying_key(),
    ed25519.SigningKey(b'\1' * 32).get_verifying_key()
]

#Create the Claim.
claim: Claim = Claim([(merit.mints[-1].hash, 0)], edPubKeys[0].to_bytes())
claim.amount = merit.mints[-1].outputs[0][1]
claim.sign(PrivateKey(0))
transactions.add(claim)
Exemple #4
0
from e2e.Classes.Transactions.Transactions import Data, Transactions

from e2e.Classes.Consensus.Verification import SignedVerification
from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

edPrivKey: Ristretto.SigningKey = Ristretto.SigningKey(b'\0' * 32)
edPubKey: bytes = edPrivKey.get_verifying_key()

transactions: Transactions = Transactions()
spamFilter: SpamFilter = SpamFilter(5)

proto = PrototypeChain(1, False)
proto.add(1)

data: Data = Data(bytes(32), edPubKey)
data.sign(edPrivKey)
data.beat(spamFilter)
transactions.add(data)

verif: SignedVerification = SignedVerification(data.hash)
verif.sign(1, PrivateKey(1))

proto.add(1, packets=[VerificationPacket(data.hash, [0])])
for _ in range(5):
    proto.add(1)

with open("e2e/Vectors/Consensus/Verification/HundredFortyTwo.json",
Exemple #5
0
from typing import Dict, List, IO, Any
import json

from e2e.Libs.BLS import PrivateKey, PublicKey

from e2e.Classes.Consensus.DataDifficulty import SignedDataDifficulty
from e2e.Classes.Consensus.MeritRemoval import SignedMeritRemoval

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

blsPrivKey: PrivateKey = PrivateKey(0)
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

proto: PrototypeChain = PrototypeChain(1, False)

#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])
proto.add(elements=[mr])

#Create a MeritRemoval with the Elements swapped.
swapped: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[1], dataDiffs[0])
proto.add(elements=[swapped])
from typing import Dict, List, Any
import json

from e2e.Libs.BLS import PrivateKey
from e2e.Classes.Merit.Merit import Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

root: List[Dict[str, Any]] = PrototypeChain(9, False).finish().toJSON()
main: Merit = Merit.fromJSON(root)
alt: Merit = Merit.fromJSON(root)

for _ in range(2):
    main.add(
        PrototypeBlock(main.blockchain.blocks[-1].header.time + 1200).finish(
            0, main))

#Create a fork Block with a lower hash.
#Same principle as DepthOne.
hashAsInt: int = int.from_bytes(main.blockchain.blocks[-2].header.hash,
                                "little")
k: int = 1
while int.from_bytes(
        PrototypeBlock(alt.blockchain.blocks[-1].header.time + 1200,
                       minerID=PrivateKey(k)).finish(0, alt).header.hash,
        "little") > hashAsInt:
    k += 1
alt.add(
    PrototypeBlock(alt.blockchain.blocks[-1].header.time + 1200,
                   minerID=PrivateKey(k)).finish(0, alt))
Exemple #7
0
from typing import IO, Any
from random import seed, getrandbits
import json

from e2e.Classes.Merit.State import State

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

#Ensure consistent vectors.
seed(1)

chain: PrototypeChain = PrototypeChain(1)
miners: int = 1

#State is used solely to get the lifetime.
#This test only has significance when Dead Merit is also tested.
for _ in range(State().lifetime * 3):
  #Why manually specify hundreds of miners when we can randomize it?
  nextMiner: int = getrandbits(8) % miners
  #If the nextMiner is 0, it's either trying to use the original miner or a new miner.
  #Create a 50% chance of creating a new miner.
  if (nextMiner == 0) and (getrandbits(1) == 1):
    nextMiner = miners
  chain.add(nextMiner)

vectors: IO[Any] = open("e2e/Vectors/Merit/State.json", "w")
vectors.write(json.dumps(chain.toJSON()))
vectors.close()
Exemple #8
0
from typing import IO, Any
import json

from e2e.Classes.Merit.Merit import Blockchain, Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

protoRoot: PrototypeChain = PrototypeChain(1, False)
protoRoot.add(1)
root: Blockchain = protoRoot.finish()

main: Merit = Merit.fromJSON(root.toJSON())
alt: Merit = Merit.fromJSON(root.toJSON())

main.add(
    PrototypeBlock(main.blockchain.blocks[-1].header.time + 1200).finish(
        0, main))

#Create the competing Block to the second miner.
#Since the difficulty is fixed at the start, they're guaranteed to have the same amount of work.
#Because of that, we can't just mine the Block; we need to mine it until it has a lower hash than the above Block.
#Calculate a custom difficulty guaranteed to beat the above Block.
hashAsInt: int = int.from_bytes(main.blockchain.blocks[-1].header.hash,
                                "little")
alt.blockchain.difficulties[-1] = 0
while (alt.blockchain.difficulties[-1] * hashAsInt).bit_length() <= 256:
    alt.blockchain.difficulties[-1] += 1

alt.add(
    PrototypeBlock(alt.blockchain.blocks[-1].header.time + 1200,
                   minerID=1).finish(0, alt))
Exemple #9
0
import json

from e2e.Classes.Consensus.DataDifficulty import DataDifficulty

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

keepsUnlockedViaElements: PrototypeChain = PrototypeChain(1, False)
for b in range(24):
    keepsUnlockedViaElements.add(elements=[DataDifficulty(b, b, 0)])

with open("e2e/Vectors/Merit/LockedMerit/KeepUnlocked.json", "w") as vectors:
    vectors.write(
        json.dumps(
            [PrototypeChain(25).toJSON(),
             keepsUnlockedViaElements.toJSON()]))
Exemple #10
0
import json

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

main: PrototypeChain = PrototypeChain(2)

alt: PrototypeChain = PrototypeChain(1)
alt.timeOffset = alt.timeOffset + 1
for _ in range(2):
    alt.add()

with open("e2e/Vectors/Merit/Reorganizations/TwoHundredThirtyTwo.json",
          "w") as vectors:
    vectors.write(json.dumps({"main": main.toJSON(), "alt": alt.toJSON()}))
Exemple #11
0
from e2e.Classes.Consensus.Verification import SignedVerification
from e2e.Classes.Consensus.VerificationPacket import SignedVerificationPacket, SignedMeritRemovalVerificationPacket
from e2e.Classes.Consensus.MeritRemoval import SignedMeritRemoval
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

blsPrivKey: PrivateKey = PrivateKey(0)
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

spamFilter: SpamFilter = SpamFilter(5)

packetedChain: PrototypeChain = PrototypeChain(1, False)
reorderedChain: PrototypeChain = PrototypeChain(1, False)

#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 the competing Datas.
verifs: List[SignedVerification] = []
for d in range(1, len(datas)):
  verifs.append(SignedVerification(datas[d].hash, 0))
  verifs[-1].sign(0, blsPrivKey)
Exemple #12
0
import json

from e2e.Libs.BLS import PrivateKey

from e2e.Classes.Merit.Merit import Blockchain, Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

secondPrivKey: PrivateKey = PrivateKey(1)

root: Blockchain = PrototypeChain(5, False).finish()

main: Merit = Merit.fromJSON(root.toJSON())
main.add(
    PrototypeBlock(main.blockchain.blocks[-1].header.time + 1200,
                   minerID=secondPrivKey).finish(0, main))

alt: Merit = Merit.fromJSON(root.toJSON())
alt.add(
    PrototypeBlock(alt.blockchain.blocks[-1].header.time + 1200).finish(
        0, alt))
alt.add(
    PrototypeBlock(alt.blockchain.blocks[-1].header.time + 1200,
                   minerID=secondPrivKey).finish(1, alt))

with open("e2e/Vectors/Merit/Reorganizations/DelayedMeritHolder.json",
          "w") as vectors:
    vectors.write(json.dumps({"main": main.toJSON(), "alt": alt.toJSON()}))
Exemple #13
0
from typing import Dict, List, Any
import json

import e2e.Libs.Ristretto.Ristretto as Ristretto
from e2e.Libs.BLS import PrivateKey

from e2e.Classes.Transactions.Transactions import Claim, Send, Transactions
from e2e.Classes.Consensus.SpamFilter import SpamFilter
from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Merit.Merit import Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

merit: Merit = Merit.fromJSON(PrototypeChain(47).toJSON())
transactions: Transactions = Transactions()

privKey: Ristretto.SigningKey = Ristretto.SigningKey(b'\0' * 32)
pubKey: bytes = privKey.get_verifying_key()

recipientPriv: Ristretto.SigningKey = Ristretto.SigningKey(b'\1' * 32)
recipientPub: bytes = recipientPriv.get_verifying_key()

olderClaim: Claim = Claim([(merit.mints[-1], 0)], pubKey)
olderClaim.sign(PrivateKey(0))
transactions.add(olderClaim)

merit.add(
  PrototypeBlock(
    merit.blockchain.blocks[-1].header.time + 1200,
    packets=[VerificationPacket(olderClaim.hash, [0])]
  ).finish(0, merit)
Exemple #14
0
from e2e.Classes.Transactions.Data import Data
from e2e.Classes.Transactions.Transactions import Transactions

from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

transactions: Transactions = Transactions()
spamFilter: SpamFilter = SpamFilter(5)

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

proto: PrototypeChain = PrototypeChain(5)
for _ in range(80):
    proto.add(1)

for _ in range(14):
    proto.add(2)

data: Data = Data(bytes(32), edPubKey.to_bytes())
data.sign(edPrivKey)
data.beat(spamFilter)
transactions.add(data)

proto.add(2, [VerificationPacket(data.hash, [0, 1])])

#Close out the Epoch.
for _ in range(6):
from typing import IO, Any
import json

from e2e.Classes.Consensus.SendDifficulty import SendDifficulty
from e2e.Classes.Consensus.DataDifficulty import DataDifficulty

from e2e.Classes.Merit.Merit import Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

merit: Merit = Merit.fromJSON(PrototypeChain(49).finish().toJSON())

#Add the Difficulties.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   elements=[SendDifficulty(2, 0, 0),
                             DataDifficulty(2, 1, 0)],
                   minerID=0).finish(0, merit))

#Close out this, and the next, Checkpoint period to lock our Merit.
for _ in range(9):
    merit.add(
        PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                       minerID=0).finish(0, merit))

#Become Pending.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   minerID=0).finish(1, merit))

vectors: IO[Any] = open("e2e/Vectors/Consensus/Difficulties/LockedMerit.json",
from typing import IO, Any
import json

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

main: PrototypeChain = PrototypeChain(4, False)
alt: PrototypeChain = PrototypeChain(2, False, main.timeOffset + 1)

vectors: IO[Any] = open("e2e/Vectors/Merit/Reorganizations/TwoHundredThirtySeven.json", "w")
vectors.write(json.dumps({
  "main": main.toJSON(),
  "alt": alt.toJSON()
}))
vectors.close()
from typing import IO, Any
import json

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

main: PrototypeChain = PrototypeChain(25, False)
alt: PrototypeChain = PrototypeChain(15, False)

#Update the time of the alt chain to be longer, causing a lower amount of work per Block.
#Compensate by adding more Blocks overall.
alt.timeOffset = 1201
for _ in range(14):
  alt.add()

vectors: IO[Any] = open("e2e/Vectors/Merit/Reorganizations/LongerChainMoreWork.json", "w")
vectors.write(json.dumps({
  "main": main.toJSON(),
  "alt": alt.toJSON()
}))
vectors.close()
Exemple #18
0
#This used to be a dependency for other generators.
#Now, it's solely used by tests who need a blank chain.

from typing import IO, Any
import json

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

vectors: IO[Any] = open("e2e/Vectors/Merit/BlankBlocks.json", "w")
vectors.write(json.dumps(PrototypeChain(25, keepUnlocked=False).toJSON()))
vectors.close()
Exemple #19
0
from typing import IO, Any
from random import seed, getrandbits
import json

from e2e.Classes.Merit.Blockchain import Blockchain

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

#Ensure consistent vectors.
seed(1)

chain: PrototypeChain = PrototypeChain(keepUnlocked=False)

blockTime: int = Blockchain().blockTime
for _ in range(100):
  #Change the time offset to ensure quality difficulty calculation..
  chain.timeOffset = max(getrandbits(32) % (blockTime * 3), blockTime // 2)
  chain.add()

vectors: IO[Any] = open("e2e/Vectors/Merit/Difficulty.json", "w")
vectors.write(json.dumps(chain.toJSON()))
vectors.close()
Exemple #20
0
from e2e.Libs.BLS import PrivateKey

from e2e.Classes.Transactions.Data import Data

from e2e.Classes.Consensus.Verification import SignedVerification
from e2e.Classes.Consensus.VerificationPacket import VerificationPacket
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

dataFilter: SpamFilter = SpamFilter(5)

edPrivKey: Ristretto.SigningKey = Ristretto.SigningKey(b'\0' * 32)
edPubKey: bytes = edPrivKey.get_verifying_key()

proto: PrototypeChain = PrototypeChain(40, keepUnlocked=True)
proto.add(1)

datas: List[Data] = [Data(bytes(32), edPubKey)]
for d in range(2):
  datas.append(Data(datas[0].hash, d.to_bytes(1, "little")))
for data in datas:
  data.sign(edPrivKey)
  data.beat(dataFilter)

verif: SignedVerification = SignedVerification(datas[1].hash)
verif.sign(0, PrivateKey(0))
proto.add(
  packets=[
    VerificationPacket(datas[0].hash, [0]),
    VerificationPacket(datas[2].hash, [1])
from e2e.Classes.Consensus.VerificationPacket import SignedVerificationPacket, SignedMeritRemovalVerificationPacket
from e2e.Classes.Consensus.MeritRemoval import SignedMeritRemoval

from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

blsPrivKey: PrivateKey = PrivateKey(0)
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

spamFilter: SpamFilter = SpamFilter(5)

e1Chain: PrototypeChain = PrototypeChain(1, False)
e2Chain: PrototypeChain = PrototypeChain(1, False)

#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)