-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made initial hash optional (None
for new accounts)
#529
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good! I left a couple of comments inline - the main one is for testing one of the things which I think might have previously been a bug.
Also, let's update the changelog.
@@ -89,7 +91,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().hash(), | |||
tx.initial_account().proof_init_hash(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was an error before - right? I'm thinking we should create a test to make sure that transaction ID remains the same as a transaction moves from executed to proven (or maybe we can integrate into existing tests?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is not a bugfix, just because of changing in input argument it was more convenient to use proof_init_hash
. If it's confusing, it might be better to revert to account's hash usage here and implement additional logic for handling new accounts here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm - I still think it was a bug previously. The test you've added is good - but it only tests the case of existing accounts. This case would have worked fine before, I think.
The case which I think would have failed before is when a new account is involved in a transaction. Could we test this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobbinth I'll implement this test and will fix the bug, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify: I think the bug is already fixed - we just need to confirm this via a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobbinth no, actually no tests failed in next
branch after adding this check into prove_and_verify_transaction
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm - are we sure then that we are testing executing transactions against new accounts? Is there any test that you see that does that?
(it is of course possible that I'm wrong and there was no bug to begin with, but I'd like to be sure).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to analyze our tests and now I can say we don't have any tests in miden-base which produce new account in transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add one such test? This could be something like consuming a note for a new account.
You could do it in a different PR based on this branch, and then, once it is done, we can merge both these PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobbinth, I created an issue for implementing of this test: #529 (comment)
Can we merge this PR then? You would probably want to take a final look.
None
for new accounts)
@@ -89,7 +91,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().hash(), | |||
tx.initial_account().proof_init_hash(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm - I still think it was a bug previously. The test you've added is good - but it only tests the case of existing accounts. This case would have worked fine before, I think.
The case which I think would have failed before is when a new account is involved in a transaction. Could we test this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
edit: ofcourse, don't merge it before finishing @bobbinth 's requests :)
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
c5d581d
to
1a7452a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good! I added a couple of comments inline - but looking this over now, I'm not sure this is as much of an improvement as I originally thought. What worries me a bit is the need for debug_assert_ne!(initial_account_hash, Some(Digest::default()))
in a couple of places as now we can have potentially redundant representation of initial hash (both None
and Digest::default()` semantically mean the same thing).
So, I'm on the fence but leaning a bit toward not merging this. What do you think?
(regardless of the above, I would still rename Account::init_proof_hash()
into just Account::init_hash()
).
objects/src/accounts/mod.rs
Outdated
/// Returns hash of the given account as used for the initial account state hash in transaction | ||
/// proofs. | ||
/// | ||
/// For existing accounts, this is exactly the same as [Account::hash()], however, for new | ||
/// accounts this value is set to `None`. This is because when a transaction is executed | ||
/// against a new account, public input for the initial account state is set to [ZERO; 4] to | ||
/// distinguish new accounts from existing accounts, and `None` returned from this method. | ||
/// indicates that `[ZERO; 4]` should be used as a public input. The actual hash of the initial | ||
/// account state (and the initial state itself), are provided to the VM via the advice provider. | ||
pub fn init_account_hash(&self) -> Option<Digest> { | ||
self.is_new().not().then(|| self.hash()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this method back where it was (i.e., line 93 above). Regarding naming, I'd probably just call it init_hash()
(I think the account
part is not needed as it is a method on Account
struct anyway).
let initial_account_hash = | ||
tx.initial_account().is_new().not().then(|| tx.initial_account().hash()); | ||
Self::new( | ||
tx.initial_account().proof_init_hash(), | ||
initial_account_hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have probably kept this as tx.initial_account().init_hash()
.
@polydez - I'm thinking we should revert most of the changes here except for renaming |
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you!
* 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
* 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
Made
initial_account_hash
inProvenTransaction
,ProvenTransactionBuilder
andTransactionId
constructor optional.I also considered to make
hash
inAccount
optional, but finally decided to leave it without changes.Resolves #522