Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6d284b4
Support updatability
d0cd Mar 19, 2025
ac8545c
Update deployment store
d0cd Mar 19, 2025
30db805
Fix deployment (de)serialization
d0cd Mar 19, 2025
434a3f8
Add benches and add migration TODOs
d0cd Mar 19, 2025
90f2621
Cleanup
d0cd Mar 19, 2025
86810f5
Cleanup up Deployment
d0cd Mar 19, 2025
1a76586
Improve deployment store API
d0cd Mar 20, 2025
75d047a
Update transaction store API
d0cd Mar 20, 2025
3b02904
Enable program checksums in the deployment
d0cd Mar 20, 2025
5112657
Improve comments, add checksum map
d0cd Mar 20, 2025
de65776
Implement migrations
d0cd Mar 20, 2025
69f2583
Fix test
d0cd Mar 20, 2025
7b36570
Cleanup comments
d0cd Mar 20, 2025
2eb82ba
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 21, 2025
462920d
Feedback
d0cd Mar 21, 2025
7ff9b13
Feedback
d0cd Mar 21, 2025
ca5c330
Feedback
d0cd Mar 21, 2025
33a3c8a
Feedback
d0cd Mar 21, 2025
72b4a9c
Fix get_edition_for_transaction
d0cd Mar 27, 2025
1d653af
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 27, 2025
da28dc0
Merge pull request #2659 from ProvableHQ/migrate/program-updatability
d0cd Mar 27, 2025
b0abf1b
Fix
d0cd Mar 27, 2025
16e52e3
Update to non-empty constructors
d0cd Mar 27, 2025
3a6391e
Update test cases
d0cd Mar 27, 2025
efccdec
Rename to upgradability, add tests
d0cd Mar 28, 2025
50661f9
Fix test
d0cd Mar 28, 2025
0b42785
Fix CI
d0cd Mar 28, 2025
f0b119b
Cleanup
d0cd Mar 28, 2025
d1bdeec
Fix test
d0cd Mar 28, 2025
ae3efb4
Fix test and cleanup
d0cd Mar 28, 2025
8b3cacb
Update ledger tests to test both versions of deployments
d0cd Mar 28, 2025
8a884eb
Fix test
d0cd Mar 28, 2025
69790ec
Cleanup
d0cd Mar 28, 2025
ae6eac1
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 28, 2025
02cfd23
Rename Deployment::len to Deployment::num_functions
howardwu Mar 28, 2025
ea65a1c
Reorder tree declarations in order of hierarchy
howardwu Mar 28, 2025
26d03d9
Clippy
d0cd Mar 28, 2025
cb61dcc
Reorder tree methods in order of hierarchy
howardwu Mar 28, 2025
9b333ed
Merge branch 'feat/program-updatability' of https://github.com/Provab…
howardwu Mar 28, 2025
3378104
Removes fee_index from Transaction::transaction_tree
howardwu Mar 28, 2025
4d9cee1
Improve the note for better context
howardwu Mar 28, 2025
04d13cd
Feedback
d0cd Mar 28, 2025
266fbff
Merge branch 'feat/program-updatability' of https://github.com/Provab…
howardwu Mar 28, 2025
0236435
Remove PartialEq and Eq on Map traits
howardwu Mar 28, 2025
b624f38
Feedback
d0cd Mar 28, 2025
018076a
Feedback, redefine program checksums
d0cd Mar 29, 2025
08cdc22
Feedback
d0cd Mar 29, 2025
207f891
Fix tests
d0cd Mar 29, 2025
cacd25a
Restrict to one upgrade/deployment per block
d0cd Apr 1, 2025
2eea916
Merge pull request #2669 from ProvableHQ/remove/eq-on-maps
vicsn Apr 8, 2025
b97c783
Feedback
d0cd Apr 8, 2025
005cd60
Fix
d0cd Apr 8, 2025
4fadf23
Add to find/get API
d0cd Apr 8, 2025
0e274f1
Refactor based on feedback
d0cd Apr 8, 2025
c618b26
Further restrict new syntax before migration
d0cd Apr 10, 2025
be0a27c
Fix
d0cd Apr 10, 2025
a225903
Add zero check for edition
d0cd Apr 17, 2025
05f30a5
Add additional fee_index check
howardwu Apr 18, 2025
493f29f
Resolve merge conflict
howardwu Apr 18, 2025
bfa667f
Adds extra deployment size checks
howardwu Apr 18, 2025
13afd8e
Update ledger/block/src/transaction/merkle.rs
vicsn Apr 21, 2025
d33c5ef
Feedback
d0cd Apr 23, 2025
bcaf360
Merge pull request #2668 from ProvableHQ/feat/improve-tree-logic
vicsn Apr 29, 2025
57b6790
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd May 27, 2025
24b8453
Bump to V8
d0cd May 27, 2025
0fc9566
Fix tests
d0cd May 27, 2025
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
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,16 @@ jobs:
workspace_member: synthesizer/snark
cache_key: v1.3.0-rust-1.83.0-snarkvm-synthesizer-snark-cache

