• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / bulletproofs-plus / 8159438199

05 Mar 2024 04:12PM UTC coverage: 97.568% (-0.1%) from 97.665%
8159438199

push

github

web-flow
fix: update source coverage script (#122)

The workflow for source coverage sets the RUST_TOOLCHAIN envar, but
`test_coverage.sh` was not respecting it.

This PR changes that and brings the coverage script in line with how
it's done in, e.g. tari_cypto.

2327 of 2385 relevant lines covered (97.57%)

1693.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.11
/src/protocols/transcript_protocol.rs
1
// Copyright 2022 The Tari Project
2
// SPDX-License-Identifier: BSD-3-Clause
3
//   Modified from:
4
//     Copyright (c) 2018 Chain, Inc.
5
//     SPDX-License-Identifier: MIT
6

7
//! Bulletproofs+ `TranscriptProtocol` trait for using a Transcript
8

9
use alloc::string::ToString;
10

11
use curve25519_dalek::{scalar::Scalar, traits::IsIdentity};
12
use merlin::Transcript;
13

14
use crate::{errors::ProofError, traits::FixedBytesRepr};
15

16
/// Defines a `TranscriptProtocol` trait for using a Merlin transcript.
17
pub trait TranscriptProtocol {
18
    /// Append a domain separator for the range proof.
19
    fn append_domain_separator(&mut self);
20

21
    /// Append a `point` with the given `label`.
22
    fn append_point<P: FixedBytesRepr>(&mut self, label: &'static [u8], point: &P);
23

24
    /// Check that a point is not the identity, then append it to the
25
    /// transcript.  Otherwise, return an error.
26
    fn validate_and_append_point<P: FixedBytesRepr + IsIdentity>(
27
        &mut self,
28
        label: &'static [u8],
29
        point: &P,
30
    ) -> Result<(), ProofError>;
31

32
    /// Append a `scalar` with a given `label`.
33
    fn append_scalar(&mut self, label: &'static [u8], scalar: &Scalar);
34

35
    /// Compute a `label`ed challenge variable.
36
    fn challenge_scalar(&mut self, label: &'static [u8]) -> Result<Scalar, ProofError>;
37
}
38

39
impl TranscriptProtocol for Transcript {
40
    fn append_domain_separator(&mut self) {
179✔
41
        self.append_message(b"dom-sep", b"Bulletproofs+ Range Proof");
179✔
42
    }
179✔
43

44
    fn append_point<P: FixedBytesRepr>(&mut self, label: &'static [u8], point: &P) {
315✔
45
        self.append_message(label, point.as_fixed_bytes());
315✔
46
    }
315✔
47

48
    fn validate_and_append_point<P: FixedBytesRepr + IsIdentity>(
2,883✔
49
        &mut self,
2,883✔
50
        label: &'static [u8],
2,883✔
51
        point: &P,
2,883✔
52
    ) -> Result<(), ProofError> {
2,883✔
53
        if point.is_identity() {
2,883✔
54
            Err(ProofError::VerificationFailed(
1✔
55
                "Identity element cannot be added to the transcript".to_string(),
1✔
56
            ))
1✔
57
        } else {
58
            self.append_message(label, point.as_fixed_bytes());
2,882✔
59
            Ok(())
2,882✔
60
        }
61
    }
2,883✔
62

63
    fn append_scalar(&mut self, label: &'static [u8], scalar: &Scalar) {
561✔
64
        self.append_message(label, scalar.as_bytes());
561✔
65
    }
561✔
66

67
    fn challenge_scalar(&mut self, label: &'static [u8]) -> Result<Scalar, ProofError> {
1,436✔
68
        let mut buf = [0u8; 64];
1,436✔
69
        self.challenge_bytes(label, &mut buf);
1,436✔
70
        let value = Scalar::from_bytes_mod_order_wide(&buf);
1,436✔
71
        if value == Scalar::ZERO {
1,436✔
72
            Err(ProofError::VerificationFailed(
×
73
                "Transcript challenge cannot be zero".to_string(),
×
74
            ))
×
75
        } else {
76
            Ok(value)
1,436✔
77
        }
78
    }
1,436✔
79
}
80

81
#[cfg(test)]
82
mod test {
83
    use curve25519_dalek::RistrettoPoint;
84
    use merlin::Transcript;
85

86
    use super::*;
87

88
    #[test]
1✔
89
    fn test_identity_point() {
1✔
90
        let mut transcript = Transcript::new(b"test");
1✔
91
        assert!(transcript
1✔
92
            .validate_and_append_point(b"identity", &RistrettoPoint::default().compress())
1✔
93
            .is_err());
1✔
94
    }
1✔
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc