-
Notifications
You must be signed in to change notification settings - Fork 26
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
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:
|
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 |
Now that 0.5 is 64-bit (only), we really need this to be updated to support 64-bit test vectors (only) We were able to use polkatool (64-bit) and do our services, which touched 23 opcodes and 5 host functions and would like to cover all the opcodes robustly. Can we wrap up 2024 with 64-bit test vectors? |
New PVM test vectors are here; see the changelog for details. |
Thank you @koute for the vectors. I have a question: "Similarly, where ram must be mutated and yet mutable access is not possible, then machine state is unchanged, and the exit reason is a fault with the lowest address to be read which is inaccessible." link |
The are two types of PVMs - outer PVMs and inner PVMs. The outer PVMs run the toplevel JAM services (
So in this case those tests were meant to test the outer PVM behavior where you have read only memory and the program tries to write there. But okay, you're right this might be confusing wrt to the GP; I'll just delete those tests. |
Thanks for the explanation! I wasn’t aware of these distinctions between outer and inner PVMs, but it makes sense now. |
I'm running into another discrepancy with my implementation. The test |
What is the memory size expected by those tests? |
You're correct. The intended behavior is that the address of the page is returned; we will update the GP.
Each test defines the expected memory layout; see |
Thanks, since the graypaper will be updated, I’ll adjust my implementation to return the address of the page. |
Hello @koute I have a question about the tests that use the For example, the test |
@bloppan Whether a basic block starts at a given position or not is not determined by the first instruction of the basic block but by the previous instruction, which is a |
Hi @koute , in the test riscv_rv64um_divu.json, when
The result is The instruction div_u_32 is 32 bits unsigned and it doesn't have sign extension, so I think the result should be |
It's an error in the GP, and the test vector is correct. The 32-bit instruction variants always sign extend. |
With the current Graypaprer spec (0.6.1) the following test vector is incorrect. Test vector
AnalysisThe incorrect current output is explained because some programming languages (such as: RUST en C) provide a negative output for a modulo operation on a negative number.
Source: https://en.wikipedia.org/wiki/Modulo Possible solutions
In summary 'maths' shoud have priority over any implementation ambiguity, therefore as is solution 1 should be the way to go. |
No, it's explained because PVM is based on RISC-V, and that's how the RISC-V's (and also coincidentally how AMD64's) modulo instruction works. It has absolutely nothing to do with how the modulo operator works in any programming language. Two of the main design principles of PVM are:
So the test vector here is correct and is what we want, and changing the semantics here as you suggest is not a good idea as it will provide no practical benefit while having significant practical downsides. Anyway, thank you for bringing this ambiguity to our attention. |
Sure thanks, this is fine of course. But then GP should be adjusted to explicitly state that the modulo operator on a negative number yields a negative number, and not a positive number as expected by 'Maths'. |
Test Case:
|
@clw8998 I can confirm the test vector is correct here and the expected value is To illustrate why let's pick some smaller numbers to make this more obvious. Let's try to divide a positive number first:
Now let's try flipping the sign:
Notice that flipping the sign of one of the inputs doesn't change the numerical value of You're right that mathematically floor does the (in this case) incorrect thing; we will fix the GP. |
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.