-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add initial PVM test vectors #3
base: master
Are you sure you want to change the base?
Conversation
pvm/README.md
Outdated
* `name` -- a unique identifier for the test | ||
* `initial_regs` -- the initial value of each of the 13 registers; these need to be set *before* the test program is executed | ||
* `code` -- the code blob of the program to be executed as part of the test | ||
* `expected_status` -- the way the program is supposed to end; currently it can be one of the following: | ||
- `"trap"` -- the execution ended with a trap (the `trap` instruction was executed, the execution went "out of bounds", an invalid jump was made, or an invalid instruction was executed) | ||
- `"halt"` -- the execution finished gracefully (a dynamic jump to address `0xffff0000` was made) | ||
* `expected_regs` -- the expected values of each of the 13 registers *after* the test program is executed |
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.
Would be nice if these could be done to the level of the Safrole test vectors - i.e. referencing the relevant symbols and equations in the GP and providing a good ASN definition.
Specifically, it looks like these test vectors are for (207) Psi, but omit the arguments and results for gas, memory and initial instruction counter.
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.
Would be nice if these could be done to the level of the Safrole test vectors - i.e. referencing the relevant symbols and equations in the GP and providing a good ASN definition.
Sure, I can do that.
Specifically, it looks like these test vectors are for (207) Psi, but omit the arguments and results for gas, memory and initial instruction counter.
Yes. The omissions were intentional, since no tests use them right now. This is only temporary of course.
The test writes a zero here, so make sure the register initially contains something *other* than a zero so that we can actually see that it was modified.
@koute Can you kindly add test cases for the host functions of Appendix B.6/B.7/B.8? Here are 4 groups, in priority order:
The first group is DA-centric, the second group is service+VM setup/invocations -- the first 2 groups are valuable to connect to code up connections to state merklization + erasure coding, whereas the latter 2 groups can be done later as they are bookkeeping oriented and are easy to get right once we solve the first 2 groups. Thank you! |
How are these programs supposed to be consumed? The program blob parse expects things like the program to start with BLOB_MAGIC. |
For these initial test vectors the priority is to get basic tests for the instruction set ready. I will also add some host call tests later, but comprehensive test suite for all host calls is probably out-of-scope, at least for pure PVM tests.
Take a look at the schema to see to which parameters of the Ψ equation from the Gray Paper they correspond to, and use them accordingly to test your own PVM implementation.
Yes, my PolkaVM uses its own container format for the program blobs which the GP doesn't use. PolkaVM is not the source of truth for how a PVM should work, the GP is. |
@koute Good point on the GP being the source of truth.
For context I'm building FFI bindings to PolkaVM. So would you say that these tests in particular are for folks who are implementing the PVM from scratch? |
We passed all the test vectors you provided so far. What is the reason for the GP needing to support 32-bit registers while the contracts pallet should definitely aim for 64-bit? After you have 64-bit PVM engineered for contracts pallet shouldn't the GP be adjusted to be 64-bit? |
Yes.
This is only temporary. We will be migrating GP to 64-bit too; we just need to first prototype the design in PolkaVM to make sure it's solid. (Otherwise we might end up with a design that looks good on paper but is bad in practice.) We're working on it right now. (That said, the changes when migrating to 64-bit won't be huge - the registers will be extended and there will be a couple of new instructions, but that's about it as far as major changes go.) As far as the instruction set and the core semantics are concerned, we aim to have both PolkaJAM and pallet-contracts in alignment and we're making effort to make sure they don't diverge. (With PolkaJAM having the priority here, but I believe we can support both with the same VM.) |
In GP(A.1), the program is defined as follows:
Edit: Looks like I misunderstood |
@ec2 Where did you read that these are SCALE compact integers? These are not SCALE compact integers. From the GP: If you look at this equation and crosscheck it with how This is a slightly different varint serialization format which:
|
@koute GP(Appendix I.3) says that I'm not super familiar with SCALE so I assumed that the screenshot just formally describes how SCALE does variable int encoding. |
@koute Sorry to keep hounding you here! I think I found a discrepancy between the testcases and the GP. In the test, the supplied arg to The test case has only TLDR: I think the impl of PVM that made these test cases have the arguments for |
Alright, we don't want to interrupt your deep work but legend has it you implemented PVM in a day =) so if its not too much to ask ... could you give us the simplest "Jam Service" byte code (for a refine+accumulate) for us to implement many of the basic host functions? Given one good example we can probably fill in the rest and provide a few more back. My idea of the simplest "Jam Service" byte code is to compute the sum of squares for a set of integer work items, like If not, do you have a better recommendation for simplest "Jam Service"? Or, a strategy that is better than hand building byte code? This sort of baby JAM test case will help teams get baby JAM implementations blood flowing, and set up a low V (like V=6) cluster complete with QUIC, erasure coding, Patricia Merkle Trie, BMT proofs, and so on. |
I am confused about trap vs halt vs panic in PVM. In GP, the trap instruction will exit with the black square, so does the jump to Lines 53 to 55 in a2b1870
Another question. |
@ec2 Yes, indeed, there is. We will fix it soon. Thanks! We highly appreciate anyone who helps crosscheck these.
@sourabhniyogi The rumors of my exploits seem to be grossly exaggerated; it was actually two days, not one. :P Anyway, we will most likely put up some more tests out in the future, but for now if you quickly want something to test with then your best bet would be to build one yourself. You don't have to build a blob by hand; you could use my work-in-progress PVM assembler. For example:
This will output the program in a PolkaVM-specific container (which is not part of the GP), but you can extract the code blob with a simple Rust program - use
Hm, you're right that the trap instruction in the GP is specified to halt instead of panicking; this should have been a panic instead. I'll see about correcting this; thanks. |
Hello @koute , I recently encountered some issues while using your PVM. Here’s my code:
When I use the following command to compile:
The bytecode content of
My question is, how do I extract the pure program portion as defined in GP_0.36(213), because it seems the first part contains some ASCII-encoded section names. ASCII encoded section name:
GP_0.36(213) should be:
|
Also found some weird encoding results. Missing operend:txt code:
after assembly:
Jump to a weird position:txt code:
after assembly:
|
That's a
No, it's not missing. It's just a zero length varint, and that is expected behavior. To save space a trailing varint in an instruction doesn't have to be encoded if it's zero. Side note: this instruction can be encoded in multiple ways, for example:
All of these encodings are valid and encode to the same instruction
You're incorrectly parsing the jump destinations as absolute, but they are encoded relative. (Notice: 17 + 55 = 72) |
hey @koute, I've noticed the Here is the
where the actual code is:
breaking down the code we have:
So, the expected value: |
@EclesioMeloJunior You can check out the disassembler/debugger we've put together here https://pvm.fluffylabs.dev/ Recently polkavm support was merged, so it might help you debug the exact problem you're having - obviously don't take it as a source of truth - that should only be the Gray Paper. I think the issue is with how you interpret the bytes |
@EclesioMeloJunior: @tomusdrw is correct; you're not properly sign extending the value from Remember that the varints are always sign extended to full 32-bits, that is: if the most significant bit of the value (as it is encoded) is Here are some examples:
|
Most testvectors should be fixed (are currently invalid) due to a strict decoding issue of |
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/contracts-on-assethub-roadmap/9513/25 |
Hi. How do the signed values work? For example in "inst_div_signed"? rA=8 (value: 2147483664) How is register 9 expected to be 3988183920? |
I recommend reading this article on Wikipedia.
It's not. It's expected to be |
Initial PVM test vectors/test suite.
This is still incomplete; not every instruction is covered yet and only very simple test cases were added. I will be expanding this aggressively.
Since we will still be making some changes (e.g. 64-bit support) I'll be explicitly versioning this, with a detailed changelog so that anyone who uses these tests can easily keep up.