Skip to content

Commit 957ac8a

Browse files
committed
Merge branch 'move_spend_limits' of https://github.com/ProvableHQ/snarkVM into move_spend_limits
2 parents f6ca0fa + a73d81e commit 957ac8a

5 files changed

Lines changed: 85 additions & 93 deletions

File tree

ledger/block/src/transaction/deployment/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,18 @@ impl<N: Network> Deployment<N> {
295295

296296
/// Returns the total density of the function and record-translation circuits in this deployment.
297297
pub fn combined_density(&self) -> u64 {
298-
self.combined_function_density()
299-
.saturating_add(self.combined_translation_density())
298+
self.combined_function_density().saturating_add(self.combined_translation_density())
300299
}
301300

302301
/// Returns the total density of the function circuits in this deployment.
303302
pub fn combined_function_density(&self) -> u64 {
304303
// Initialize the accumulator.
305304
let mut combined_density = 0u64;
306-
305+
307306
// Iterate over the function verifying keys.
308307
for (_, (vk, _)) in self.function_verifying_keys() {
309308
let info = vk.circuit_info;
310-
309+
311310
let function_density = (info.num_non_zero_a as u64)
312311
.saturating_add(info.num_non_zero_b as u64)
313312
.saturating_add(info.num_non_zero_c as u64);

synthesizer/benches/total_deployment_verification.rs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,18 @@ fn sample_next_block<R: Rng + CryptoRng>(
9696
// into actual deployments in various configurations (for instance, 4 deployments of size N vs. 2 deployments
9797
// of size 2N vs. 1 deployment of size 4N)
9898
fn main() {
99-
10099
// One array element = one group of deployments checked together. Each such group is represented by a pair:
101100
// (number of programs in the deployment, size of the program). The size of the program is in actuality the number
102101
// of inputs to the program's only function, which simply hashes them. The total density of the program grows
103102
// essentially linearly with this value.
104103
let deployment_configs = [
105104
// Each set of configurations visually grouped together corresponds to approximately the same total density.
106105
(1, 1 << 4),
107-
108106
(1, 1 << 5),
109107
(2, 1 << 4),
110-
111108
(1, 1 << 6),
112109
(2, 1 << 5),
113110
(4, 1 << 4),
114-
115111
(1, 1 << 7),
116112
(2, 1 << 6),
117113
(4, 1 << 5),
@@ -139,54 +135,62 @@ fn main() {
139135

140136
// Advance the ledger to the latest consensus version
141137
let transactions: [Transaction<CurrentNetwork>; 0] = [];
142-
while vm.block_store().current_block_height() < CurrentNetwork::CONSENSUS_HEIGHT(ConsensusVersion::latest()).unwrap() {
138+
while vm.block_store().current_block_height()
139+
< CurrentNetwork::CONSENSUS_HEIGHT(ConsensusVersion::latest()).unwrap()
140+
{
143141
let next_block = sample_next_block(&vm, &private_key, &transactions, rng).unwrap();
144142
vm.add_next_block(&next_block).unwrap();
145143
}
146144

147145
for (deployment_idx, (num_progs, multiplier)) in deployment_configs.into_iter().enumerate() {
148-
149146
println!("Processing deployment with {num_progs} program(s) with multiplier {multiplier}");
150147

151-
let deployments = (0..num_progs).map(|i| {
152-
153-
let mut program_str = format!(r"
148+
let deployments = (0..num_progs)
149+
.map(|i| {
150+
let mut program_str = format!(
151+
r"
154152
program test_{deployment_idx}_{i}.aleo;
155153
156154
function fun:
157155
input r0 as [field; 32u32].public;
158-
");
156+
"
157+
);
159158

160-
for j in 1..multiplier {
161-
program_str += &format!(r"
159+
for j in 1..multiplier {
160+
program_str += &format!(
161+
r"
162162
hash.bhp256 r0 into r{j} as field;
163-
");
164-
}
165-
166-
program_str += r"
163+
"
164+
);
165+
}
166+
167+
program_str += r"
167168
constructor:
168169
assert.eq true true;
169170
";
170171

171-
let program = Program::from_str(&program_str).unwrap();
172+
let program = Program::from_str(&program_str).unwrap();
172173

173-
// Deploy the first program
174-
let deployment_tx = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap();
175-
let deployment = deployment_tx.deployment().unwrap();
174+
// Deploy the first program
175+
let deployment_tx = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap();
176+
let deployment = deployment_tx.deployment().unwrap();
176177

177-
assert!(deployment.verifying_keys().len() == 1);
178-
let circuit_info = deployment.verifying_keys().first().unwrap().1.0.circuit_info;
179-
let combined_density = circuit_info.num_non_zero_a + circuit_info.num_non_zero_b + circuit_info.num_non_zero_c;
180-
println!(" - Program {:?}: total density: {combined_density:?}", deployment.program().id());
181-
182-
(deployment_tx, combined_density as usize)
183-
}).collect::<Vec<_>>();
178+
assert!(deployment.verifying_keys().len() == 1);
179+
let circuit_info = deployment.verifying_keys().first().unwrap().1.0.circuit_info;
180+
let combined_density =
181+
circuit_info.num_non_zero_a + circuit_info.num_non_zero_b + circuit_info.num_non_zero_c;
182+
println!(" - Program {:?}: total density: {combined_density:?}", deployment.program().id());
183+
184+
(deployment_tx, combined_density as usize)
185+
})
186+
.collect::<Vec<_>>();
184187

185188
let (deployment_txs, combined_densities): (Vec<_>, Vec<_>) = deployments.into_iter().unzip();
186189
let total_density = combined_densities.iter().sum::<usize>();
187190

188191
let start = Instant::now();
189-
vm.check_transactions(&deployment_txs.iter().map(|deployment| (deployment, None)).collect::<Vec<_>>(), rng).unwrap();
192+
vm.check_transactions(&deployment_txs.iter().map(|deployment| (deployment, None)).collect::<Vec<_>>(), rng)
193+
.unwrap();
190194
let elapsed = start.elapsed().as_millis() as f64 / 1000.0;
191195
println!("Deployment(s) with total density {total_density} checked in {elapsed:.2} s\n");
192196
}

synthesizer/process/src/cost.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ pub fn deployment_cost_v3<N: Network>(
225225
.ok_or(anyhow!("The storage cost computation overflowed for a deployment"))?;
226226

227227
// Compute the synthesis cost in microcredits.
228-
let synthesis_cost = combined_density * N::SYNTHESIS_FEE_MULTIPLIER
229-
/ N::ARC_0005_COMPUTE_DISCOUNT;
228+
let synthesis_cost = combined_density * N::SYNTHESIS_FEE_MULTIPLIER / N::ARC_0005_COMPUTE_DISCOUNT;
230229

231230
// Compute a Stack for the deployment.
232231
let stack = Stack::new(process, deployment.program())?;

0 commit comments

Comments
 (0)