Skip to content

Commit 35bdb72

Browse files
authored
Convert TicketEnvelope.attempt to VarInt64 (#256)
1 parent b4b9bbb commit 35bdb72

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

pyjamaz/models/block.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pyjamaz.exceptions import BlockValidationError
99

10-
from jamcodec.types import H256, U32, Option, Vec, Array, U8, U16, Bool, H512, Bytes, BitArray, Tuple
10+
from jamcodec.types import H256, U32, Option, Vec, Array, U8, U16, Bool, H512, Bytes, BitArray, Tuple, VarInt64
1111
from pyjamaz.graypaper_constants import VALIDATOR_COUNT, EPOCH_TIMESLOTS, CORE_COUNT
1212
from pyjamaz.hashing import blake2b_256_hash
1313
from pyjamaz.models.common import WorkReport, TicketBody, ValidatorData
@@ -44,19 +44,15 @@ class TicketEnvelope(Serializable):
4444
4545
Attributes
4646
----------
47-
attempt: U8
47+
attempt: VarInt64
4848
GP-0.7.2-eq:6.29 (e) | An entry index
4949
signature: Array(U8,784)
5050
GP-0.7.2-eq:6.29 (p) | Proof of a ticket's validity
5151
"""
52-
attempt: int = field(metadata={'codec': U8})
52+
attempt: int = field(metadata={'codec': VarInt64})
5353
signature: bytes = field(metadata={'codec': Array(U8, 784)})
5454

5555
def __post_init__(self):
56-
# Validate that attempt is a valid U8 integer
57-
if not isinstance(self.attempt, int) or not (0 <= self.attempt <= 255):
58-
raise BlockValidationError("Attempt must be an integer between 0 and 255")
59-
6056
# Validate that signature is a valid ByteArray784
6157
if not isinstance(self.signature, (bytes, bytearray)) or len(self.signature) != 784:
6258
raise BlockValidationError("Signature must be a bytes object of length 784")

pyjamaz/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from math import floor
88
from typing import List, Optional
99

10+
from jamcodec.types import VarInt64
1011
from pyjamaz.graypaper_constants import CORE_COUNT, VALIDATOR_COUNT, EPOCH_TIMESLOTS, ROTATION_PERIOD_CORE
1112

1213
from pyjamaz.hashing import blake2b_256_hash
@@ -149,7 +150,7 @@ def substitute_if_nothing(*args) -> Optional[any]:
149150

150151

151152
def vrf_input_ticket_seal(entropy: bytes, ticket_attempt: int) -> bytes:
152-
return b"jam_ticket_seal" + entropy + int.to_bytes(ticket_attempt, byteorder='little', length=1)
153+
return b"jam_ticket_seal" + entropy + VarInt64.encode(ticket_attempt).to_bytes()
153154

154155

155156
def vrf_input_fallback_seal(entropy: bytes) -> bytes:

0 commit comments

Comments
 (0)