Skip to content
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

[Docs]: Update Transaction #1114

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

phklive
Copy link
Contributor

@phklive phklive commented Jan 29, 2025

In this PR I propose to update the Transaction section of the Miden documentation:

  • more explanative
  • more approachable for new developers
  • shortened
  • simplified
  • re-phrased
  • updated structure

Additional questions:

  • How can we describe the different components of a transaction considering that there is no Transaction object but two:
  1. ExecutedTransaction
  2. ProvenTransaction

Closes: 0xPolygonMiden/miden-docs#15

@phklive phklive added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Jan 29, 2025
@phklive phklive self-assigned this Jan 29, 2025
@phklive phklive marked this pull request as ready for review January 29, 2025 15:55
Copy link
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 left some comments inline. Overall, I think we are missing quite a bit of content. Basically, we want the user to come away from this section knowing how transactions work and what one can do with them. This needs to be high-level content but it needs to be comprehensive. For example, we don't need to explain about kernels, execution contents, procedure names etc. but we probably should cover how how notes are executed, why we need transaction scripts, who defines note sequencing, how can transactions be authenticated (e.g., do they need to be signed like in other chains?) etc.

docs/architecture/transaction.md Outdated Show resolved Hide resolved
docs/architecture/transaction.md Outdated Show resolved Hide resolved

In Miden, a `Transaction` represents the state transition of a single account. A `Transaction` takes a single [account](accounts.md) and one or more [notes](notes.md), and none or one script (piece of code executed after all notes have been executed) as input, and outputs the same account with a potentially updated state, together with some potential newly created notes.