synthesizer-upgrade:
docker:
- image: cimg/rust:1.83.0 # Attention - Change the MSRV in Cargo.toml and rust-toolchain as well
resource_class: << pipeline.parameters.xlarge >>
steps:
- run_serial:
flags: test_vm_upgrade --features=test
workspace_member: synthesizer
cache_key: v1.3.0-rust-1.83.0-snarkvm-synthesizer-upgrade-cache

utilities:
docker:
- image: cimg/rust:1.83.0 # Attention - Change the MSRV in Cargo.toml and rust-toolchain as well
Expand Down Expand Up @@ -1018,6 +1028,7 @@ workflows:
- synthesizer-program-integration-instruction-equal
- synthesizer-program-integration-instruction-commit
- synthesizer-snark
- synthesizer-upgrade
- utilities
- utilities-derives
- wasm
Expand Down
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.

26 changes: 26 additions & 0 deletions circuit/program/src/data/plaintext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ impl<A: Aleo> From<&Literal<A>> for Plaintext<A> {
}
}

// A macro that derives the `From` implementation for an array of literals.
// The array element type should be generic and so should the size.
macro_rules! impl_plaintext_from_array {
($element:ident, $($size:literal),+) => {
$(
impl<A: Aleo> From<[$element<A>; $size]> for Plaintext<A> {
fn from(value: [$element<A>; $size]) -> Self {
Self::Array(
value
.into_iter()
.map(|element| Plaintext::from(Literal::$element(element)))
.collect(),
OnceCell::new(),
)
}
}
)+
};
}

// Implement for `[U8<N>, SIZE]` for sizes 1 through 32.
impl_plaintext_from_array!(
U8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32
);

#[cfg(all(test, feature = "console"))]
mod tests {
use super::*;
Expand Down
22 changes: 21 additions & 1 deletion console/algorithms/benches/bhp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,30 @@ fn bhp1024(c: &mut Criterion) {
c.bench_function(&format!("BHP1024 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input)));
}

fn bhp1024_large(c: &mut Criterion) {
const SIZE_IN_BYTES: [usize; 4] =
[1_000 /* 1 kB */, 10_000 /* 10 KB */, 100_000 /* 100 KB */, 1_000_000 /* 1 MiB */];
let rng = &mut TestRng::default();

// Benchmark the BHP1024 hash function for different input sizes.
for size in SIZE_IN_BYTES.iter() {
let input = (0..size * 8).map(|_| bool::rand(rng)).collect::<Vec<_>>();
c.bench_function(&format!("BHP1024 Hash - input size {} bytes", size), |b| {
b.iter(|| BHP1024::<Console>::setup("BHP1024").unwrap().hash(&input))
});
}
}

criterion_group! {
name = bhp;
config = Criterion::default().sample_size(1000);
targets = bhp256, bhp512, bhp768, bhp1024
}

criterion_main!(bhp);
criterion_group! {
name = bhp_large;
config = Criterion::default().sample_size(100);
targets = bhp1024_large
}

criterion_main!(bhp, bhp_large);
8 changes: 4 additions & 4 deletions console/network/src/canary_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ impl Network for CanaryV0 {
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(not(any(test, feature = "test", feature = "test_consensus_heights")))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_900_000),
(ConsensusVersion::V3, 4_560_000),
(ConsensusVersion::V4, 5_730_000),
(ConsensusVersion::V5, 5_780_000),
(ConsensusVersion::V6, 6_240_000),
(ConsensusVersion::V7, 6_895_000),
(ConsensusVersion::V8, 999_999_999),
];
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 10),
(ConsensusVersion::V3, 11),
(ConsensusVersion::V4, 12),
(ConsensusVersion::V5, 13),
(ConsensusVersion::V6, 14),
(ConsensusVersion::V7, 15),
(ConsensusVersion::V8, 16),
];
/// The network edition.
const EDITION: u16 = 0;
/// The genesis block coinbase target.
#[cfg(not(feature = "test_targets"))]
const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
Expand Down
6 changes: 3 additions & 3 deletions console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub enum ConsensusVersion {
V6 = 6,
/// V7: Update to program rules.
V7 = 7,
/// V8: Support for program upgradability.
V8 = 8,
}

