Merge pull request #518 from zcash/merge-non-consensus-changes-3

Merge non-consensus changes
This commit is contained in:
str4d 2022-02-28 23:48:24 +00:00 committed by GitHub
commit c423167b30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 71 additions and 215 deletions

View File

@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
override: true
- name: Fetch path to Zcash parameters
@ -55,7 +55,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
override: true
- name: Add target
run: rustup target add ${{ matrix.target }}
@ -78,7 +78,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
override: true
# Build benchmarks to prevent bitrot
- name: Build benchmarks
@ -88,20 +88,20 @@ jobs:
args: --all --benches
clippy:
name: Clippy (1.54.0)
name: Clippy (1.56.1)
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
components: clippy
override: true
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
name: Clippy (1.54.0)
name: Clippy (1.56.1)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
@ -173,7 +173,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
override: true
- name: cargo fetch
uses: actions-rs/cargo@v1
@ -196,7 +196,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0
toolchain: 1.56.1
override: true
# cargo fmt does not build the code, and running it in a fresh clone of

View File

@ -19,7 +19,8 @@ panic = 'abort'
codegen-units = 1
[patch.crates-io]
orchard = { git = "https://github.com/zcash/orchard.git", rev = "f1795f8068c8c83af89af8a061131759f973d656" }
hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" }
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "dd57b430dee7c0b163f4035fef2280cd1935036c" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "3ddf6c49f7484ed1295bd5351317bbfe49e14472" }
zcash_encoding = { path = "components/zcash_encoding" }
zcash_note_encryption = { path = "components/zcash_note_encryption" }
hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" }

View File

@ -7,5 +7,8 @@ and this library adheres to Rust's notion of
## [Unreleased]
### Changed
- MSRV is now 1.56.1.
## [0.1.0] - 2020-07-10
Initial release.

View File

@ -7,5 +7,8 @@ and this library adheres to Rust's notion of
## [Unreleased]
### Changed
- MSRV is now 1.56.1.
## [0.1.0] - 2021-12-17
Initial release.

View File

@ -1 +1 @@
1.54.0
1.56.1

View File

@ -41,7 +41,7 @@ and this library adheres to Rust's notion of
- `zcash_client_backend::encoding::encode_transparent_address`
### Changed
- MSRV is now 1.54.0.
- MSRV is now 1.56.1.
- Bumped dependencies to `ff 0.11`, `group 0.11`, `bls12_381 0.6`, `jubjub 0.8`.
- `zcash_client_backend::proto`:
- `compact_formats::CompactSpend` has been renamed to `CompactSaplingSpend`,

View File

@ -18,7 +18,7 @@ and this library adheres to Rust's notion of
rewinds exceed supported bounds.
### Changed
- MSRV is now 1.54.0.
- MSRV is now 1.56.1.
- Bumped dependencies to `ff 0.11`, `group 0.11`, `jubjub 0.8`.
- Renamed the following to use lower-case abbreviations (matching Rust
naming conventions):

View File

@ -14,6 +14,7 @@ and this library adheres to Rust's notion of
- `zcash_history::Entry::new_leaf`
### Changed
- MSRV is now 1.56.1.
- `zcash_history::{Entry, IndexedNode, Tree}` now have a `Version` parameter.
### Removed

View File

@ -101,7 +101,7 @@ and this library adheres to Rust's notion of
- `impl Sum<&Amount> for Option<Amount>`
### Changed
- MSRV is now 1.54.0.
- MSRV is now 1.56.1.
- Bumped dependencies to `ff 0.11`, `group 0.11`, `bls12_381 0.6`, `jubjub 0.8`.
- The following modules and helpers have been moved into
`zcash_primitives::sapling`:

View File

