Skip to content

chore: check matching account delta commitments#1093

Merged
bobbinth merged 10 commits intonextfrom
santiagopittella-account-delta-checks
Jul 22, 2025
Merged

chore: check matching account delta commitments#1093
bobbinth merged 10 commits intonextfrom
santiagopittella-account-delta-checks

Conversation

@SantiagoPittella
Copy link
Copy Markdown
Collaborator

closes #306

@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-account-delta-checks branch from 00bad99 to b257cc5 Compare July 16, 2025 20:13
@SantiagoPittella SantiagoPittella requested review from Mirko-von-Leipzig, bobbinth and igamigo and removed request for Mirko-von-Leipzig July 16, 2025 20:43
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a 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! I left a comment inline. We should probably merge this after 0xMiden/protocol#1603 is merged.

Also, it would be great to add a test to make sure this works (the code in this PR would actually reject all incoming transactions) - but I'm not sure how easy it is.

Comment thread crates/rpc/src/server/api.rs Outdated
Comment thread CHANGELOG.md Outdated
Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; modulo the change from Bobbin.

@SantiagoPittella
Copy link
Copy Markdown
Collaborator Author

Added a test, it is quite a bit hacky but serves it purpose. Also left a an approve on 0xMiden/protocol#1603 but has some merge conflicts, I can address them if you want @bobbinth

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a 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 think the code itself is there, but I wonder if we should improve the construction of a dummy transaction a bit. I left a comment about this inline.

Comment thread crates/rpc/src/tests.rs Outdated
Comment thread crates/rpc/src/tests.rs Outdated
Comment thread crates/rpc/src/tests.rs
Comment on lines +172 to +192
let tx = ProvenTransactionBuilder::new(
account_id,
[8; 32].try_into().unwrap(),
[3; 32].try_into().unwrap(),
[22; 32].try_into().unwrap(), // delta commitment
0.into(),
Word::default(),
u32::MAX.into(),
ExecutionProof::new(Proof::new_dummy(), HashFunction::default()),
)
.account_update_details(AccountUpdateDetails::Delta(
AccountDelta::new(
account_id,
AccountStorageDelta::new(),
AccountVaultDelta::default(),
Felt::default(),
)
.unwrap(),
))
.build()
.unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is an easier way to create a dummy proven transaction. At the very least, would be great to have a simpler way to create dummy ExecutionProof. Maybe we should make a small PR in miden-vm that adds ExecutionProof:dummy()? This way, we could avoid adding miden-air and winterfell dependencies in this PR.

cc @PhilippGackstatter and @igamigo in case you have other suggestions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the changes, but I don't have permission to push in the vm repo. Will sync lambdaclass fork and send it from there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just opened 0xMiden/miden-vm#2007

Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a world where we make it easier to create real txs? I've been thinking about a db-tx like API for a while now, but I don't actually know enough :)

// Create an account with a `Counter` component (however that works).
// This could also come from a mock chain.
let account = AccountBuilder::default().with_component(Counter).build();

// Create an AccountTx which holds a ref to `Account` plus whatever stuff it 
// wants to execute. I imagine this would be some sort of cmd/vm stack.
let mut tx = account.begin_tx();

// This exposes the counter state + API.
// SAFETY: account definitely has a counter component.
let mut counter = tx.get_component(Counter).unwrap();
counter.increment(); // Or whatever method it has.
counter.increment();

// Do other stuff. Grab other components.

// This is now an ExecutedTransaction using the original account state.
let executed_tx = tx.execute().unwrap();

// You can now apply or discard the changes of the tx to the account.
tx.commit().unwrap();
// tx.abort().unwrap();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have something simple to create realistic transactions. Though I guess proving is still an issue ito performance for tests?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just opened 0xMiden/miden-vm#2007

miden-vm v0.16.3 with these changes is now on crates.io.

It would be nice to have something simple to create realistic transactions. Though I guess proving is still an issue ito performance for tests?

Generating a real proof is expensive, most other things shouldn't be.

@PhilippGackstatter @igamigo - anything you can recommend on how to improve creation of a dummy transaction here?

If there isn't anything too simple to do, I'd probably use what we have here and create another issue for improving creation of dummy transactions in miden-base.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For creating ExecutedTransaction it's easiest to use MockChain::build_tx_context. Once we've gotten rid of the pending note APIs in MockChain, there shouldn't really be a way to create transactions that couldn't exist in a real chain, so that would be optimal. This can already be done now just by not using those APIs and instead adding notes via the APIs on MockChainBuilder or creating them yourself.

Once you have an ExecutedTransaction, then you could technically use ProvenTransactionExt::from_executed_transaction_mocked to convert that transaction into a proven transaction with a dummy proof. But I also would like to get rid of it, because it's hacky and could easily break or do something that a real transaction could not do as the codebase evolves.

Ideally, all our prover types in miden-base would all have a prove and prove_dummy function that takes an ExecutedTransaction and turns it into a ProvenTransaction with the only difference being the use of a dummy proof on the latter. That would be much easier to maintain. The batch and block prover roughly have that functionality, but it could be exposed in a better way.

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a 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!

I'm going to merge this PR - but should we create an issue to refactor the test once the changes mentioned by @PhilippGackstatter are implemented in miden-base (I'm guessing this will be in the next release).

@bobbinth bobbinth merged commit 531451a into next Jul 22, 2025
8 checks passed
@bobbinth bobbinth deleted the santiagopittella-account-delta-checks branch July 22, 2025 07:04
@SantiagoPittella
Copy link
Copy Markdown
Collaborator Author

@bobbinth I created #1104 , and put it in the next release (v0.12).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify public accounts' details

4 participants