-
Notifications
You must be signed in to change notification settings - Fork 57
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
Migrate to the VM next
branch (v0.12.0)
#1086
Conversation
During the migration I noticed that our libraries and folders with @plafer, @bitwalker could you tell what could have caused this error? |
To expand on what @Fumuran said our our kernel library is currently structured like this:
We add the modules in In a first step, we assemble the kernel library which works fine. Once that is assembled, we instantiate another assembler with the kernel library to assemble Lines 125 to 131 in d678c9e
This previously worked but no longer does after 0xPolygonMiden/miden-vm#1606. Swapping the order makes everything work and since it seems more logical to add the shared modules first anyway, given the dependence of the kernel lib on the shared modules, I pushed a commit that swaps them. Whether that's the intended behavior is a question for the VM team. |
@@ -33,16 +33,16 @@ codegen-units = 1 | |||
lto = true | |||
|
|||
[workspace.dependencies] | |||
assembly = { package = "miden-assembly", version = "0.11", default-features = false } | |||
assembly = { package = "miden-assembly", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } |
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 note: We should either pin the dependencies to a specific commit on next to avoid breakage if next is updated, or merge #1059 shortly after this one (which points to the element-addressable-memory
branch).
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 hope that we will be able to merge the element-addressable memory PR right after this one, but I agree that it makes sense to pin the specific commit
fn set_advice<S: ProcessState>( | ||
&mut self, | ||
process: &S, | ||
injector: AdviceInjector, | ||
) -> Result<HostResponse, ExecutionError> { | ||
match injector { | ||
AdviceInjector::SigToStack { .. } => self.on_signature_requested(process), | ||
injector => self.adv_provider.set_advice(process, &injector), | ||
} |
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 had to remove the set_advice
and get_advice
implementations because they no longer exist on the AdviceProvider
trait. We previously used this to call on_signature_requested
when the SigToStack
injector (now SystemEvent
) was provided (e.g. which is what adv.push_sig.rpo_falcon512
results in, like in rpo_falcon512::verify
(https://github.com/0xPolygonMiden/miden-vm/blob/b13ed4d67c13d99d750d7b91293a91b0185cb84d/stdlib/asm/crypto/dsa/rpo_falcon512.masm#L599)).
This is failing now in a bunch of tests with AdviceMapKeyNotFound
. I assume it's this part where it originates: https://github.com/0xPolygonMiden/miden-vm/blob/8420dcd37078c605f90c87d233eb964ae3468fc9/processor/src/operations/sys_ops/sys_event_handlers.rs#L650-L652.
As I understand it, Miden VM previously delegated signature creation to the AdviceProvider / Host whereas now, in the above code, it requires the public key/secret key key-value pair to be present in the advice map.
We have an account component rpo_falcon512
which users may or may not add to their account code (https://github.com/0xPolygonMiden/miden-base/blob/next/miden-lib/asm/account_components/rpo_falcon_512.masm). If they do, we need to be able to inject a signature into the advice stack. These components are generic and so we likely shouldn't add code in miden-base which injects the public-secret key-pair since that would couple us to this component and wouldn't work for other user-written components.
If the above is true, I'm not sure how we should handle this change. The above code requires the secret key to be mapped into the advice provider. I don't think it is a good idea to expose a secret key to so many parts of code. Typically one would want to minimize exposure of the key to make the attack surface as minimal as possible. In a practical scenario, secret keys will be stored in key stores or secure hardware modules where they won't be accessible, so users need to be able to compute signatures themselves in an impl TransactionAuthenticator
, which is invoked by TransactionExecutor
to generate a signature, which in turn needs to be able to injected into the advice map.
Not sure if I'm missing something or if that is still possible, but that's my current understanding.
cc @plafer
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 think the core of the issue is that we have FalconSigToStack
event classified as a system even, and thus it is not "overridable", but we do need to override it in this case. There is an issue in miden-vm
to make handling of events more customizable and to reclassify a number of these events as "library" rather than system events. But that'll take some time to implement.
One stop-gap solution could be to just make an exception for the FalconSigToStack
event. Then, the default host would call the current method for generating the signature (which relies on the private key being in the advice provider), but our transaction host could do something else for it. I'll make a quick PR with this solution.
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 implemented the stop-gap solution in 0xPolygonMiden/miden-vm#1630. @Fumuran - could you try it out and let me know if it works?
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. I left a couple of comments inline.
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.
// add the shared modules to the kernel lib under the kernel::util namespace | ||
main_assembler.add_modules_from_dir(kernel_namespace, &shared_path)?; | ||
main_assembler.add_modules_from_dir(kernel_namespace.clone(), &shared_path)?; | ||
main_assembler.add_modules_from_dir(kernel_namespace, &source_dir.join("lib"))?; |
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.
Should we add a comment here to say that the order is important?
@bobbinth This PR works on your |
Let's not merge anything yet - but you could update #1084 to be based on this PR, no? |
#1084 is updated, although P2ID and P2IDR tests are still failing, because there is no fix of the system event in the |
Ah, my bad, I forgot to do so after rebase. Updated the base branch to be |
Now all the test should be passing, right? |
I don't think it was an explicit goal but since the fix is simple, I would leave things as-is. |
This PR updates the code of the
miden-base
to be compatible with the next version of the Miden VM.