Provide the offset of the instruction data to the VM's r2
register
#316
Replies: 6 comments 7 replies
-
If we start building things around this pattern, if we just push the pointer of ABIv2 into r2, existing Rust programs will inherit compatibility with ABIv2 by default. We can also just not embark on multi-year-long wastes of time that take the chain down all the time. |
Beta Was this translation helpful? Give feedback.
-
i was told to come here to voice my support for this change. I am in favor of doing this, but with setting let ix_data = unsafe { core::slice::from_raw_parts(r2, r2.sub(8).cast::<usize>().load()) }; which would compile to something like
instead of having to do
before we can construct a slice. Additionally, any static offsets are easier to read in the assembly, e.g. // let ix_data = unsafe { core::slice::from_raw_parts(r2, r2.sub(8).cast::<usize>().load()) };
let disc = ix_data[0];
let some_u64_payload = unsafe { ix_data.add(1).cast::<u64>().read_unaligned() }; compile to
instead of
|
Beta Was this translation helpful? Give feedback.
-
I like this change a lot, assuming it doesn't break existing programs! Very simple to understand and seems like it's effectively already been implemented. |
Beta Was this translation helpful? Give feedback.
-
I've enabled a non-voting node on mb with all four GPRs (r2, r3, r4, r5) occupied to see who breaks. As for the specific implementation, the offset being the data, not the length, works for me. |
Beta Was this translation helpful? Give feedback.
-
I'm in favor of this change too, so I'm pushing for it. But I prefer the approach of @cavemanloverboy |
Beta Was this translation helpful? Give feedback.
-
OK, mb node is healthy and I'll continue to monitor it. In the meantime, the SIMD is up, with @cavemanloverboy's implementation request mentioned above. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
The current serialization layout of the VM's input region makes it inefficient for sBPF programs to access the serialized instruction data directly. This stems from the need to parse the entire accounts section in order to locate the instruction data.
When using default entrypoints like the SDK's
entrypoint!
the input region is fully deserialized into the canonical&Pubkey
,&[AccountInfo]
and&[u8]
parameters. Optimized alternatives, such as Pinocchio'slazy_program_entrypoint!
allow skipping most of this deserialization if the program doesn’t need all accounts.However, even with Pinocchio's optimized entrypoint, it's not possible to access the instruction data without first walking over the entire accounts section to calculate the offset of the instruction data.
Suggested Change
A number of contributors have suggested providing the offset of the serialized instruction data to the VM's
r2
register.Programs currently accept a pointer to the beginning of the input region, which is the number of accounts and also the beginning of the accounts section.
With the additional
r2
argument, entrypoints can look like this:The input region pointer is provided as a pointer in the
r1
register. The instruction data offset would be provided as au64
offset tor2
, not a pointer.We can provide the new additional parameter to r2 in two ways:
r2
r2
ABI v2
The new serialization layout presented in SIMD-0177 (Program Runtime ABI v2) also solves the aforementioned inefficiency.
Once a program has been updated to use the new ABI layout proposed in SIMD-0177, they would have no use for the offset in
r2
anymore. Hence, this is one main reason we are hesitant to add the change.Example implementation:
https://github.com/buffalojoec/solana/blob/4bd1624e7b64a45d4802fbed673543a11d9fc6b3/programs/bpf_loader/src/lib.rs#L1652-L1658
https://github.com/buffalojoec/solana-sdk/blob/3a881e89a783f8cf1a102de90e294b88c5f1ba82/program-entrypoint/src/lib.rs#L206-L229
https://github.com/anza-xyz/mollusk/blob/r2-input-data-offset/test-programs/register-metadata/src/lib.rs
Beta Was this translation helpful? Give feedback.
All reactions