Skip to content

Commit f27bcae

Browse files
committed
Enable program checksums in the deployment
1 parent b45b4a7 commit f27bcae

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

ledger/store/src/transaction/deployment.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
525525
None => bail!("Failed to get the deployed program '{program_id}' (edition {edition})"),
526526
};
527527

528+
// Compute the program checksum.
529+
let program_checksum = program.checksum().ok();
530+
528531
// Initialize a vector for the verifying keys and certificates.
529532
let mut verifying_keys = Vec::with_capacity(program.functions().len());
530533

@@ -545,7 +548,7 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
545548
}
546549

547550
// Return the deployment.
548-
Ok(Some(Deployment::new(edition, program, verifying_keys, None)?))
551+
Ok(Some(Deployment::new(edition, program, verifying_keys, program_checksum)?))
549552
}
550553

551554
/// Returns the fee for the given `transaction ID`.

synthesizer/process/src/stack/deploy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<N: Network> Stack<N> {
5252

5353
// Return the deployment.
5454
// Note that the checksum is **intentionally** left as `None`. It should be added in `VM::deploy`.
55-
Deployment::new(*self.program_edition, self.program.clone(), verifying_keys, None)
55+
Deployment::new(*self.program_edition, self.program.clone(), verifying_keys, Some(self.program_checksum))
5656
}
5757

5858
/// Checks each function in the program on the given verifying key and certificate.

synthesizer/src/vm/deploy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
3535
let deployment = self.deploy_raw(program, rng)?;
3636
// Ensure the transaction is not empty.
3737
ensure!(!deployment.program().functions().is_empty(), "Attempted to create an empty transaction deployment");
38-
// TODO (@d0cd). Set the checksum in the deployment. Use similar logic to how the correct execution cost is computed in VM::execute
38+
// TODO (@d0cd). Unset the checksum in the deployment if the block height is less than the migration height.
39+
// Use similar logic to how the correct execution cost is computed in VM::execute
3940
// Compute the deployment ID.
4041
let deployment_id = deployment.to_deployment_id()?;
4142
// Construct the owner.

synthesizer/src/vm/mod.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ function a:
10741074
// Note: `deployment_transaction_ids` is sorted lexicographically by transaction ID, so the order may change if we update internal methods.
10751075
assert_eq!(
10761076
deployment_transaction_ids,
1077-
vec![deployment_4.id(), deployment_3.id(), deployment_2.id(), deployment_1.id()],
1077+
vec![deployment_3.id(), deployment_1.id(), deployment_4.id(), deployment_2.id()],
10781078
"Update me if serialization has changed"
10791079
);
10801080
}
@@ -1460,8 +1460,13 @@ function do:
14601460
let fee = vm.execute_fee_authorization(fee_authorization, None, rng).unwrap();
14611461

14621462
// Create a new deployment transaction with the overreported verifying keys.
1463-
let adjusted_deployment =
1464-
Deployment::new(deployment.edition(), deployment.program().clone(), vks_with_overreport, None).unwrap();
1463+
let adjusted_deployment = Deployment::new(
1464+
deployment.edition(),
1465+
deployment.program().clone(),
1466+
vks_with_overreport,
1467+
deployment.program_checksum().cloned(),
1468+
)
1469+
.unwrap();
14651470
let adjusted_transaction = Transaction::from_deployment(program_owner, adjusted_deployment, fee).unwrap();
14661471

14671472
// Verify the deployment transaction. It should error when certificate checking for constraint count mismatch.
@@ -1515,8 +1520,13 @@ function do:
15151520
}
15161521

15171522
// Create a new deployment transaction with the underreported verifying keys.
1518-
let adjusted_deployment =
1519-
Deployment::new(deployment.edition(), deployment.program().clone(), vks_with_underreport, None).unwrap();
1523+
let adjusted_deployment = Deployment::new(
1524+
deployment.edition(),
1525+
deployment.program().clone(),
1526+
vks_with_underreport,
1527+
deployment.program_checksum().cloned(),
1528+
)
1529+
.unwrap();
15201530
let deployment_id = adjusted_deployment.to_deployment_id().unwrap();
15211531
let adjusted_transaction =
15221532
Transaction::Deploy(txid, deployment_id, program_owner, Box::new(adjusted_deployment), fee);
@@ -1590,8 +1600,13 @@ function do:
15901600
}
15911601

15921602
// Create a new deployment transaction with the underreported verifying keys.
1593-
let adjusted_deployment =
1594-
Deployment::new(deployment.edition(), deployment.program().clone(), vks_with_underreport, None).unwrap();
1603+
let adjusted_deployment = Deployment::new(
1604+
deployment.edition(),
1605+
deployment.program().clone(),
1606+
vks_with_underreport,
1607+
deployment.program_checksum().cloned(),
1608+
)
1609+
.unwrap();
15951610
let deployment_id = adjusted_deployment.to_deployment_id().unwrap();
15961611
let adjusted_transaction =
15971612
Transaction::Deploy(txid, deployment_id, program_owner, Box::new(adjusted_deployment), fee);

synthesizer/src/vm/verify.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
151151
ensure!(owner.verify(*deployment_id), "Invalid owner signature for deployment transaction '{id}'");
152152
// Verify the program checksum, if it exists.
153153
// TODO (@d0cd): Add requirement for the program checksum after migration height. Use similar logic to how the execution fee is checked.
154+
// Before the migration, the checksum should be `None`.
154155
if let Some(given_checksum) = deployment.program_checksum() {
155156
let expected_checksum = deployment.program().checksum()?;
156157
ensure!(

synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ outputs:
2525
execute:
2626
test_rand.aleo/rand_chacha_check:
2727
outputs:
28-
- '{"type":"future","id":"818878742790741579153893179075772445872751227433677932822653185952935999557field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 1field,\n true\n ]\n}"}'
28+
- '{"type":"future","id":"3094980085105288375234060174899683221046711858965162333618502474712664334238field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 2field,\n true\n ]\n}"}'
2929
speculate: the execution was accepted
3030
add_next_block: succeeded.
3131
additional:

synthesizer/tests/tests/vm/execute_and_finalize/test_rand.aleo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cases:
1212
inputs: [0field, false]
1313
- program: test_rand.aleo
1414
function: rand_chacha_check
15-
inputs: [1field, true]
15+
inputs: [2field, true]
1616
*/
1717

1818
program test_rand.aleo;

0 commit comments

Comments
 (0)