Add docs for secp256k1 and instruction introspection. (#12369)
This commit is contained in:
28
docs/src/implemented-proposals/instruction_introspection.md
Normal file
28
docs/src/implemented-proposals/instruction_introspection.md
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: instruction introspection
|
||||
---
|
||||
|
||||
## Problem
|
||||
|
||||
Some smart contract programs may want to verify that another Instruction is present in a
|
||||
given Message since that Instruction could be be performing a verification of certain data,
|
||||
in a precompiled function. (See secp256k1\_instruction for an example).
|
||||
|
||||
## Solution
|
||||
|
||||
Add a new sysvar Sysvar1nstructions1111111111111111111111111 that a program can reference
|
||||
and received the Message's instruction data inside, and also the index of the current instruction.
|
||||
|
||||
Two helper functions to extract this data can be used:
|
||||
|
||||
```
|
||||
fn load_current_index(instruction_data: &[u8]) -> u16;
|
||||
fn load_instruction_at(instruction_index: usize, instruction_data: &[u8]) -> Result<Instruction>;
|
||||
```
|
||||
|
||||
The runtime will recognize this special instruction, serialize the Message instruction data
|
||||
for it and also write the current instruction index and then the bpf program can extract the
|
||||
necessary information from there.
|
||||
|
||||
Note: custom serialization of instructions is used because bincode is about 10x slower
|
||||
in native code and exceeds current BPF instruction limits.
|
Reference in New Issue
Block a user