From 50ae3b08e1b877c17868d00963b74c901b2d5e51 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 16 Jan 2025 06:09:27 +0100 Subject: [PATCH 1/8] Proto/DAL: use Raw_level instead of Level in error for consistency --- src/proto_alpha/lib_protocol/validate.ml | 2 +- src/proto_alpha/lib_protocol/validate_errors.ml | 6 +++--- src/proto_alpha/lib_protocol/validate_errors.mli | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index bc0220e6e78e..ff3d1e2e90dc 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1721,7 +1721,7 @@ module Anonymous = struct let*? () = error_unless (not already_denounced) - (Dal_already_denounced {delegate; level}) + (Dal_already_denounced {delegate; level = level.level}) in let traps_fraction = (Constants.parametric ctxt).dal.traps_fraction in let*? is_trap = diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index dc59f2460e68..fad54e35aea7 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -899,7 +899,7 @@ module Anonymous = struct | Invalid_shard_index of {given : int; min : int; max : int} | Dal_already_denounced of { delegate : Signature.Public_key_hash.t; - level : Level.t; + level : Raw_level.t; } | Denunciations_not_allowed_just_after_migration of { level : Raw_level.t; @@ -979,11 +979,11 @@ module Anonymous = struct entrapment." Signature.Public_key_hash.pp delegate - Level.pp + Raw_level.pp level) (obj2 (req "delegate" Signature.Public_key_hash.encoding) - (req "level" Level.encoding)) + (req "level" Raw_level.encoding)) (function | Dal_already_denounced {delegate; level} -> Some (delegate, level) | _ -> None) diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 7ec53da75fe9..108d3283d11b 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -160,7 +160,7 @@ module Anonymous : sig | Invalid_shard_index of {given : int; min : int; max : int} | Dal_already_denounced of { delegate : Signature.Public_key_hash.t; - level : Level.t; + level : Raw_level.t; } | Denunciations_not_allowed_just_after_migration of { level : Raw_level.t; -- GitLab From f68d4d283fadeb8bb185b7b78fefbd6b87259de1 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 15 Jan 2025 14:50:25 +0100 Subject: [PATCH 2/8] Proto/DAL: add accusation validation error when no DAL content --- src/proto_alpha/lib_protocol/validate.ml | 9 ++++-- .../lib_protocol/validate_errors.ml | 32 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 5 +++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index ff3d1e2e90dc..ab125459b6ae 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1675,8 +1675,13 @@ module Anonymous = struct in match dal_content with | None -> - (* TODO: return error *) - failwith "Wrong evidence: the attester did not DAL attest" + tzfail + (Invalid_accusation_no_dal_content + { + tb_slot = consensus_content.slot; + level = consensus_content.level; + slot_index; + }) | Some dal_content -> ( let number_of_slots = Constants.dal_number_of_slots vi.ctxt in let*? () = diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index fad54e35aea7..9da586c2e442 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -905,6 +905,11 @@ module Anonymous = struct level : Raw_level.t; first_allowed_level : Raw_level.t; } + | Invalid_accusation_no_dal_content of { + tb_slot : Slot.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1016,6 +1021,33 @@ module Anonymous = struct Denunciations_not_allowed_just_after_migration {level; first_allowed_level}) ; + register_error_kind + `Permanent + ~id:"validate.operation.invalid_accusation_no_dal_content" + ~title:"Invalid accusation: no DAL content" + ~description: + "Invalid accusation: the attestation operation has no DAL content." + ~pp:(fun ppf (tb_slot, level, slot_index) -> + Format.fprintf + ppf + "Invalid accusation for validator slot %a, level %a, and DAL slot \ + index %a: the attestation operation has no DAL content." + Slot.pp + tb_slot + Raw_level.pp + level + Dal.Slot_index.pp + slot_index) + (obj3 + (req "TB_slot" Slot.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding)) + (function + | Invalid_accusation_no_dal_content {tb_slot; level; slot_index} -> + Some (tb_slot, level, slot_index) + | _ -> None) + (fun (tb_slot, level, slot_index) -> + Invalid_accusation_no_dal_content {tb_slot; level; slot_index}) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 108d3283d11b..7ea8545b5d21 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -166,6 +166,11 @@ module Anonymous : sig level : Raw_level.t; first_allowed_level : Raw_level.t; } + | Invalid_accusation_no_dal_content of { + tb_slot : Slot.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From 871cc9e85c42dd997d4d82223c885441c337bb21 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 15 Jan 2025 16:39:38 +0100 Subject: [PATCH 3/8] Proto/DAL: add accusation validation error when slot was not attested --- src/proto_alpha/lib_protocol/validate.ml | 11 ++++--- .../lib_protocol/validate_errors.ml | 32 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 5 +++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index ab125459b6ae..58fa0243d859 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1692,12 +1692,13 @@ module Anonymous = struct let*? () = check_shard_index_is_in_range ~number_of_shards shard_index in - assert ( - (* TODO: check and return error *) - Dal.Attestation.is_attested - dal_content.attestation - slot_index) ; let level = consensus_content.level in + let*? () = + error_unless + (Dal.Attestation.is_attested dal_content.attestation slot_index) + (Invalid_accusation_slot_not_attested + {tb_slot = consensus_content.slot; level; slot_index}) + in let* protocol_first_level = First_level_of_protocol.get vi.ctxt in let*? () = (* Due to the DAL node possibly not checking for traps before the R diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 9da586c2e442..084e455b03ba 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -910,6 +910,11 @@ module Anonymous = struct level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Invalid_accusation_slot_not_attested of { + tb_slot : Slot.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1048,6 +1053,33 @@ module Anonymous = struct | _ -> None) (fun (tb_slot, level, slot_index) -> Invalid_accusation_no_dal_content {tb_slot; level; slot_index}) ; + register_error_kind + `Permanent + ~id:"validate.operation.invalid_accusation_slot_not_attested" + ~title:"Invalid accusation: the delegate did not attest the DAL slot" + ~description: + "Invalid accusation: the delegate did not attest the DAL slot." + ~pp:(fun ppf (tb_slot, level, slot_index) -> + Format.fprintf + ppf + "Invalid accusation for validator slot %a, level %a, and DAL slot \ + index %a: the delegate did not attest the DAL slot." + Slot.pp + tb_slot + Raw_level.pp + level + Dal.Slot_index.pp + slot_index) + (obj3 + (req "TB_slot" Slot.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding)) + (function + | Invalid_accusation_slot_not_attested {tb_slot; level; slot_index} -> + Some (tb_slot, level, slot_index) + | _ -> None) + (fun (tb_slot, level, slot_index) -> + Invalid_accusation_slot_not_attested {tb_slot; level; slot_index}) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 7ea8545b5d21..3b49342b280b 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -171,6 +171,11 @@ module Anonymous : sig level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Invalid_accusation_slot_not_attested of { + tb_slot : Slot.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From eca00ab6711a57a21cccf38d9cb858f57b97982f Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 15 Jan 2025 17:16:00 +0100 Subject: [PATCH 4/8] Proto/DAL: add accusation validation error when the shard is not a trap --- src/proto_alpha/lib_protocol/validate.ml | 13 +++++-- .../lib_protocol/validate_errors.ml | 36 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 6 ++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 58fa0243d859..3856335fbbde 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1736,8 +1736,17 @@ module Anonymous = struct shard_with_proof.shard.share ~traps_fraction in - assert (* TODO: check and return error *) - is_trap ; + let*? () = + error_unless + is_trap + (Invalid_accusation_shard_is_not_trap + { + delegate; + level = level.level; + slot_index; + shard_index = shard_with_proof.shard.index; + }) + in let* _ctxt, shard_owner = let*? tb_slot = Slot.of_int shard_index in Stake_distribution.slot_owner vi.ctxt level tb_slot diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 084e455b03ba..038e71973c4d 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -915,6 +915,12 @@ module Anonymous = struct level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Invalid_accusation_shard_is_not_trap of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + shard_index : int; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1080,6 +1086,36 @@ module Anonymous = struct | _ -> None) (fun (tb_slot, level, slot_index) -> Invalid_accusation_slot_not_attested {tb_slot; level; slot_index}) ; + register_error_kind + `Permanent + ~id:"validate.operation.invalid_accusation_shard_is_not_trap" + ~title:"Invalid accusation: the provided shard is not a trap" + ~description:"Invalid accusation: the provided shard is not a trap." + ~pp:(fun ppf (delegate, level, slot_index, shard_index) -> + Format.fprintf + ppf + "Invalid accusation for delegate %a, level %a, DAL slot index %a, \ + and shard index %d: the provided shard is not a trap." + Signature.Public_key_hash.pp + delegate + Raw_level.pp + level + Dal.Slot_index.pp + slot_index + shard_index) + (obj4 + (req "delegate" Signature.Public_key_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding) + (req "shard_index" int31)) + (function + | Invalid_accusation_shard_is_not_trap + {delegate; level; slot_index; shard_index} -> + Some (delegate, level, slot_index, shard_index) + | _ -> None) + (fun (delegate, level, slot_index, shard_index) -> + Invalid_accusation_shard_is_not_trap + {delegate; level; slot_index; shard_index}) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 3b49342b280b..238ad21d99ae 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -176,6 +176,12 @@ module Anonymous : sig level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Invalid_accusation_shard_is_not_trap of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + shard_index : int; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From d43b194502e726a937775ddd0f3f48d7979e8c08 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 16 Jan 2025 05:34:10 +0100 Subject: [PATCH 5/8] Proto/DAL: add accusation validation error when the shard is not assigned to the attester --- src/proto_alpha/lib_protocol/validate.ml | 17 +++++--- .../lib_protocol/validate_errors.ml | 43 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 7 +++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 3856335fbbde..f6f814b6e94b 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1751,11 +1751,18 @@ module Anonymous = struct let*? tb_slot = Slot.of_int shard_index in Stake_distribution.slot_owner vi.ctxt level tb_slot in - assert ( - (* TODO: check and return error *) - Signature.Public_key_hash.equal - delegate - shard_owner.delegate) ; + let*? () = + error_unless + (Signature.Public_key_hash.equal delegate shard_owner.delegate) + (Invalid_accusation_wrong_shard_owner + { + delegate; + level = level.level; + slot_index; + shard_index = shard_with_proof.shard.index; + shard_owner = shard_owner.delegate; + }) + in let attestation_lag = (Constants.parametric vi.ctxt).dal.attestation_lag in diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 038e71973c4d..8d797d6a984d 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -921,6 +921,13 @@ module Anonymous = struct slot_index : Dal.Slot_index.t; shard_index : int; } + | Invalid_accusation_wrong_shard_owner of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + shard_index : int; + shard_owner : Signature.Public_key_hash.t; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1116,6 +1123,42 @@ module Anonymous = struct (fun (delegate, level, slot_index, shard_index) -> Invalid_accusation_shard_is_not_trap {delegate; level; slot_index; shard_index}) ; + register_error_kind + `Permanent + ~id:"validate.operation.invalid_accusation_wrong_shard_owner" + ~title: + "Invalid accusation: the provided shard is not assigned to the attester" + ~description: + "Invalid accusation: the provided shard is not assigned to the \ + attester." + ~pp:(fun ppf (delegate, level, slot_index, shard_index, shard_owner) -> + Format.fprintf + ppf + "Invalid accusation for delegate %a, level %a, DAL slot index %a, \ + and shard index %d: the shard is assigned to %a, not the attester." + Signature.Public_key_hash.pp + delegate + Raw_level.pp + level + Dal.Slot_index.pp + slot_index + shard_index + Signature.Public_key_hash.pp + shard_owner) + (obj5 + (req "delegate" Signature.Public_key_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding) + (req "shard_index" Data_encoding.int31) + (req "shard_owner" Signature.Public_key_hash.encoding)) + (function + | Invalid_accusation_wrong_shard_owner + {delegate; level; slot_index; shard_index; shard_owner} -> + Some (delegate, level, slot_index, shard_index, shard_owner) + | _ -> None) + (fun (delegate, level, slot_index, shard_index, shard_owner) -> + Invalid_accusation_wrong_shard_owner + {delegate; level; slot_index; shard_index; shard_owner}) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 238ad21d99ae..460d6d055d05 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -182,6 +182,13 @@ module Anonymous : sig slot_index : Dal.Slot_index.t; shard_index : int; } + | Invalid_accusation_wrong_shard_owner of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + shard_index : int; + shard_owner : Signature.Public_key_hash.t; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From 5dde47c557a2f007f1ebb4351c86b1773237afa3 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 16 Jan 2025 05:40:31 +0100 Subject: [PATCH 6/8] Proto/DAL: add validation error when the failing to retrieve slot headers --- src/proto_alpha/lib_protocol/validate.ml | 8 +++-- .../lib_protocol/validate_errors.ml | 35 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 5 +++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index f6f814b6e94b..38df0b677363 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1781,9 +1781,11 @@ module Anonymous = struct | None -> (* TODO: https://gitlab.com/tezos/tezos/-/issues/7126 Can also fail if `attestation_lag` changes. *) - failwith (* TODO: return error *) - "SHOULD NOT HAPPEN IF 1) the denunciation age is correct, and 2) \ - the storage is updated correctly" + (* It should not happen if 1) the denunciation age is correct, and 2) \ + the storage is updated correctly *) + tzfail + (Accusation_validity_error_cannot_get_slot_headers + {delegate; level = level.level; slot_index}) | Some headers -> ( let slot_header_opt = List.find diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 8d797d6a984d..dbe4f7c45e64 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -928,6 +928,11 @@ module Anonymous = struct shard_index : int; shard_owner : Signature.Public_key_hash.t; } + | Accusation_validity_error_cannot_get_slot_headers of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1159,6 +1164,36 @@ module Anonymous = struct (fun (delegate, level, slot_index, shard_index, shard_owner) -> Invalid_accusation_wrong_shard_owner {delegate; level; slot_index; shard_index; shard_owner}) ; + register_error_kind + `Permanent + ~id:"validate.operation.accusation_validity_error_cannot_get_slot_headers" + ~title:"Accusation validity error: cannot get slot headers" + ~description: + "Accusation validity internal error: unable to retrieve the required \ + DAL slot headers." + ~pp:(fun ppf (delegate, level, slot_index) -> + Format.fprintf + ppf + "Accusation validity internal error for delegate %a, level %a, and \ + DAL slot index %a: unable to retrieve the required slot headers." + Signature.Public_key_hash.pp + delegate + Raw_level.pp + level + Dal.Slot_index.pp + slot_index) + (obj3 + (req "delegate" Signature.Public_key_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding)) + (function + | Accusation_validity_error_cannot_get_slot_headers + {delegate; level; slot_index} -> + Some (delegate, level, slot_index) + | _ -> None) + (fun (delegate, level, slot_index) -> + Accusation_validity_error_cannot_get_slot_headers + {delegate; level; slot_index}) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 460d6d055d05..e6f59a4a71c1 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -189,6 +189,11 @@ module Anonymous : sig shard_index : int; shard_owner : Signature.Public_key_hash.t; } + | Accusation_validity_error_cannot_get_slot_headers of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From d4020c4672f82dbd871075c8322dcf90d0fb07a1 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 16 Jan 2025 05:49:49 +0100 Subject: [PATCH 7/8] Proto/DAL: add accusation validation error for levels mismatch --- src/proto_alpha/lib_protocol/validate.ml | 17 +++-- .../lib_protocol/validate_errors.ml | 72 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 7 ++ 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 38df0b677363..fc7176a1fa65 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1810,13 +1810,20 @@ module Anonymous = struct attestation in return_unit - | Some _ -> + | Some (header, _publisher) -> (* TODO: https://gitlab.com/tezos/tezos/-/issues/7126 Can also fail if `attestation_lag` changes. *) - (* TODO: return error *) - failwith - "SHOULD NOT HAPPEN: mismatch between published levels in \ - storage versus in evidence" + (* mismatch between published levels in \ + storage versus in evidence; it should not happen *) + tzfail + (Accusation_validity_error_levels_mismatch + { + delegate; + level = level.level; + slot_index; + accusation_published_level = published_level; + store_published_level = header.id.published_level; + }) | None -> (* TODO: return error *) failwith diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index dbe4f7c45e64..3d327b7be533 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -933,6 +933,13 @@ module Anonymous = struct level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Accusation_validity_error_levels_mismatch of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + accusation_published_level : Raw_level.t; + store_published_level : Raw_level.t; + } | Conflicting_dal_entrapment of operation_conflict let () = @@ -1194,6 +1201,71 @@ module Anonymous = struct (fun (delegate, level, slot_index) -> Accusation_validity_error_cannot_get_slot_headers {delegate; level; slot_index}) ; + register_error_kind + `Permanent + ~id:"validate.operation.accusation_validity_error_levels_mismatch" + ~title:"Accusation validity internal error: levels mismatch" + ~description: + "Accusation validity internal error: mismatch between published levels \ + in storage and evidence." + ~pp:(fun + ppf + ( delegate, + level, + slot_index, + accusation_published_level, + store_published_level ) + -> + Format.fprintf + ppf + "Accusation validity error for delegate %a, level %a, and DAL slot \ + index %a: mismatch between published levels in evidence (%a) and \ + storage (%a)." + Signature.Public_key_hash.pp + delegate + Raw_level.pp + level + Dal.Slot_index.pp + slot_index + Raw_level.pp + accusation_published_level + Raw_level.pp + store_published_level) + (obj5 + (req "delegate" Signature.Public_key_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding) + (req "accusation_published_level" Raw_level.encoding) + (req "store_published_level" Raw_level.encoding)) + (function + | Accusation_validity_error_levels_mismatch + { + delegate; + level; + slot_index; + accusation_published_level; + store_published_level; + } -> + Some + ( delegate, + level, + slot_index, + accusation_published_level, + store_published_level ) + | _ -> None) + (fun ( delegate, + level, + slot_index, + accusation_published_level, + store_published_level ) -> + Accusation_validity_error_levels_mismatch + { + delegate; + level; + slot_index; + accusation_published_level; + store_published_level; + }) ; register_error_kind `Branch ~id:"validate.operation.conflicting_dal_entrapment" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index e6f59a4a71c1..a143fac844ab 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -194,6 +194,13 @@ module Anonymous : sig level : Raw_level.t; slot_index : Dal.Slot_index.t; } + | Accusation_validity_error_levels_mismatch of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + accusation_published_level : Raw_level.t; + store_published_level : Raw_level.t; + } | Conflicting_dal_entrapment of operation_conflict | Conflicting_nonce_revelation of operation_conflict | Conflicting_vdf_revelation of operation_conflict -- GitLab From 5a292efda3faac638374c497544ba8f57b3c7901 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 16 Jan 2025 05:56:16 +0100 Subject: [PATCH 8/8] Proto/DAL: add accusation validation error when slot was not published --- src/proto_alpha/lib_protocol/validate.ml | 18 +++++------ .../lib_protocol/validate_errors.ml | 31 +++++++++++++++++++ .../lib_protocol/validate_errors.mli | 5 +++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index fc7176a1fa65..d36bec58a721 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1766,13 +1766,14 @@ module Anonymous = struct let attestation_lag = (Constants.parametric vi.ctxt).dal.attestation_lag in - let published_level = + let* published_level = match Raw_level.(sub (succ level.level) attestation_lag) with | None -> - failwith - "SHOULD NOT HAPPEN ON MAINNET. It can in theory happen on test \ - networks (but it is very unlikely)" - | Some level -> level + (* The slot couldn't have been published in this case *) + tzfail + (Invalid_accusation_slot_not_published + {delegate; level = level.level; slot_index}) + | Some level -> return level in let* slot_headers_opt = Dal.Slot.find_slot_headers ctxt published_level @@ -1825,10 +1826,9 @@ module Anonymous = struct store_published_level = header.id.published_level; }) | None -> - (* TODO: return error *) - failwith - "Wrong evidence: no slot was published at the mentioned \ - level and index")) + tzfail + (Invalid_accusation_slot_not_published + {delegate; level = level.level; slot_index}))) let check_dal_entrapment_evidence vi (operation : Kind.dal_entrapment_evidence operation) = diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 3d327b7be533..7b48f864b66e 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -928,6 +928,11 @@ module Anonymous = struct shard_index : int; shard_owner : Signature.Public_key_hash.t; } + | Invalid_accusation_slot_not_published of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Accusation_validity_error_cannot_get_slot_headers of { delegate : Signature.Public_key_hash.t; level : Raw_level.t; @@ -1171,6 +1176,32 @@ module Anonymous = struct (fun (delegate, level, slot_index, shard_index, shard_owner) -> Invalid_accusation_wrong_shard_owner {delegate; level; slot_index; shard_index; shard_owner}) ; + register_error_kind + `Permanent + ~id:"validate.operation.invalid_accusation_slot_not_published" + ~title:"Invalid accusation: DAL slot not published" + ~description:"Invalid accusation: the DAL slot was not published." + ~pp:(fun ppf (delegate, level, slot_index) -> + Format.fprintf + ppf + "Invalid accusation for delegate %a, level %a, and DAL slot index \ + %a: the DAL slot was not published." + Signature.Public_key_hash.pp + delegate + Raw_level.pp + level + Dal.Slot_index.pp + slot_index) + (obj3 + (req "delegate" Signature.Public_key_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot_index" Dal.Slot_index.encoding)) + (function + | Invalid_accusation_slot_not_published {delegate; level; slot_index} -> + Some (delegate, level, slot_index) + | _ -> None) + (fun (delegate, level, slot_index) -> + Invalid_accusation_slot_not_published {delegate; level; slot_index}) ; register_error_kind `Permanent ~id:"validate.operation.accusation_validity_error_cannot_get_slot_headers" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index a143fac844ab..1dbeb5fd03e4 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -189,6 +189,11 @@ module Anonymous : sig shard_index : int; shard_owner : Signature.Public_key_hash.t; } + | Invalid_accusation_slot_not_published of { + delegate : Signature.Public_key_hash.t; + level : Raw_level.t; + slot_index : Dal.Slot_index.t; + } | Accusation_validity_error_cannot_get_slot_headers of { delegate : Signature.Public_key_hash.t; level : Raw_level.t; -- GitLab