Skip to content

Commit

Permalink
Merge pull request #5 from trilitech/ajinkyaraj-23@4-add-attestation+…
Browse files Browse the repository at this point in the history
…dal-support

add attestation+dal support
  • Loading branch information
ajinkyaraj-23 authored Jan 26, 2024
2 parents 4213636 + 371f1ab commit c3e33cb
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2
VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-)
APPVERSION_M=2
APPVERSION_N=4
APPVERSION_P=6
APPVERSION_P=7
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# Only warn about version tags if specified/inferred
Expand Down
1 change: 1 addition & 0 deletions src/baking_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ bool parse_consensus_operation(parsed_baking_data_t *const out,
return true;
case 20: // tenderbake preendorsement
case 21: // tenderbake endorsement
case 23: // tenderbake endorsement + DAL
if (length < sizeof(struct tenderbake_consensus_op_wire)) return false;
struct tenderbake_consensus_op_wire const *const tb_op = data;
out->is_tenderbake = true;
Expand Down
49 changes: 48 additions & 1 deletion test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from utils.message import (
Preattestation,
Attestation,
AttestationDal,
Fitness,
BlockHeader,
Block
Expand All @@ -35,7 +36,7 @@
def test_version(client: TezosClient) -> None:
"""Test the VERSION instruction."""

expected_version = Version(Version.AppKind.BAKING, 2, 4, 6)
expected_version = Version(Version.AppKind.BAKING, 2, 4, 7)

version = client.version()

Expand Down Expand Up @@ -397,6 +398,52 @@ def test_sign_attestation(
account.check_signature(signature, bytes(attestation))


@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_attestation_dal(
account: Account,
with_hash: bool,
client: TezosClient,
firmware: Firmware,
navigator: Navigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on attestation."""

main_chain_id: int = 0
main_hwm = Hwm(0)
test_hwm = Hwm(0)

instructions = get_setup_app_context_instructions(firmware)

send_and_navigate(
send=lambda: client.setup_app_context(
account,
main_chain_id,
main_hwm,
test_hwm),
navigate=lambda: navigator.navigate(instructions))

attestation = AttestationDal(
chain_id=main_chain_id,
branch="0000000000000000000000000000000000000000000000000000000000000000",
slot=0,
op_level=0,
op_round=0,
block_payload_hash="0000000000000000000000000000000000000000000000000000000000000000",
dal_message="0000000000000000000000000000000000000000000000000000000000000000"
)

if with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))




@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_block(
Expand Down
66 changes: 54 additions & 12 deletions test/python/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class ConsensusProtocol(IntEnum):
class OperationTag(IntEnum):
"""Class representing the operation tag."""

PROPOSAL = 5
BALLOT = 6
BABYLON_REVEAL = 107
BABYLON_TRANSACTION = 108
BABYLON_ORIGINATION = 109
BABYLON_DELEGATION = 110
ATHENS_REVEAL = 7
ATHENS_TRANSACTION = 8
ATHENS_ORIGINATION = 9
ATHENS_DELEGATION = 10
PREATTESTATION = 20
ATTESTATION = 21
PROPOSAL = 5
BALLOT = 6
BABYLON_REVEAL = 107
BABYLON_TRANSACTION = 108
BABYLON_ORIGINATION = 109
BABYLON_DELEGATION = 110
ATHENS_REVEAL = 7
ATHENS_TRANSACTION = 8
ATHENS_ORIGINATION = 9
ATHENS_DELEGATION = 10
PREATTESTATION = 20
ATTESTATION = 21
ATTESTATION_WITH_DAL = 23

class Preattestation(Message):
"""Class representing a preattestation."""
Expand Down Expand Up @@ -168,6 +169,47 @@ def raw(self) -> bytes:
raw += self.block_payload_hash
return raw

class AttestationDal(Message):
"""Class representing an attestation + DAL."""
chain_id: int
branch: bytes
slot: int
op_level: int
op_round: int
block_payload_hash: bytes
dal_message: bytes

def __init__(self,
chain_id: int,
branch: Union[str,bytes],
slot: int,
op_level: int,
op_round: int,
block_payload_hash: Union[str,bytes],
dal_message: Union[str,bytes]):
self.chain_id = chain_id
self.branch = scrub(branch)
assert_data_size("branch", self.branch, 32)
self.slot = slot
self.op_level = op_level
self.op_round = op_round
self.block_payload_hash = scrub(block_payload_hash)
assert_data_size("block_payload_hash", self.block_payload_hash, 32)
self.dal_message = scrub(dal_message)

def raw(self) -> bytes:
raw = b''
raw += MagicByte.TENDERBAKE_ENDORSEMENT.to_bytes(1, byteorder='big')
raw += self.chain_id.to_bytes(4, byteorder='big')
raw += self.branch
raw += OperationTag.ATTESTATION_WITH_DAL.to_bytes(1, byteorder='big')
raw += self.slot.to_bytes(2, byteorder='big')
raw += self.op_level.to_bytes(4, byteorder='big')
raw += self.op_round.to_bytes(4, byteorder='big')
raw += self.block_payload_hash
raw += self.dal_message
return raw

class Fitness:
"""Class representing a fitness."""
level: int
Expand Down

0 comments on commit c3e33cb

Please sign in to comment.