nomos-specs/carnot/test_beacon_verification.py
Giacomo Pasini 255689151a
Random Beacon revision
This is a proposed revision of the random beacon specification.
First of all it fixes a few little mistakes in the signing
process:
* Use BasicSchemeMPL instead of PoPSchemeMPL since we don't use
  Proof of Possession.
* Hashing the values prior to the call to BasicSchemeMPL.sing()
  is not necessary. This step has been removed.

In addition, all data inside the random beacon state that
anyone willing to verify must know anyway has been removed.
In the current version this includes the 'context' and the public
key of the signer. The verifier has to independently check that
those values have been correctly obtained anyway, so there's no
need to include them in the state that is passed around.

Lastly, the beacon context view has been changed from using a
string encoding to a little endian variable-length encoding and
is now tied to qc.view instead of current_view of the processing
node.
2023-05-24 12:43:23 +02:00

40 lines
1.3 KiB
Python

from typing import Tuple
from unittest import TestCase
from beacon import *
from random import randint
class TestRandomBeaconVerification(TestCase):
@staticmethod
def happy_beacon_and_pk(view: View) -> Tuple[RandomBeacon, PublicKey]:
sk = generate_random_sk()
beacon = NormalMode.generate_beacon(sk, view)
return beacon, sk.get_g1()
@staticmethod
def unhappy_beacon(last_beacon: Entropy, view: View) -> RandomBeacon:
return RecoveryMode.generate_beacon(last_beacon, view)
def setUp(self):
beacon, pk = self.happy_beacon_and_pk(0)
self.beacon = RandomBeaconHandler(beacon)
def test_happy(self):
for i in range(3):
new_beacon, pk = self.happy_beacon_and_pk(i)
self.beacon.verify_happy(new_beacon, pk, i)
def test_unhappy(self):
for i in range(1, 3):
new_beacon = self.unhappy_beacon(self.beacon.last_beacon.entropy(), i)
self.beacon.verify_unhappy(new_beacon, i)
def test_mixed(self):
for i in range(1, 6, 2):
new_beacon, pk = self.happy_beacon_and_pk(i)
self.beacon.verify_happy(new_beacon, pk, i)
new_beacon = self.unhappy_beacon(self.beacon.last_beacon.entropy(), i+1)
self.beacon.verify_unhappy(new_beacon, i+1)