Skip to content

Commit

Permalink
Merge pull request #1659 from zcash/zcash_transparent_no_std
Browse files Browse the repository at this point in the history
Implement `no_std` support for `zcash_transparent`
  • Loading branch information
str4d authored Dec 16, 2024
2 parents 24833e7 + b5b1225 commit efd8176
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zcash_transparent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zcash_address.workspace = true
zcash_encoding.workspace = true
zcash_protocol.workspace = true
zip32.workspace = true
core2.workspace = true

# Dependencies exposed in a public API:
# (Breaking upgrades to these require a breaking upgrade to this crate.)
Expand Down
10 changes: 6 additions & 4 deletions zcash_transparent/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Support for legacy transparent addresses and scripts.
use byteorder::{ReadBytesExt, WriteBytesExt};
use zcash_address::TryFromRawAddress;

use std::fmt;
use std::io::{self, Read, Write};
use std::ops::Shl;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
use core::ops::Shl;
use core2::io::{self, Read, Write};

use zcash_address::TryFromRawAddress;
use zcash_encoding::Vector;

/// Defined script opcodes.
Expand Down
9 changes: 5 additions & 4 deletions zcash_transparent/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Types and functions for building transparent transaction components.
use std::collections::BTreeMap;
use std::fmt;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::fmt;

use zcash_protocol::value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount};

Expand Down Expand Up @@ -287,7 +288,7 @@ impl TxIn<Unauthorized> {
TxIn {
prevout,
script_sig: (),
sequence: std::u32::MAX,
sequence: u32::MAX,
}
}
}
Expand Down Expand Up @@ -362,7 +363,7 @@ impl Bundle<Unauthorized> {
});

#[cfg(not(feature = "transparent-inputs"))]
let script_sigs = std::iter::empty::<Result<Script, Error>>();
let script_sigs = core::iter::empty::<Result<Script, Error>>();

Ok(Bundle {
vin: self
Expand Down
11 changes: 7 additions & 4 deletions zcash_transparent/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//! Structs representing the components within Zcash transactions.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use zcash_protocol::TxId;

use std::fmt::Debug;
use std::io::{self, Read, Write};
use alloc::vec::Vec;
use core::fmt::Debug;
use core2::io::{self, Read, Write};

use zcash_protocol::value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount};
use zcash_protocol::{
value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount},
TxId,
};

use crate::{
address::{Script, TransparentAddress},
Expand Down
4 changes: 3 additions & 1 deletion zcash_transparent/src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Transparent key components.
use alloc::string::ToString;
use alloc::vec::Vec;
use bip32::{
ChildNumber, ExtendedKey, ExtendedKeyAttrs, ExtendedPrivateKey, ExtendedPublicKey, Prefix,
};
Expand Down Expand Up @@ -341,7 +343,7 @@ pub(crate) mod private {
///
/// [BIP32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
pub trait IncomingViewingKey: private::SealedChangeLevelKey + std::marker::Sized {
pub trait IncomingViewingKey: private::SealedChangeLevelKey + core::marker::Sized {
/// Derives a transparent address at the provided child index.
#[allow(deprecated)]
fn derive_address(
Expand Down
5 changes: 5 additions & 0 deletions zcash_transparent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! # Zcash transparent protocol
#![no_std]

pub mod address;
pub mod builder;
pub mod bundle;
Expand All @@ -8,3 +10,6 @@ pub mod sighash;

#[cfg(feature = "transparent-inputs")]
pub mod keys;

#[macro_use]
extern crate alloc;
4 changes: 3 additions & 1 deletion zcash_transparent/src/pczt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! PCZT support for transparent Zcash.
use std::collections::BTreeMap;
use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;

use bip32::ChildNumber;
use getset::Getters;
Expand Down
4 changes: 3 additions & 1 deletion zcash_transparent/src/pczt/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::BTreeMap;
use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;

use bip32::ChildNumber;
use zcash_protocol::{value::Zatoshis, TxId};
Expand Down
1 change: 1 addition & 0 deletions zcash_transparent/src/pczt/signer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::sighash::SignableInput;
use alloc::vec::Vec;

impl super::Input {
/// Signs the transparent spend with the given spend authorizing key.
Expand Down
3 changes: 2 additions & 1 deletion zcash_transparent/src/pczt/tx_extractor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use zcash_protocol::value::Zatoshis;

use crate::{
Expand Down Expand Up @@ -57,7 +58,7 @@ impl super::Bundle {
Ok(TxIn {
prevout,
script_sig: script_sig(input)?,
sequence: input.sequence.unwrap_or(std::u32::MAX),
sequence: input.sequence.unwrap_or(u32::MAX),
})
})
.collect::<Result<Vec<_>, E>>()?;
Expand Down
2 changes: 2 additions & 0 deletions zcash_transparent/src/pczt/updater.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use ripemd::Ripemd160;
use sha2::{Digest, Sha256};

Expand Down
1 change: 1 addition & 0 deletions zcash_transparent/src/sighash.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use getset::Getters;
use zcash_protocol::value::Zatoshis;

Expand Down

0 comments on commit efd8176

Please sign in to comment.