@ -1,14 +1,11 @@
//! Implementations of serialization and parsing for Orchard note commitment trees.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::convert::TryFrom;
use std::hash::Hash;
use std::convert::{TryFrom, TryInto};
use std::io::{self, Read, Write};
use incrementalmerkletree::{
bridgetree::{
AuthFragment, BridgeTree, Checkpoint, Frontier, Leaf, MerkleBridge, NonEmptyFrontier,
},
bridgetree::{AuthFragment, Frontier, Leaf, MerkleBridge, NonEmptyFrontier},
Hashable, Position,
};
use orchard::tree::MerkleHashOrchard;
@ -18,14 +15,6 @@ use super::{CommitmentTree, HashSer};
pub const SER_V1: u8 = 1;
pub fn read_frontier_v0<H: Hashable + super::Hashable, R: Read>(
mut reader: R,
) -> io::Result<Frontier<H, 32>> {
let tree = CommitmentTree::read(&mut reader)?;
Ok(tree.to_frontier())
}
impl HashSer for MerkleHashOrchard {
fn read<R: Read>(mut reader: R) -> io::Result<Self>
where
@ -46,6 +35,14 @@ impl HashSer for MerkleHashOrchard {
}
}
pub fn read_frontier_v0<H: Hashable + super::Hashable, R: Read>(
mut reader: R,
) -> io::Result<Frontier<H, 32>> {
let tree = CommitmentTree::read(&mut reader)?;
Ok(tree.to_frontier())
}
pub fn write_nonempty_frontier_v1<H: HashSer, W: Write>(
mut writer: W,
frontier: &NonEmptyFrontier<H>,
@ -108,19 +105,32 @@ pub fn read_frontier_v1<H: HashSer + Clone, R: Read>(reader: R) -> io::Result<Fr
}
}
pub fn write_position<W: Write>(mut writer: W, position: Position) -> io::Result<()> {
writer.write_u64::<LittleEndian>(position.try_into().unwrap())
}
pub fn read_position<R: Read>(mut reader: R) -> io::Result<Position> {
let p = reader.read_u64::<LittleEndian>()?;
<usize>::try_from(p).map(Position::from).map_err(|err| {
io::Error::new(
io::ErrorKind::Unsupported,
format!(
"usize could not be decoded to a 64-bit value on this platform: {:?}",
err
),
)
})
}
pub fn write_auth_fragment_v1<H: HashSer, W: Write>(
mut writer: W,
fragment: &AuthFragment<H>,
) -> io::Result<()> {
writer.write_u64::<LittleEndian>(<u64>::from(fragment.position()))?;
writer.write_u64::<LittleEndian>(fragment.altitudes_observed() as u64)?;
write_position(&mut writer, fragment.position())?;
writer.write_u64::<LittleEndian>(fragment.altitudes_observed().try_into().unwrap())?;
Vector::write(&mut writer, fragment.values(), |w, a| a.write(w))
}
pub fn read_position<R: Read>(mut reader: R) -> io::Result<Position> {
Ok(Position::from(reader.read_u64::<LittleEndian>()? as usize))
}
#[allow(clippy::redundant_closure)]
pub fn read_auth_fragment_v1<H: HashSer, R: Read>(mut reader: R) -> io::Result<AuthFragment<H>> {
let position = read_position(&mut reader)?;
@ -130,7 +140,7 @@ pub fn read_auth_fragment_v1<H: HashSer, R: Read>(mut reader: R) -> io::Result<A
Ok(AuthFragment::from_parts(position, alts_observed, values))
}
pub fn write_bridge_v1<H: HashSer, W: Write>(
pub fn write_bridge_v1<H: HashSer + Ord, W: Write>(
mut writer: W,
bridge: &MerkleBridge<H>,
) -> io::Result<()> {
@ -143,7 +153,7 @@ pub fn write_bridge_v1<H: HashSer, W: Write>(
&mut writer,
&bridge.auth_fragments().iter().collect::<Vec<_>>(),
|w, (i, a)| {
w.write_u64::<LittleEndian>(**i as u64)?;
w.write_u64::<LittleEndian>(u64::from(**i))?;
write_auth_fragment_v1(w, a)
},
)?;
@ -152,13 +162,12 @@ pub fn write_bridge_v1<H: HashSer, W: Write>(
Ok(())
}
pub fn read_bridge_v1<H: HashSer + Clone, R: Read>(mut reader: R) -> io::Result<MerkleBridge<H>> {
pub fn read_bridge_v1<H: HashSer + Ord + Clone, R: Read>(
mut reader: R,
) -> io::Result<MerkleBridge<H>> {
let prior_position = Optional::read(&mut reader, read_position)?;
let auth_fragments = Vector::read(&mut reader, |r| {
Ok((
r.read_u64::<LittleEndian>()? as usize,
read_auth_fragment_v1(r)?,
))
let auth_fragments = Vector::read(&mut reader, |mut r| {
Ok((read_position(&mut r)?, read_auth_fragment_v1(r)?))
})?
.into_iter()
.collect();
@ -171,99 +180,22 @@ pub fn read_bridge_v1<H: HashSer + Clone, R: Read>(mut reader: R) -> io::Result<
))
}
pub const EMPTY_CHECKPOINT: u8 = 0;
pub const BRIDGE_CHECKPOINT: u8 = 1;
pub fn write_checkpoint_v1<W: Write>(mut writer: W, checkpoint: &Checkpoint) -> io::Result<()> {
match checkpoint {
Checkpoint::Empty => {
writer.write_u8(EMPTY_CHECKPOINT)?;
}
Checkpoint::AtIndex(i) => {
writer.write_u8(BRIDGE_CHECKPOINT)?;
writer.write_u64::<LittleEndian>(*i as u64)?;
}
}
Ok(())
}
pub fn read_checkpoint_v1<R: Read>(mut reader: R) -> io::Result<Checkpoint> {
match reader.read_u8()? {
EMPTY_CHECKPOINT => Ok(Checkpoint::Empty),
BRIDGE_CHECKPOINT => Ok(Checkpoint::AtIndex(
reader.read_u64::<LittleEndian>()? as usize
)),
flag => Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Unrecognized checkpoint variant identifier: {:?}", flag),
)),
}
}
pub fn write_tree_v1<H: HashSer + Hash + Eq, W: Write>(
pub fn write_bridge<H: HashSer + Ord, W: Write>(
mut writer: W,
tree: &BridgeTree<H, 32>,
) -> io::Result<()> {
Vector::write(&mut writer, tree.bridges(), |w, b| write_bridge_v1(w, b))?;
Vector::write(
&mut writer,
&tree.witnessable_leaves().iter().collect::<Vec<_>>(),
|mut w, (a, i)| {
a.write(&mut w)?;
w.write_u64::<LittleEndian>(**i as u64)?;
Ok(())
},
)?;
Vector::write(&mut writer, tree.checkpoints(), |w, c| {
write_checkpoint_v1(w, c)
})?;
writer.write_u64::<LittleEndian>(tree.max_checkpoints() as u64)?;
Ok(())
}
#[allow(clippy::redundant_closure)]
pub fn read_tree_v1<H: Hashable + HashSer + Hash + Eq + Clone, R: Read>(
mut reader: R,
) -> io::Result<BridgeTree<H, 32>> {
BridgeTree::from_parts(
Vector::read(&mut reader, |r| read_bridge_v1(r))?,
Vector::read(&mut reader, |mut r| {
Ok((H::read(&mut r)?, r.read_u64::<LittleEndian>()? as usize))
})?
.into_iter()
.collect(),
Vector::read(&mut reader, |r| read_checkpoint_v1(r))?,
reader.read_u64::<LittleEndian>()? as usize,
)
.map_err(|err| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Consistency violation found when attempting to deserialize Merkle tree: {:?}",
err
),
)
})
}
pub fn write_tree<H: HashSer + Hash + Eq, W: Write>(
mut writer: W,
tree: &BridgeTree<H, 32>,
bridge: &MerkleBridge<H>,
) -> io::Result<()> {
writer.write_u8(SER_V1)?;
write_tree_v1(&mut writer, tree)
write_bridge_v1(writer, bridge)
}
pub fn read_tree<H: Hashable + HashSer + Hash + Eq + Clone, R: Read>(
pub fn read_bridge<H: HashSer + Ord + Clone, R: Read>(
mut reader: R,
) -> io::Result<BridgeTree<H, 32>> {
) -> io::Result<MerkleBridge<H>> {
match reader.read_u8()? {
SER_V1 => read_tree_v1(&mut reader),
SER_V1 => read_bridge_v1(&mut reader),
flag => Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Unrecognized tree serialization version: {:?}", flag),
format!("Unrecognized serialization version: {:?}", flag),
)),
}
}

