Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] #3714: Signature validation in no_std #4270

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use self::default::*;
/// Module with a set of default values.
pub mod default {
/// Default amount of fuel provided for execution
pub const DEFAULT_FUEL_LIMIT: u64 = 30_000_000;
pub const DEFAULT_FUEL_LIMIT: u64 = 55_000_000;
/// Default amount of memory given for smart contract
pub const DEFAULT_MAX_MEMORY: u32 = 500 * 2_u32.pow(20); // 500 MiB
}
Expand Down
2 changes: 1 addition & 1 deletion configs/peer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"max_wasm_size_bytes": 4194304
},
"WASM_RUNTIME_CONFIG": {
"FUEL_LIMIT": 30000000,
"FUEL_LIMIT": 55000000,
"MAX_MEMORY": 524288000
}
},
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion configs/peer/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"NewParameter": "?WSVIdentLengthLimits=1,128_LL"
},
{
"NewParameter": "?WASMFuelLimit=30000000"
"NewParameter": "?WASMFuelLimit=55000000"
},
{
"NewParameter": "?WASMMaxMemory=524288000"
Expand Down
9 changes: 0 additions & 9 deletions data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ declare_versioned!(SignedBlock 1..2, Debug, Clone, PartialEq, Eq, PartialOrd, Or

impl BlockPayload {
/// Calculate block payload [`Hash`](`iroha_crypto::HashOf`).
#[cfg(feature = "std")]
pub fn hash(&self) -> iroha_crypto::HashOf<Self> {
iroha_crypto::HashOf::new(self)
}
Expand Down Expand Up @@ -188,13 +187,11 @@ impl SignedBlock {
}

/// Calculate block hash
#[cfg(feature = "std")]
pub fn hash(&self) -> HashOf<Self> {
iroha_crypto::HashOf::new(self)
}

/// Add additional signatures to this block
#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
#[must_use]
pub fn sign(mut self, key_pair: &KeyPair) -> Self {
Expand All @@ -209,7 +206,6 @@ impl SignedBlock {
/// # Errors
///
/// If given signature doesn't match block hash
#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
pub fn add_signature(
&mut self,
Expand All @@ -224,7 +220,6 @@ impl SignedBlock {
}

/// Add additional signatures to this block
#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
pub fn replace_signatures(
&mut self,
Expand Down Expand Up @@ -261,9 +256,7 @@ mod candidate {

impl SignedBlockCandidate {
fn validate(self) -> Result<SignedBlockV1, &'static str> {
#[cfg(feature = "std")]
self.validate_signatures()?;
#[cfg(feature = "std")]
self.validate_header()?;

if self.payload.transactions.is_empty() {
Expand All @@ -276,7 +269,6 @@ mod candidate {
})
}

#[cfg(feature = "std")]
fn validate_header(&self) -> Result<(), &'static str> {
let actual_txs_hash = self.payload.header().transactions_hash;

Expand All @@ -296,7 +288,6 @@ mod candidate {
Ok(())
}

#[cfg(feature = "std")]
fn validate_signatures(&self) -> Result<(), &'static str> {
self.signatures
.verify(&self.payload)
Expand Down
1 change: 0 additions & 1 deletion data_model/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,6 @@ pub mod http {

impl SignedQueryCandidate {
fn validate(self) -> Result<SignedQueryV1, &'static str> {
#[cfg(feature = "std")]
if self.signature.verify(&self.payload).is_err() {
return Err("Query signature not valid");
}
Expand Down
13 changes: 0 additions & 13 deletions data_model/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ impl WasmSmartContract {

impl TransactionPayload {
/// Calculate transaction payload [`Hash`](`iroha_crypto::HashOf`).
#[cfg(feature = "std")]
pub fn hash(&self) -> iroha_crypto::HashOf<Self> {
iroha_crypto::HashOf::new(self)
}
Expand Down Expand Up @@ -273,13 +272,11 @@ impl SignedTransaction {
}

/// Calculate transaction [`Hash`](`iroha_crypto::HashOf`).
#[cfg(feature = "std")]
pub fn hash(&self) -> iroha_crypto::HashOf<Self> {
iroha_crypto::HashOf::new(self)
}

/// Sign transaction with provided key pair.
#[cfg(feature = "std")]
#[must_use]
pub fn sign(self, key_pair: &iroha_crypto::KeyPair) -> SignedTransaction {
let SignedTransaction::V1(mut tx) = self;
Expand All @@ -294,7 +291,6 @@ impl SignedTransaction {
}

/// Add additional signatures to this transaction
#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
pub fn merge_signatures(&mut self, other: Self) -> bool {
if self.payload().hash() != other.payload().hash() {
Expand Down Expand Up @@ -326,7 +322,6 @@ impl SignedTransactionV1 {

impl TransactionValue {
/// Calculate transaction [`Hash`](`iroha_crypto::HashOf`).
#[cfg(feature = "std")]
pub fn hash(&self) -> iroha_crypto::HashOf<SignedTransaction> {
self.value.hash()
}
Expand Down Expand Up @@ -372,17 +367,11 @@ mod candidate {
}

impl SignedTransactionCandidate {
#[cfg(feature = "std")]
fn validate(self) -> Result<SignedTransactionV1, &'static str> {
self.validate_signatures()?;
self.validate_instructions()
}

#[cfg(not(feature = "std"))]
fn validate(self) -> Result<SignedTransactionV1, &'static str> {
self.validate_instructions()
}

fn validate_instructions(self) -> Result<SignedTransactionV1, &'static str> {
if let Executable::Instructions(instructions) = &self.payload.instructions {
if instructions.is_empty() {
Expand All @@ -396,7 +385,6 @@ mod candidate {
})
}

#[cfg(feature = "std")]
fn validate_signatures(&self) -> Result<(), &'static str> {
self.signatures
.verify(&self.payload)
Expand Down Expand Up @@ -739,7 +727,6 @@ mod http {
}

/// Sign transaction with provided key pair.
#[cfg(feature = "std")]
#[must_use]
pub fn sign(self, key_pair: &iroha_crypto::KeyPair) -> SignedTransaction {
let signatures = SignaturesOf::new(key_pair, &self.payload);
Expand Down
2 changes: 1 addition & 1 deletion torii/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub mod profiling {
{
// Create profiler guard
let guard = pprof::ProfilerGuardBuilder::default()
.frequency(frequency.get() as i32)
.frequency(frequency.get().into())
mversic marked this conversation as resolved.
Show resolved Hide resolved
.blocklist(&["libc", "libgcc", "pthread", "vdso"])
.build()
.map_err(|e| {
Expand Down
Loading