From 7dd4de80eb0ba74d3668ef6e89c7305d14ac233d Mon Sep 17 00:00:00 2001 From: sakridge Date: Mon, 21 Sep 2020 13:50:23 -0700 Subject: [PATCH] Add docs for secp256k1 and instruction introspection. (#12369) --- .../instruction_introspection.md | 28 +++++++++++++++++++ .../secp256k1_instruction.md | 5 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 docs/src/implemented-proposals/instruction_introspection.md rename docs/src/{proposals => implemented-proposals}/secp256k1_instruction.md (94%) diff --git a/docs/src/implemented-proposals/instruction_introspection.md b/docs/src/implemented-proposals/instruction_introspection.md new file mode 100644 index 0000000000..99627e628a --- /dev/null +++ b/docs/src/implemented-proposals/instruction_introspection.md @@ -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; +``` + +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. diff --git a/docs/src/proposals/secp256k1_instruction.md b/docs/src/implemented-proposals/secp256k1_instruction.md similarity index 94% rename from docs/src/proposals/secp256k1_instruction.md rename to docs/src/implemented-proposals/secp256k1_instruction.md index de2b1bee38..7c20d0eb97 100644 --- a/docs/src/proposals/secp256k1_instruction.md +++ b/docs/src/implemented-proposals/secp256k1_instruction.md @@ -57,8 +57,9 @@ Cost of the transaction will count the number of signatures to verify multiplied ## Optimization notes -The operation will have to take place after deserialization and accounts load assuming the transaction references external -accounts for the inputs. It should be relatively easy though to scan the transaction for introspection inputs. +The operation will have to take place after (at least partial) deserialization, but all inputs come +from the transaction data itself, this allows it to be relatively easy to execute in parallel to +transaction processing and PoH verification. ## Other solutions