View File

@ -239,6 +239,7 @@ pub trait Authorization {
type TzeAuth: tze::Authorization;
}
#[derive(Debug)]
pub struct Authorized;
impl Authorization for Authorized {
@ -282,6 +283,7 @@ impl PartialEq for Transaction {
}
}
#[derive(Debug)]
pub struct TransactionData<A: Authorization> {
version: TxVersion,
consensus_branch_id: BranchId,
@ -438,92 +440,6 @@ impl<A: Authorization> TransactionData<A> {
}
}
impl<A: Authorization> std::fmt::Debug for TransactionData<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
f,
"TransactionData(
version = {:?},
consensus_branch_id = {:?},
lock_time = {:?},
expiry_height = {:?},
transparent_fields = {{{}}}
sprout = {{{}}},
sapling = {{{}}},
orchard = {{{}}},
tze = {{{}}}
)",
self.version,
self.consensus_branch_id,
self.lock_time,
self.expiry_height,
if let Some(b) = &self.transparent_bundle {
format!(
"
vin = {:?},
vout = {:?},
",
b.vin, b.vout
)
} else {
"".to_string()
},
if let Some(b) = &self.sprout_bundle {
format!(
"
joinsplits = {:?},
joinsplit_pubkey = {:?},
",
b.joinsplits, b.joinsplit_pubkey
)
} else {
"".to_string()
},
if let Some(b) = &self.sapling_bundle {
format!(
"
value_balance = {:?},
shielded_spends = {:?},
shielded_outputs = {:?},
binding_sig = {:?},
",
b.value_balance, b.shielded_spends, b.shielded_outputs, b.authorization
)
} else {
"".to_string()
},
if let Some(b) = &self.orchard_bundle {
format!(
"
value_balance = {:?},
actions = {:?},
",
b.value_balance(),
b.actions().len()
)
} else {
"".to_string()
},
{
#[cfg(feature = "zfuture")]
if let Some(b) = &self.tze_bundle {
format!(
"
tze_inputs = {:?},
tze_outputs = {:?},
",
b.vin, b.vout
)
} else {
"".to_string()
}
#[cfg(not(feature = "zfuture"))]
""
}
)
}
}
impl<A: Authorization> TransactionData<A> {
pub fn sapling_value_balance(&self) -> Amount {
self.sapling_bundle
@ -992,21 +908,21 @@ impl Transaction {
}
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct TransparentDigests<A> {
pub prevouts_digest: A,
pub sequence_digest: A,
pub outputs_digest: A,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct TzeDigests<A> {
pub inputs_digest: A,
pub outputs_digest: A,
pub per_input_digest: Option<A>,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct TxDigests<A> {
pub header_digest: A,
pub transparent_digests: Option<TransparentDigests<A>>,

View File

@ -7,7 +7,7 @@ and this library adheres to Rust's notion of
## [Unreleased]
### Changed
- MSRV is now 1.54.0.
- MSRV is now 1.56.1.
- Bumped dependencies to `ff 0.11`, `group 0.11`, `bellman 0.11.1`,
`bls12_381 0.6`, `jubjub 0.8`.
- `zcash_proofs::sapling::SaplingVerificationContext::new` now takes a