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

tari-project / tari / 13012261930

28 Jan 2025 02:09PM UTC coverage: 73.991% (+8.6%) from 65.396%
13012261930

push

github

web-flow
feat: keep keys in compressed form (#6753)

Description
---
Keeps all crypto public keys in compressed form, and only uncompressing
when needed.

Motivation and Context
---
This should improve speed and reduce the compression of keys. Comparing
unit test speeds this PR is roughly the same as before. But unit test
almost always do crypto operations to ensure everything is correct.
Where this PR increases performance is when only reading something and
providing it. For example, just reading the mainnet gen block in its
current form on avg it takes 56 seconds. With this pr this time is taken
down to on avg 15 seconds. Thats a 370% speed improvement.

How Has This Been Tested?
---
unit tests

1623 of 2110 new or added lines in 123 files covered. (76.92%)

335 existing lines in 28 files now uncovered.

83511 of 112867 relevant lines covered (73.99%)

273339.14 hits per line

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

62.5
/infrastructure/tari_script/src/script_context.rs
1
// Copyright 2020. The Tari Project
2
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
3
// following conditions are met:
4
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
5
// disclaimer.
6
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
7
// following disclaimer in the documentation and/or other materials provided with the distribution.
8
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
9
// products derived from this software without specific prior written permission.
10
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
11
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
12
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
15
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17

18
use tari_crypto::ristretto::pedersen::CompressedPedersenCommitment;
19

20
use crate::HashValue;
21

22
/// Contextual data for use in Tari scripts. The context will typically be unambiguously and deterministically
23
/// populated by nodes that are executing the script.
24
#[derive(Debug, Clone, Default)]
25
pub struct ScriptContext {
26
    /// The height of the chain where the UTXO is being _spent_; not the height the UTXO was created in
27
    block_height: u64,
28
    /// The hash of the previous block's hash
29
    prev_block_hash: HashValue,
30
    /// The commitment of the UTXO that is attached to this script
31
    commitment: CompressedPedersenCommitment,
32
}
33

34
impl ScriptContext {
35
    pub fn new(height: u64, prev_hash: &HashValue, com: &CompressedPedersenCommitment) -> Self {
201✔
36
        ScriptContext {
201✔
37
            block_height: height,
201✔
38
            prev_block_hash: *prev_hash,
201✔
39
            commitment: com.clone(),
201✔
40
        }
201✔
41
    }
201✔
42

43
    pub fn block_height(&self) -> u64 {
55✔
44
        self.block_height
55✔
45
    }
55✔
46

47
    pub fn prev_block_hash(&self) -> &HashValue {
×
48
        &self.prev_block_hash
×
49
    }
×
50

NEW
51
    pub fn commitment(&self) -> &CompressedPedersenCommitment {
×
52
        &self.commitment
×
53
    }
×
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc