Skip to content

Commit

Permalink
Made initial hash optional (None for new accounts) (#529)
Browse files Browse the repository at this point in the history
* feat: optional initial hash for new accounts
fix: use `core::ops::Not` instead of `std::ops::Not`
fix: address review comments
refactor: rename function
docs: update changelog
tests: add checking proven transaction id for cases when account creation was involved

* refactor: move `init_account_hash` function back to `Account`

* fix: no-std build

* fix: address review comments
  • Loading branch information
polydez authored and bobbinth committed May 13, 2024
1 parent 62e5063 commit e0ab8c2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions miden-lib/src/transaction/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ToTransactionKernelInputs for PreparedTransaction {
let account = self.account();
let stack_inputs = TransactionKernel::build_input_stack(
account.id(),
account.proof_init_hash(),
account.init_hash(),
self.input_notes().commitment(),
self.block_header().hash(),
);
Expand All @@ -43,7 +43,7 @@ impl ToTransactionKernelInputs for ExecutedTransaction {
let account = self.initial_account();
let stack_inputs = TransactionKernel::build_input_stack(
account.id(),
account.proof_init_hash(),
account.init_hash(),
self.input_notes().commitment(),
self.block_header().hash(),
);
Expand All @@ -61,7 +61,7 @@ impl ToTransactionKernelInputs for TransactionWitness {

let stack_inputs = TransactionKernel::build_input_stack(
account.id(),
account.proof_init_hash(),
account.init_hash(),
self.input_notes().commitment(),
self.block_header().hash(),
);
Expand Down
2 changes: 1 addition & 1 deletion miden-tx/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl TransactionProver {

let builder = ProvenTransactionBuilder::new(
account_id,
tx_witness.account().proof_init_hash(),
tx_witness.account().init_hash(),
tx_outputs.account.hash(),
block_hash,
proof,
Expand Down
3 changes: 3 additions & 0 deletions miden-tx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,14 @@ fn prove_witness_and_verify() {
let executed_transaction = executor
.execute_transaction(account_id, block_ref, &note_ids, data_store.tx_args().clone())
.unwrap();
let executed_transaction_id = executed_transaction.id();

let proof_options = ProvingOptions::default();
let prover = TransactionProver::new(proof_options);
let proven_transaction = prover.prove_transaction(executed_transaction).unwrap();

assert_eq!(proven_transaction.id(), executed_transaction_id);

let serialised_transaction = proven_transaction.to_bytes();
let proven_transaction = ProvenTransaction::read_from_bytes(&serialised_transaction).unwrap();

Expand Down
3 changes: 3 additions & 0 deletions miden-tx/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ impl DataStore for MockDataStore {
pub fn prove_and_verify_transaction(
executed_transaction: ExecutedTransaction,
) -> Result<(), TransactionVerifierError> {
let executed_transaction_id = executed_transaction.id();
// Prove the transaction

let proof_options = ProvingOptions::default();
let prover = TransactionProver::new(proof_options);
let proven_transaction = prover.prove_transaction(executed_transaction).unwrap();

assert_eq!(proven_transaction.id(), executed_transaction_id);

// Serialize & deserialize the ProvenTransaction
let serialised_transaction = proven_transaction.to_bytes();
let proven_transaction = ProvenTransaction::read_from_bytes(&serialised_transaction).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion objects/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Account {
/// against a new account, public input for the initial account state is set to [ZERO; 4] to
/// distinguish new accounts from existing accounts. The actual hash of the initial account
/// state (and the initial state itself), are provided to the VM via the advice provider.
pub fn proof_init_hash(&self) -> Digest {
pub fn init_hash(&self) -> Digest {
if self.is_new() {
Digest::default()
} else {
Expand Down
2 changes: 1 addition & 1 deletion objects/src/transaction/transaction_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl From<&ExecutedTransaction> for TransactionId {
let input_notes_hash = tx.input_notes().commitment();
let output_notes_hash = tx.output_notes().commitment();
Self::new(
tx.initial_account().proof_init_hash(),
tx.initial_account().init_hash(),
tx.final_account().hash(),
input_notes_hash,
output_notes_hash,
Expand Down

0 comments on commit e0ab8c2

Please sign in to comment.