pub trait Network:
Expand All @@ -108,8 +110,6 @@ pub trait Network:
const ID: u16;
/// The network name.
const NAME: &'static str;
/// The network edition.
const EDITION: u16;

/// The function name for the inclusion circuit.
const INCLUSION_FUNCTION_NAME: &'static str;
Expand Down Expand Up @@ -228,7 +228,7 @@ pub trait Network:

/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `N::CONSENSUS_VERSION`
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7];
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8];
/// A list of (consensus_version, size) pairs indicating the maximum number of validators in a committee.
// Note: This value must **not** decrease without considering the impact on serialization.
// Decreasing this value will break backwards compatibility of serialization without explicit
Expand Down
8 changes: 4 additions & 4 deletions console/network/src/mainnet_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,29 @@ impl Network for MainnetV0 {
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(not(any(test, feature = "test")))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_800_000),
(ConsensusVersion::V3, 4_900_000),
(ConsensusVersion::V4, 6_135_000),
(ConsensusVersion::V5, 7_060_000),
(ConsensusVersion::V6, 7_560_000),
(ConsensusVersion::V7, 7_570_000),
(ConsensusVersion::V8, 999_999_999),
];
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(any(test, feature = "test"))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 10),
(ConsensusVersion::V3, 11),
(ConsensusVersion::V4, 12),
(ConsensusVersion::V5, 13),
(ConsensusVersion::V6, 14),
(ConsensusVersion::V7, 15),
(ConsensusVersion::V8, 16),
];
/// The network edition.
const EDITION: u16 = 0;
/// The genesis block coinbase target.
#[cfg(not(feature = "test"))]
const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
Expand Down
8 changes: 4 additions & 4 deletions console/network/src/testnet_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ impl Network for TestnetV0 {
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(not(any(test, feature = "test", feature = "test_consensus_heights")))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_950_000),
(ConsensusVersion::V3, 4_800_000),
(ConsensusVersion::V4, 6_625_000),
(ConsensusVersion::V5, 6_765_000),
(ConsensusVersion::V6, 7_600_000),
(ConsensusVersion::V7, 8_365_000),
(ConsensusVersion::V8, 999_999_999),
];
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
#[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 7] = [
const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 8] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 10),
(ConsensusVersion::V3, 11),
(ConsensusVersion::V4, 12),
(ConsensusVersion::V5, 13),
(ConsensusVersion::V6, 14),
(ConsensusVersion::V7, 15),
(ConsensusVersion::V8, 16),
];
/// The network edition.
const EDITION: u16 = 0;
/// The genesis block coinbase target.
#[cfg(not(feature = "test_targets"))]
const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
Expand Down
26 changes: 26 additions & 0 deletions console/program/src/data/plaintext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ impl<N: Network> From<&Literal<N>> for Plaintext<N> {
}
}

// A macro that derives the `From` implementation for an array of literals.
// The array element type should be generic and so should the size.
macro_rules! impl_plaintext_from_array {
($element:ident, $($size:literal),+) => {
$(
impl<N: Network> From<[$element<N>; $size]> for Plaintext<N> {
fn from(value: [$element<N>; $size]) -> Self {
Self::Array(
value
.into_iter()
.map(|element| Plaintext::from(Literal::$element(element)))
.collect(),
OnceCell::new(),
)
}
}
)+
};
}

// Implement for `[U8<N>, SIZE]` for sizes 1 through 32.
impl_plaintext_from_array!(
U8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32
);