![Transaction diagram](../img/architecture/transaction/transaction-diagram.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

To me this digram is somewhat confusing. I would use something simpler (which have a simpler version in the deck). The proportions of the graphic are also off (it is too big).

Comment on lines +15 to +17
## Transaction core components

WIP
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are missing quite a bit of information about what transactions are and what they can do and maybe this is the section this info is supposed to go to? The things we should cover (at the high level):

  • How transaction execution flows - e.g., note scripts are executed one by one, this sequence is defined by whoever crates the transaction, note scripts can call procedures exposed by the account interface - but they cannot do arbitrary things etc.
    • We could give a bit of info about things like note inputs and note args and how they affect note execution - but maybe that's too much and should go somewhere else.
  • I would explain a bit more about the transaction script and why it is needed. maybe give a couple of examples of what it is used for (same goes for notes).
  • We should also mention other interesting things about transactions - e.g., that it is possible set transaction expiration height (both accounts and notes can do this), that we can read states of other accounts in a transaction (via foreign procedure invocation).

We don't need to go into all of the above topics in depth, but we should make sure a somewhat technical person can come away with good understanding of how transactions work and what they provide.

I would also add a "real-world" example of how transactions accomplish some task - e.g., transferring funds from one account to another.

docs/architecture/transaction.md Outdated Show resolved Hide resolved

There are two types of transactions in Miden: **local transactions** and **network transactions**.

![Local vs network transactions](../img/architecture/transaction/local-vs-network-transaction.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this comes from our deck, but this diagram is actually not correct. All steps happen in both cases - just who does them differs.

Comment on lines +32 to +38
This is where clients executing the transactions also generate the proofs of their correct execution. So, no additional work needs to be performed by the network.

Local transactions are useful for several reasons:

1. They are cheaper (i.e., lower fees) as zk-proofs are already generated by the clients.
2. They allow fairly complex computations because the proof size doesn't grow linearly with the complexity of the computation.
3. They enable privacy as neither the account state nor account code are needed to verify the zk-proof.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can improve this section to make sure it really stands out. Local transactions is something that most other chains cannot do. They basically enabled theoretically unbounded computation complexity (e.g., no more gas limits). I would also make sure that this is not just for users - apps can benefit from this too. e.g., we can have apps running their logic off-chain (either in a centralized or decentralized mode) to minimize fees, not be subject to network congestion etc.

Comment on lines +46 to +47
1. Clients may not have sufficient resources to generate zk-proofs.
2. Executing many transactions against the same public account by different clients is challenging, as the account state changes after every transaction. Due to this, the Miden node/operator acts as a "synchronizer" to execute transactions sequentially by feeding the output of the previous transaction into the input of the next.
Copy link
Contributor

Choose a reason for hiding this comment

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

The first point is not correct - I would get rid of it. Network transactions are there basically for 2 reasons:

  1. Handling of public shared state. This is an important thing to cover somewhat in depth because after reading about local transactions, savvy developers will immediately have questions about how how public shared state works.
  2. Ensuring liveness for public accounts. This is something we haven't really covered previously, but is a pretty cool thing which would basically let the network update some accounts only during some blocks. For example, let's say for 59 minutes of every hour only some permissioned set of entities can update a given account, but every last minute of the hour, the network can do it. This way, as long as the permissioned set does what it is supposed to, the computational burden on the network is minimal. But if the permissioned set stops working, the network could still update the account (though at a much slower pace).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify why the first point is not true?

I have the feeling that the second point is a very specific use case of networked tx's and does not really have it's place there. But it could be argued.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you clarify why the first point is not true?

Network transactions do not help resource-constrained clients. That is, for the network transaction to happen, the client still needs to put a note intended for this transaction on-chain. So, they still need to generate a proof for this transaction. What helps resource-constrained clients is delegated proving - but that's different from network transactions.

I have the feeling that the second point is a very specific use case of networked tx's and does not really have it's place there. But it could be argued.

Yeah, we probably don't need to describe it in such detail but maybe there is a good way to mention it in 1 - 2 sentences as an example of what network transactions could be used for.

Copy link
Contributor Author

@phklive phklive Jan 31, 2025

Choose a reason for hiding this comment

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

Network transactions do not help resource-constrained clients. That is, for the network transaction to happen, the client still needs to put a note intended for this transaction on-chain. So, they still need to generate a proof for this transaction. What helps resource-constrained clients is delegated proving - but that's different from network transactions.

Does that mean that in Miden there is no way for a user to make a transaction without executing the VM and Prover?

Would a user have the ability to make a transaction like in Ethereum by simply signing a message? ( I guess this would work for public accounts but not for local / private accounts )

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean that in Miden there is no way for a user to make a transaction without executing the VM and Prover?

Without executing - no, without proving, yes. That is, the user could execute a transaction but delegate proving to someone else (at the expense of giving up privacy to this someone).

Would a user have the ability to make a transaction like in Ethereum by simply signing a message? ( I guess this would work for public accounts but not for local / private accounts )

Doing something like this today would be pretty difficult. The biggest question is, what message would the user sign? For example, if we want someone else to execute a transaction on our behalf, we need to give them enough info to complete the transaction. Currently, the means a signature over a message that is derived from: initial account state, final account state, all input notes of the transaction, all output notes of a transaction. If someone can produce such a message (and a corresponding signature), then someone else can create a transaction for them.

However, building such a messages for a general transaction would mean executing the VM (to get the final state of the account and output notes). For a specialized transaction, we can probably compute these without running the VM (e.g., if we consume a P2ID note, we know how the account will be updated - so, no need to run the VM to get the account's final state).

Another option could be to re-define what is being signed (and this can be specified on per-account basis). Maybe it is enough to sign over initial account state + input notes, but this needs to be analyzed more carefully to make sure we don't open up any attack vectors.

Comment on lines +49 to +60
## Transaction lifecycle

In Miden, every `Transaction` is executed within the Miden VM. Throughout its lifetime, a `Transaction` progresses through various phases:

1. **Compilation:** All `Transaction` inputs (account, notes, script) are compiled into an executable Miden program.
2. **Execution:** The `Transaction` program is executed within the Miden VM, which produces outputs (updated account, notes).
3. **Proving:** The executed `Transaction` is proven by the Miden prover.

![Transaction execution process](../img/architecture/transaction/transaction-execution-process.png)

> **Info**
> - One of the main reasons for separating out the execution and proving steps is to allow _stateless provers_; i.e., the executed transaction has all the data it needs to re-execute and prove a transaction without database access. This supports easier proof-generation distribution.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need to mention compilation/execution/proving in this section - it feels like lower-level details that can be explained somewhere else. I would talk about proving costs and delegated proving though - but maybe as a part of some other section above.

docs/architecture/transaction.md Outdated Show resolved Hide resolved
@phklive phklive requested a review from Dominik1999 January 30, 2025 16:51
@phklive
Copy link
Contributor Author

phklive commented Jan 30, 2025

Thank you! Looks good. I left some comments inline. Overall, I think we are missing quite a bit of content. Basically, we want the user to come away from this section knowing how transactions work and what one can do with them. This needs to be high-level content but it needs to be comprehensive. For example, we don't need to explain about kernels, execution contents, procedure names etc. but we probably should cover how how notes are executed, why we need transaction scripts, who defines note sequencing, how can transactions be authenticated (e.g., do they need to be signed like in other chains?) etc.

Indeed, this was a first pass where I mainly remove the unnecessary things and update to the new style. There is definitely some content missing indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog This PR does not require an entry in the `CHANGELOG.md` file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the transaction section in the docs
2 participants