Skip to content

Commit 667ae41

Browse files
Bartosz Lenartbartossh
andauthored
README for Solana audit, spell fixes, encapsulation fixes. (#29)
### Reference: [TASK RDS-1952](https://redstone-team.atlassian.net/browse/RDS-1952) ### Description We want to have short description of the code in README.md inside rust-sdk. --------- Co-authored-by: bartossh <bartosz.lenart@redstone.com>
1 parent 92c7840 commit 667ae41

File tree

18 files changed

+170
-153
lines changed

18 files changed

+170
-153
lines changed

README.md

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
1-
# RedStone
2-
3-
## See autogenerated docs for:
4-
5-
1. [`redstone` crate with
6-
`crypto_secp256k1`](https://docs.redstone.finance/rust/redstone/crypto_secp256k1/redstone/index.html)
7-
pure Rust implementation
8-
2. [`redstone` crate with `crypto_secp256k1` and
9-
`network_casper`](https://docs.redstone.finance/rust/redstone/crypto_secp256k1,network_casper/redstone/index.html)
10-
extension for Casper
11-
3. [`redstone` crate with `crypto_radix` and
12-
`network_radix`](https://docs.redstone.finance/rust/redstone/crypto_radix,network_radix/redstone/index.html)
13-
extension for Radix
1+
# RustSDK - Audit guide
2+
3+
<!-- TOC -->
4+
5+
- [RustSDK - Audit guide](#rustsdk---audit-guide)
6+
- [Repository](#repository)
7+
- [Code description](#code-description)
8+
- [Documentation](#documentation)
9+
- [Rust APIs and SDKs code conventions](#rust-apis-and-sdks-code-conventions)
10+
- [What should be audited](#what-should-be-audited)
11+
- [Rust files](#rust-files)
12+
- [Other files](#other-files)
13+
14+
<!-- TOC -->
15+
16+
## Repository
17+
18+
- The repository: https://github.com/redstone-finance/rust-sdk
19+
- The CommitId: [will be prepared for the particular version]
20+
- Path: [crates/redstone](./src)
21+
22+
The direct path should look like:
23+
[https://github.com/redstone-finance/rust-sdk/tree/[COMMIT_ID]/crates/redstone](https://github.com/redstone-finance/rust-sdk/tree/main/crates/redstone)
24+
25+
## Code description
26+
27+
### Documentation
28+
29+
- Redstone crate documentation [./crates/redstone/README.md](./crates/redstone/README.md)
30+
- RedstoneConfig is abstraction required as configuration for the RedStone protocol.
31+
[redstone/trait.RedStoneConfig](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/trait.RedStoneConfig.html)
32+
- Process Payload function is the main processor of the RedStone payload
33+
[redstone/core/processor/fn.process_payload](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/processor/fn.process_payload.html)
34+
- General [RedStone Blockchain Oracles docs](https://docs.redstone.finance/docs/get-started/data-formatting-processing/)
35+
- Especially [The push model docs](https://docs.redstone.finance/docs/get-started/models/redstone-push/)
36+
37+
### Rust APIs and SDKs code conventions
38+
39+
We try to follow conventions from [here](https://rust-lang.github.io/api-guidelines/checklist.html).
40+
41+
## What should be audited
42+
43+
### Rust files
44+
45+
## The code-lines in `*/crates/redstone/src/**/*.rs` files should be audited besides files listed below:
46+
47+
- ./crates/redstone/src/core/test_helpers.rs - file should not be audited.
48+
- ./crates/redstone/src/helpers - directory should not be audited.
49+
- all test, imports and comments should not be included for audit.
50+
51+
### Other files
52+
53+
- We suggest to read `**/README.md`
54+
- We suggest to audit Dependencies inside `**/Cargo.toml` files

crates/redstone/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Rust-SDK - General Assumption
2+
3+
<!-- TOC -->
4+
5+
- [Rust-SDK General Assumption](#rust-sdk---general-assumption)
6+
- [Rust SDK Overview](#rust-sdk-overview)
7+
- [Network](#network)
8+
- [Configuration](#configuration)
9+
- [Processor](#processor)
10+
- [Contract](#contract)
11+
- [Cryptographic modules](#cryptographic-modules)
12+
13+
<!-- TOC -->
14+
15+
## Rust SDK Overview
16+
17+
The main documentation page [rust/redstone/rust_sdk_2/redstone/index.html](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/index.html)
18+
lists the collection of utilities to make deserializing and decrypting RedStone payload as well as
19+
the Rust based blockchain utils, cryptographic methods, network and contract primitives.
20+
21+
## Network
22+
23+
Network module contains primitives that allow to communicate via processor module with clear interface giving clear `Error` messages
24+
and `Environment` trait all in one place [rust/redstone/rust_sdk_2/redstone/network](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/network/index.html).
25+
26+
## Configuration
27+
28+
Configuration module contains configuration for the RedStone payload processor [rust/redstone/rust_sdk_2/redstone/core/config](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/config/index.html).
29+
30+
- Configuration for the RedStone Rust-SDK is given as a pluggable entity. Any type implementing RedStoneConfig trait
31+
is a valid type to be used as config [redstone/trait.RedStoneConfig](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/trait.RedStoneConfig.html)
32+
Configuration requires to allow for perforimng two actions and to provide the Config type:
33+
- Crypto operations needed for address recovery. Different blockchains requires different cryptographic flavors.
34+
- Environment in which we execute. Provides logging etc. The same situation of flavors applies for the Environment.
35+
- Please check specific blockchain module for the implementation of Crypto and Environment modules:
36+
- Default [rust/redstone/rust_sdk_2/redstone/default_ext](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/default_ext/index.html)
37+
- Solana [rust/redstone/rust_sdk_2/redstone/solana](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/solana/index.html)
38+
- Radix [/rust/redstone/rust_sdk_2/redstone/radix](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/radix/index.html)
39+
- Casper [rust/redstone/rust_sdk_2/redstone/casper](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/casper/index.html)
40+
- Config type - configuration for a RedStone payload processor.
41+
Specifies the parameters necessary for the verification and aggregation of values from various data points passed by the RedStone payload.
42+
[rust/redstone/rust_sdk_2/redstone/core/config/struct.Config](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/config/struct.Config.html)
43+
44+
## Processor
45+
46+
Processor module contains the main processor of the RedStone payload [rust/redstone/rust_sdk_2/redstone/core/processor](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/processor/index.html).
47+
48+
- To proses payload use `process_payload` function in processor module
49+
[rust/redstone/rust_sdk_2/redstone/core/processor/fn.process_payload.html](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/processor/fn.process_payload.html)
50+
- The `config` argument is described above Configuration.
51+
- The `payload` argument is type that is convertible to bytes (Vec<u8>), and the bytes encoding is described in
52+
[redstone.finance docs data-formatting-processing](https://docs.redstone.finance/docs/get-started/data-formatting-processing/#how-data-is-encoded-before-being-put-on-the-blockchain)
53+
- The result of `process_payload` [rust/redstone/rust_sdk_2/redstone/core/processor_result/type.ProcessorResult](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/processor_result/type.ProcessorResult.html)
54+
returns success or an error:
55+
- Success contains a validated payload [rust/redstone/rust_sdk_2/redstone/core/processor_result/struct.ValidatedPayload](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/core/processor_result/struct.ValidatedPayload.html)
56+
containing a `min_timestamp` in [ ms ] which is the minimum timestamp encountered during processing and `values` (`Vec<Value>`)
57+
where [rust/redstone/rust_sdk_2/redstone/struct.Value](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/struct.Value.html)
58+
Each element in this vector represents a processed value corresponding to the passed data_feed item in the Config
59+
60+
## Contract
61+
62+
Contract module contains contract primitives used for verification of the contract data and logic [rust/redstone/rust_sdk_2/redstone/contract/index.html](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/contract/index.html)
63+
For the specific verification primitive description look in to [rust/redstone/rust_sdk_2/redstone/contract/verification](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/contract/verification/index.html)
64+
65+
## Cryptographic methods
66+
67+
1. [`redstone` crate with
68+
`crypto_secp256k1`](https://docs.redstone.finance/rust/redstone/crypto_secp256k1/redstone/index.html)
69+
pure Rust implementation
70+
2. [`redstone` crate with `crypto_secp256k1` and
71+
`network_casper`](https://docs.redstone.finance/rust/redstone/crypto_secp256k1,network_casper/redstone/index.html)
72+
extension for Casper
73+
3. [`redstone` crate with `crypto_radix` and
74+
`network_radix`](https://docs.redstone.finance/rust/redstone/crypto_radix,network_radix/redstone/index.html)
75+
extension for Radix
76+
4. Solana [rust/redstone/rust_sdk_2/redstone/solana/enum.SolanaCrypto](https://docs.redstone.finance/rust/redstone/rust_sdk_2/redstone/solana/enum.SolanaCrypto.html)

crates/redstone/benches/benchmarks.rs

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,12 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
2-
use redstone::utils::slice::check_no_duplicates;
32

4-
fn benchmark_has_duplicates_unique_shuffled(c: &mut Criterion) {
5-
let slice = vec![
6-
94, 218, 60, 212, 192, 42, 177, 209, 232, 95, 127, 89, 41, 133, 251, 130, 53, 84, 3, 46,
7-
123, 175, 152, 143, 57, 38, 139, 132, 171, 118, 147, 105, 166, 124, 215, 233, 44, 160, 237,
8-
149, 163, 162, 96, 70, 161, 1, 191, 78, 67, 231, 30, 35, 244, 145, 47, 99, 186, 0, 158,
9-
247, 128, 154, 214, 194, 223, 37, 72, 169, 62, 227, 136, 59, 129, 80, 235, 58, 222, 106,
10-
23, 10, 24, 200, 178, 69, 252, 202, 198, 153, 52, 142, 31, 195, 61, 181, 254, 190, 242,
11-
112, 148, 64, 101, 167, 75, 114, 33, 168, 224, 249, 164, 87, 174, 208, 108, 34, 117, 144,
12-
245, 180, 119, 213, 65, 179, 115, 126, 74, 63, 20, 196, 159, 16, 206, 243, 131, 157, 26,
13-
103, 83, 79, 246, 116, 4, 113, 187, 229, 219, 6, 54, 36, 86, 12, 207, 104, 250, 141, 109,
14-
55, 45, 228, 27, 43, 100, 110, 176, 156, 102, 85, 248, 146, 189, 32, 184, 140, 137, 66,
15-
122, 97, 221, 98, 225, 150, 236, 134, 199, 165, 76, 107, 170, 135, 182, 203, 19, 211, 239,
16-
220, 238, 71, 48, 234, 22, 88, 29, 172, 13, 21, 204, 205, 120, 226, 197, 77, 7, 111, 151,
17-
193, 8, 15, 240, 5, 91, 14, 39, 25, 125, 50, 155, 82, 253, 230, 92, 56, 121, 201, 2, 93,
18-
40, 217, 210, 18, 241, 185, 68, 28, 73, 188, 216, 173, 183, 90, 51, 17, 138, 9, 255, 11,
19-
49, 81,
20-
];
21-
c.bench_function("benchmark_has_duplicates_unique_shuffled", |b| {
3+
fn benchmark_placeholder(c: &mut Criterion) {
4+
c.bench_function("benchmark_placeholder", |b| {
225
b.iter(|| {
23-
if check_no_duplicates(&slice).is_err() {
24-
panic!("Shouldn't find any repetition in benchmark");
25-
};
6+
let _a: Vec<u8> = Vec::with_capacity(256);
267
})
278
});
289
}
29-
30-
fn benchmark_has_duplicates_not_unique_shuffled(c: &mut Criterion) {
31-
let slice = vec![
32-
94, 218, 60, 212, 192, 42, 177, 209, 232, 95, 127, 89, 41, 133, 251, 130, 53, 84, 3, 46,
33-
123, 175, 152, 143, 57, 38, 139, 132, 171, 118, 147, 105, 166, 124, 215, 233, 44, 160, 237,
34-
149, 163, 162, 96, 70, 161, 1, 191, 78, 67, 231, 30, 35, 244, 145, 47, 99, 186, 0, 158,
35-
247, 128, 154, 214, 194, 223, 37, 72, 169, 62, 227, 136, 59, 129, 80, 235, 58, 222, 106,
36-
23, 10, 24, 200, 178, 69, 252, 202, 198, 153, 52, 142, 31, 195, 61, 181, 254, 190, 242,
37-
112, 148, 64, 101, 167, 75, 114, 33, 168, 224, 249, 164, 87, 174, 208, 108, 34, 117, 144,
38-
245, 180, 119, 213, 65, 179, 115, 126, 74, 63, 20, 196, 159, 16, 206, 243, 131, 157, 26,
39-
103, 83, 79, 246, 116, 4, 113, 187, 229, 219, 6, 54, 36, 86, 12, 207, 104, 250, 141, 109,
40-
55, 45, 228, 27, 43, 100, 110, 176, 156, 102, 85, 248, 146, 189, 32, 184, 140, 137, 66,
41-
122, 97, 221, 98, 225, 150, 236, 134, 199, 165, 76, 107, 170, 135, 182, 203, 19, 211, 239,
42-
220, 238, 71, 48, 234, 22, 88, 29, 172, 13, 21, 204, 205, 120, 226, 197, 77, 7, 111, 151,
43-
193, 8, 15, 240, 5, 91, 14, 39, 25, 125, 50, 155, 82, 253, 230, 92, 56, 121, 201, 2, 93,
44-
40, 217, 210, 18, 241, 185, 68, 28, 73, 188, 216, 173, 183, 90, 51, 17, 138, 9, 254, 11,
45-
49, 81,
46-
];
47-
48-
c.bench_function("benchmark_has_duplicates_unique_shuffled", |b| {
49-
b.iter(|| {
50-
let Err(_) = check_no_duplicates(&slice) else {
51-
panic!("Shouldn't find any repetition in benchmark");
52-
};
53-
})
54-
});
55-
}
56-
57-
fn benchmark_has_duplicates_unique_shuffled_extra_small(c: &mut Criterion) {
58-
let slice = vec![94, 218, 60, 212];
59-
60-
c.bench_function(
61-
"benchmark_has_duplicates_unique_shuffled_extra_small",
62-
|b| {
63-
b.iter(|| {
64-
if check_no_duplicates(&slice).is_err() {
65-
panic!("Shouldn't find any repetition in benchmark");
66-
};
67-
})
68-
},
69-
);
70-
}
71-
fn benchmark_has_duplicates_unique_shuffled_medium(c: &mut Criterion) {
72-
let slice = vec![
73-
94, 218, 60, 212, 192, 42, 177, 209, 232, 95, 127, 89, 41, 133, 251, 130, 53, 84, 3, 46,
74-
];
75-
76-
c.bench_function(
77-
"benchmark_has_duplicates_unique_shuffled_quite_small",
78-
|b| {
79-
b.iter(|| {
80-
if check_no_duplicates(&slice).is_err() {
81-
panic!("Shouldn't find any repetition in benchmark");
82-
};
83-
})
84-
},
85-
);
86-
}
87-
88-
fn benchmark_has_duplicates_unique_shuffled_small(c: &mut Criterion) {
89-
let slice = vec![94, 218, 60, 212, 192, 42, 177, 209, 232, 95, 127, 89];
90-
91-
c.bench_function(
92-
"benchmark_has_duplicates_unique_shuffled_quite_small",
93-
|b| {
94-
b.iter(|| {
95-
if check_no_duplicates(&slice).is_err() {
96-
panic!("Shouldn't find any repetition in benchmark");
97-
};
98-
})
99-
},
100-
);
101-
}
102-
103-
criterion_group!(
104-
benches,
105-
benchmark_has_duplicates_unique_shuffled,
106-
benchmark_has_duplicates_not_unique_shuffled,
107-
benchmark_has_duplicates_unique_shuffled_extra_small,
108-
benchmark_has_duplicates_unique_shuffled_medium,
109-
benchmark_has_duplicates_unique_shuffled_small
110-
);
10+
criterion_group!(benches, benchmark_placeholder,);
11111

11212
criterion_main!(benches);

crates/redstone/src/contract/verification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn verify_package_timestamp(
9898

9999
/// Verifies if:
100100
/// * Package timestamps are strictly increasing
101-
/// * This is the first write or the time between writes is stricly increasing
101+
/// * This is the first write or the time between writes is strictly increasing
102102
pub fn verify_trusted_update(
103103
time_now: TimestampMillis,
104104
last_write_time: Option<TimestampMillis>,
@@ -116,7 +116,7 @@ pub fn verify_trusted_update(
116116

117117
/// Verifies if:
118118
/// * Package timestamps are strictly increasing
119-
/// * This is the first write or the time between writes is stricly greater than `min_time_between_updates`
119+
/// * This is the first write or the time between writes is strictly greater than `min_time_between_updates`
120120
pub fn verify_untrusted_update(
121121
time_now: TimestampMillis,
122122
last_write_time: Option<TimestampMillis>,

crates/redstone/src/core/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl Config {
6161
/// * `signers` - List of identifiers for signers authorized to sign the data.
6262
/// * `feed_ids` - Identifiers for the data feeds from which values are aggregated.
6363
/// * `block_timestamp` - The current block time in timestamp format, used for verifying data timeliness.
64-
/// * `max_timestamp_delay_ms` - Maximum delay of the package agains the current block timestamp.
65-
/// If None is provieded then default config value is used.
66-
/// * `max_timestamp_ahead_ms` - Maximum ahead of time of the package agains current block timestamp.
67-
/// If None is provieded then default config value is used.
64+
/// * `max_timestamp_delay_ms` - Maximum delay of the package against the current block timestamp.
65+
/// If None is provided then default config value is used.
66+
/// * `max_timestamp_ahead_ms` - Maximum ahead of time of the package against current block timestamp.
67+
/// If None is provided then default config value is used.
6868
///
6969
/// # Returns
7070
///

crates/redstone/src/core/validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
/// requires data integrity and authenticity checks. Implementations of this trait are responsible for
1515
/// defining the logic behind each validation step, ensuring that data conforms to expected rules and
1616
/// conditions.
17-
pub(crate) trait Validator {
17+
pub trait Validator {
1818
/// Retrieves the index of a given data feed.
1919
///
2020
/// This method takes a `feed_id` representing the unique identifier of a data feed and

crates/redstone/src/default_ext/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use sha3::{Digest, Keccak256};
44
use crate::{crypto::Crypto, network::StdEnv, Bytes, CryptoError, RedStoneConfigImpl};
55

66
/// Standard nonspecialized implementation of the RedStoneConfig.
7-
/// Constructuble from the [crate::core::config::Config].
7+
/// Constructible from the [crate::core::config::Config].
88
pub type StdRedStoneConfig = RedStoneConfigImpl<DefaultCrypto, StdEnv>;
99

1010
/// Default crypto operations. Uses k256 and sha3 crates.

crates/redstone/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod crypto;
1818
pub mod network;
1919
mod protocol;
2020
mod types;
21-
pub mod utils;
21+
mod utils;
2222

2323
#[cfg(feature = "solana")]
2424
pub mod solana;
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
pub(crate) const UNSIGNED_METADATA_BYTE_SIZE_BS: usize = 3;
2-
pub(crate) const DATA_PACKAGES_COUNT_BS: usize = 2;
3-
pub(crate) const DATA_POINT_COUNT_MAX_VALUE: usize = u16::MAX as usize; // 0xFFFF
4-
pub(crate) const DATA_POINTS_COUNT_BS: usize = 3;
5-
pub(crate) const SIGNATURE_BS: usize = 65;
6-
pub(crate) const DATA_POINT_VALUE_BYTE_SIZE_BS: usize = 4;
7-
pub(crate) const DATA_FEED_ID_BS: usize = 32;
8-
pub(crate) const TIMESTAMP_BS: usize = 6;
9-
pub(crate) const MAX_TIMESTAMP_DELAY_MS: u64 = 15 * 60 * 1000; // 15 minutes in milliseconds
10-
pub(crate) const MAX_TIMESTAMP_AHEAD_MS: u64 = 3 * 60 * 1000; // 3 minutes in milliseconds
11-
pub(crate) const REDSTONE_MARKER_BS: usize = 9;
12-
pub(crate) const REDSTONE_MARKER: [u8; 9] = [0, 0, 2, 237, 87, 1, 30, 0, 0]; // 0x000002ed57011e0000
1+
pub const UNSIGNED_METADATA_BYTE_SIZE_BS: usize = 3;
2+
pub const DATA_PACKAGES_COUNT_BS: usize = 2;
3+
pub const DATA_POINT_COUNT_MAX_VALUE: usize = u16::MAX as usize; // 0xFFFF
4+
pub const DATA_POINTS_COUNT_BS: usize = 3;
5+
pub const SIGNATURE_BS: usize = 65;
6+
pub const DATA_POINT_VALUE_BYTE_SIZE_BS: usize = 4;
7+
pub const DATA_FEED_ID_BS: usize = 32;
8+
pub const TIMESTAMP_BS: usize = 6;
9+
pub const MAX_TIMESTAMP_DELAY_MS: u64 = 15 * 60 * 1000; // 15 minutes in milliseconds
10+
pub const MAX_TIMESTAMP_AHEAD_MS: u64 = 3 * 60 * 1000; // 3 minutes in milliseconds
11+
pub const REDSTONE_MARKER_BS: usize = 9;
12+
pub const REDSTONE_MARKER: [u8; 9] = [0, 0, 2, 237, 87, 1, 30, 0, 0]; // 0x000002ed57011e0000

crates/redstone/src/protocol/data_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::fmt::{Debug, Formatter};
33

44
use crate::{protocol::data_point::DataPoint, SignerAddress, TimestampMillis};
55
#[derive(Clone, PartialEq, Eq)]
6-
pub(crate) struct DataPackage {
6+
pub struct DataPackage {
77
pub(crate) signer_address: SignerAddress,
88
pub(crate) timestamp: TimestampMillis,
99
pub(crate) data_points: Vec<DataPoint>,

0 commit comments

Comments
 (0)