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

Implement no_std support for zcash_transparent #1659

Merged
merged 1 commit into from
Dec 16, 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
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 @@
Ok(TxIn {
prevout,
script_sig: script_sig(input)?,
sequence: input.sequence.unwrap_or(std::u32::MAX),
sequence: input.sequence.unwrap_or(u32::MAX),

Check warning on line 61 in zcash_transparent/src/pczt/tx_extractor.rs

View check run for this annotation

Codecov / codecov/patch

zcash_transparent/src/pczt/tx_extractor.rs#L61

Added line #L61 was not covered by tests
})
})
.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
Loading