Skip to content

Commit

Permalink
zcash_transparent: Fix its dependencies to work with no-std
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Dec 16, 2024
1 parent efd8176 commit 7bff034
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 27 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ categories = ["cryptography::cryptocurrencies"]
[workspace.dependencies]
# Intra-workspace dependencies
equihash = { version = "0.2", path = "components/equihash" }
zcash_address = { version = "0.6", path = "components/zcash_address" }
zcash_address = { version = "0.6", path = "components/zcash_address", default-features = false }
zcash_client_backend = { version = "0.15", path = "zcash_client_backend" }
zcash_encoding = { version = "0.2.1", path = "components/zcash_encoding", default-features = false }
zcash_keys = { version = "0.5", path = "zcash_keys" }
Expand Down Expand Up @@ -71,8 +71,8 @@ pasta_curves = "0.5"

# - Transparent
bip32 = { version = "0.5", default-features = false }
ripemd = "0.1"
secp256k1 = "0.27"
ripemd = { version = "0.1", default-features = false }
secp256k1 = { version = "0.27", default-features = false, features = ["alloc"] }
transparent = { package = "zcash_transparent", version = "0.0", path = "zcash_transparent", default-features = false }

# Boilerplate
Expand All @@ -86,8 +86,8 @@ rand_core = "0.6"
rust_decimal = { version = "1.35", default-features = false, features = ["serde"] }

# Digests
blake2b_simd = "1"
sha2 = "0.10"
blake2b_simd = { version = "1", default-features = false }
sha2 = { version = "0.10", default-features = false }

# Documentation
document-features = "0.2"
Expand All @@ -97,7 +97,7 @@ base64 = "0.22"
bech32 = { version = "0.11", default-features = false, features = ["alloc"] }
bs58 = { version = "0.5", default-features = false, features = ["alloc", "check"] }
byteorder = "1"
hex = "0.4"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
percent-encoding = "2.1.0"
postcard = { version = "1", features = ["alloc"] }
serde = { version = "1", features = ["derive"] }
Expand Down Expand Up @@ -129,7 +129,7 @@ tonic-build = { version = "0.12", default-features = false }

# Secret management
secrecy = "0.8"
subtle = "2.2.3"
subtle = { version = "2.2.3", default-features = false }

# SQLite databases
# - Warning: One of the downstream consumers requires that SQLite be available through
Expand Down Expand Up @@ -167,7 +167,7 @@ trait-variant = "0.1"
# ZIP 32
aes = "0.8"
fpe = "0.6"
zip32 = "0.1.1"
zip32 = { version = "0.1.1", default-features = false }

[profile.release]
lto = true
Expand Down
3 changes: 2 additions & 1 deletion components/zcash_protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ proptest.workspace = true

[features]
default = ["std"]
std = ["document-features", "dep:memuse"]
std = ["dep:document-features", "dep:memuse"]

## Exposes APIs that are useful for testing, such as `proptest` strategies.
test-dependencies = [
"dep:incrementalmerkletree",
Expand Down
4 changes: 2 additions & 2 deletions components/zip321/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories.workspace = true

[dependencies]
zcash_address.workspace = true
zcash_protocol.workspace = true
zcash_protocol = { workspace = true, features = ["std"] }

# - Parsing and Encoding
nom = "7"
Expand All @@ -27,7 +27,7 @@ proptest = { workspace = true, optional = true }

[dev-dependencies]
zcash_address = { workspace = true, features = ["test-dependencies"] }
zcash_protocol = { workspace = true, features = ["test-dependencies"] }
zcash_protocol = { workspace = true, features = ["std", "test-dependencies"] }
proptest.workspace = true

[features]
Expand Down
2 changes: 1 addition & 1 deletion zcash_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
equihash.workspace = true
zcash_address.workspace = true
zcash_encoding.workspace = true
zcash_encoding = { workspace = true, features = ["std"] }
zcash_protocol.workspace = true
zip32.workspace = true

Expand Down
12 changes: 9 additions & 3 deletions zcash_transparent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ 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.)
# - Digests (output types exposed)
blake2b_simd.workspace = true
sha2.workspace = true

# - Encodings
core2.workspace = true

# - Secret management
subtle.workspace = true

Expand All @@ -47,17 +49,21 @@ secp256k1 = { workspace = true, optional = true }
getset.workspace = true

# - Documentation
document-features.workspace = true
document-features = { workspace = true, optional = true }

# - Encodings
bs58.workspace = true
byteorder.workspace = true
hex.workspace = true

# - Transparent protocol
ripemd.workspace = true

[features]
default = ["std"]
std = [
"dep:document-features",
]

## Enables spending transparent notes with the transaction builder.
transparent-inputs = ["bip32/secp256k1-ffi", "dep:secp256k1"]

Expand Down
9 changes: 5 additions & 4 deletions zcash_transparent/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Support for legacy transparent addresses and scripts.
use byteorder::{ReadBytesExt, WriteBytesExt};

use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
Expand Down Expand Up @@ -314,12 +312,15 @@ impl fmt::Debug for Script {

impl Script {
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
let script = Vector::read(&mut reader, |r| r.read_u8())?;
let script = Vector::read(&mut reader, |r| {
let mut bytes = [0; 1];
r.read_exact(&mut bytes).map(|_| bytes[0])
})?;
Ok(Script(script))
}

pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
Vector::write(&mut writer, &self.0, |w, e| w.write_u8(*e))
Vector::write(&mut writer, &self.0, |w, e| w.write_all(&[*e]))
}

/// Returns the length of this script as encoded (including the initial CompactSize).
Expand Down
17 changes: 10 additions & 7 deletions zcash_transparent/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Structs representing the components within Zcash transactions.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

use alloc::vec::Vec;
use core::fmt::Debug;
use core2::io::{self, Read, Write};
Expand Down Expand Up @@ -160,13 +158,14 @@ impl OutPoint {
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
let mut hash = [0u8; 32];
reader.read_exact(&mut hash)?;
let n = reader.read_u32::<LittleEndian>()?;
Ok(OutPoint::new(hash, n))
let mut n = [0; 4];
reader.read_exact(&mut n)?;
Ok(OutPoint::new(hash, u32::from_le_bytes(n)))
}

pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
writer.write_all(self.hash.as_ref())?;
writer.write_u32::<LittleEndian>(self.n)
writer.write_all(&self.n.to_le_bytes())
}

/// Returns `true` if this `OutPoint` is "null" in the Bitcoin sense: it has txid set to
Expand Down Expand Up @@ -204,7 +203,11 @@ impl TxIn<Authorized> {
pub fn read<R: Read>(mut reader: &mut R) -> io::Result<Self> {
let prevout = OutPoint::read(&mut reader)?;
let script_sig = Script::read(&mut reader)?;
let sequence = reader.read_u32::<LittleEndian>()?;
let sequence = {
let mut sequence = [0; 4];
reader.read_exact(&mut sequence)?;
u32::from_le_bytes(sequence)
};

Ok(TxIn {
prevout,
Expand All @@ -216,7 +219,7 @@ impl TxIn<Authorized> {
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
self.prevout.write(&mut writer)?;
self.script_sig.write(&mut writer)?;
writer.write_u32::<LittleEndian>(self.sequence)
writer.write_all(&self.sequence.to_le_bytes())
}
}

Expand Down
4 changes: 4 additions & 0 deletions zcash_transparent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! # Zcash transparent protocol
//!
#![cfg_attr(feature = "std", doc = "## Feature flags")]
#![cfg_attr(feature = "std", doc = document_features::document_features!())]
//!
#![no_std]

Expand Down

0 comments on commit 7bff034

Please sign in to comment.