#[cfg(test)]
mod tests {
use super::*;
Expand Down
9 changes: 5 additions & 4 deletions console/program/src/state_path/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ pub type TransactionsTree<N> = BHPMerkleTree<N, TRANSACTIONS_DEPTH>;
/// The Merkle path for a transaction in a block.
pub type TransactionsPath<N> = MerklePath<N, TRANSACTIONS_DEPTH>;

/// The Merkle tree for the execution.
pub type ExecutionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
/// The Merkle tree for the deployment.
pub type DeploymentTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
/// The Merkle tree for the transaction.
pub type TransactionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
/// The Merkle path for a function or transition in the transaction.
pub type TransactionPath<N> = MerklePath<N, TRANSACTION_DEPTH>;

/// The Merkle tree for the execution.
pub type ExecutionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
/// The Merkle tree for the deployment.
pub type DeploymentTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;

/// The Merkle tree for the transition.
pub type TransitionTree<N> = BHPMerkleTree<N, TRANSITION_DEPTH>;
/// The Merkle path for an input or output ID in the transition.
Expand Down
9 changes: 6 additions & 3 deletions ledger/block/src/transaction/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ impl<N: Network> ToBytes for Transaction<N> {
1u8.write_le(&mut writer)?;

// Write the transaction.
// We don't write the deployment or execution id, which are recomputed when creating the transaction.
// Note: We purposefully do not write out the deployment or execution ID,
// and instead recompute it when reconstructing the transaction, to ensure there was no malleability.
match self {
Self::Deploy(id, _, owner, deployment, fee) => {
// Write the variant.
Expand Down Expand Up @@ -147,8 +148,10 @@ mod tests {
let rng = &mut TestRng::default();

for expected in [
crate::transaction::test_helpers::sample_deployment_transaction(true, rng),
crate::transaction::test_helpers::sample_deployment_transaction(false, rng),
crate::transaction::test_helpers::sample_deployment_transaction(1, true, rng),
crate::transaction::test_helpers::sample_deployment_transaction(1, false, rng),
crate::transaction::test_helpers::sample_deployment_transaction(2, true, rng),
crate::transaction::test_helpers::sample_deployment_transaction(2, false, rng),
crate::transaction::test_helpers::sample_execution_transaction_with_fee(true, rng),
crate::transaction::test_helpers::sample_execution_transaction_with_fee(false, rng),
]
Expand Down
52 changes: 39 additions & 13 deletions ledger/block/src/transaction/deployment/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use super::*;
impl<N: Network> FromBytes for Deployment<N> {
/// Reads the deployment from a buffer.
fn read_le<R: Read>(mut reader: R) -> IoResult<Self> {
// Read the version.
let version = u8::read_le(&mut reader)?;
// Ensure the version is valid.
if version != 1 {
return Err(error("Invalid deployment version"));
}
// Read the version and ensure the version is valid.
let version = match u8::read_le(&mut reader)? {
1 => DeploymentVersion::V1,
2 => DeploymentVersion::V2,
version => return Err(error(format!("Invalid deployment version: {}", version))),
};

// Read the edition.
let edition = u16::read_le(&mut reader)?;
Expand All @@ -45,16 +45,35 @@ impl<N: Network> FromBytes for Deployment<N> {
verifying_keys.push((identifier, (verifying_key, certificate)));
}

// If the deployment version is 2, read the program checksum and verify it.
let program_checksum = match version {
DeploymentVersion::V1 => None,
DeploymentVersion::V2 => {
// Read the program checksum.
let bytes: [u8; 32] = FromBytes::read_le(&mut reader)?;
let checksum = bytes.map(U8::new);
// Verify the checksum.
if checksum != program.to_checksum() {
return Err(error(format!(
"Invalid checksum in the deployment: expected [{}], got [{}]",
program.to_checksum().iter().join(", "),
checksum.iter().join(", ")
)));
}
Some(checksum)
}
};

// Return the deployment.
Self::new(edition, program, verifying_keys).map_err(|err| error(format!("{err}")))
Self::new(edition, program, verifying_keys, program_checksum).map_err(|err| error(format!("{err}")))
}
}

impl<N: Network> ToBytes for Deployment<N> {
/// Writes the deployment to a buffer.
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> {
// Write the version.
1u8.write_le(&mut writer)?;
(self.version() as u8).write_le(&mut writer)?;
// Write the edition.
self.edition.write_le(&mut writer)?;
// Write the program.
Expand All @@ -70,6 +89,12 @@ impl<N: Network> ToBytes for Deployment<N> {
// Write the certificate.
certificate.write_le(&mut writer)?;
}
// Write the checksum, if it exists.
if let Some(program_checksum) = &self.program_checksum {
for byte in program_checksum {
byte.write_le(&mut writer)?;
}
}
Ok(())
}
}
Expand All @@ -82,12 +107,13 @@ mod tests {
fn test_bytes() -> Result<()> {
let rng = &mut TestRng::default();

// Construct a new deployment.
let expected = test_helpers::sample_deployment(rng);
// Construct the deployments.
for expected in [test_helpers::sample_deployment_v1(rng), test_helpers::sample_deployment_v2(rng)] {
// Check the byte representation.
let expected_bytes = expected.to_bytes_le()?;
assert_eq!(expected, Deployment::read_le(&expected_bytes[..])?);
}

// Check the byte representation.
let expected_bytes = expected.to_bytes_le()?;
assert_eq!(expected, Deployment::read_le(&expected_bytes[..])?);
Ok(())
}
}
Loading