diff --git a/404.html b/404.html index 462c37684..b19f63503 100644 --- a/404.html +++ b/404.html @@ -1,43 +1,46 @@ - - - - - Page not found - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Page not found - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -59,10 +62,10 @@ @@ -216,5 +230,6 @@

- + + diff --git a/CONTRIBUTING.html b/CONTRIBUTING.html index 9ee4e7491..6376b56e5 100644 --- a/CONTRIBUTING.html +++ b/CONTRIBUTING.html @@ -1,42 +1,45 @@ - - - - - Contributing - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Contributing - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -175,7 +192,7 @@

The Kona Book

Contributing

Thank you for wanting to contribute! Before contributing to this repository, please read through this document and -discuss the change you wish to make via issue or in the development telegram.

+discuss the change you wish to make via issue.

Dependencies

Before working with this repository locally, you'll need to install several dependencies:

@@ -250,5 +269,6 @@

Pul

- + + diff --git a/custom.css b/custom.css new file mode 100644 index 000000000..a5fdb46d9 --- /dev/null +++ b/custom.css @@ -0,0 +1,141 @@ +table { + width: 100%; +} + +table thead th { + padding: .75rem; + text-align: left; + font-weight: 500; + line-height: 1.5; + width: auto; +} + +table td { + padding: .75rem; + border: none; +} + +table thead tr { + border: none; + border-bottom: 2px var(--table-border-color) solid; +} + +table tbody tr { + border-bottom: 1px var(--table-border-line) solid; +} + +table tbody tr:nth-child(2n) { + background: unset; +} + +.content h1, +.content h2, +.content h3, +.content h4 { + font-weight: 600; + margin-top: 1.275em; + margin-bottom: .875em; +} + +.ferra { + --bg: #2b292d; + --fg: #fecdb2; + --heading-fg: #fff; + + --sidebar-bg: #383539; + --sidebar-fg: #fecdb2; + --sidebar-non-existant: #feceb454; + --sidebar-active: #ffa07a; + --scrollbar: var(--sidebar-fg); + + --icons: #f6b6c9ba; + --icons-hover: #b7b9cc; + + --links: #ffa07a; + + --inline-code-color: #f6b6c9ba; + + --theme-popup-bg: #383539; + --theme-popup-border: #5f5a60; + --theme-hover: rgba(0, 0, 0, .2); + + --quote-bg: #222124; + --quote-border: #2b292d; + + --table-border-color: #383539; + --table-header-bg: hsla(226, 23%, 31%, 0); + --table-alternate-bg: hsl(226, 23%, 14%); + --table-border-line: #383539; + + --searchbar-border-color: #222124; + --searchbar-bg: #222124; + --searchbar-fg: #fecdb2; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #fce2d4; + --searchresults-border-color: #feceb454; + --search-mark-bg: #f6b6c9ba; + +} + +.ferra .content .header { + color: #fce2d4; +} + +/* highlight.js theme, :where() is used to avoid increasing specificity */ + +:where(.ferra) .hljs { + background: #222124; + color: #feceb4e1; +} + +:where(.ferra) .hljs-comment, +:where(.ferra) .hljs-quote { + color: #6F5D63; +} + +:where(.ferra) .hljs-link, +:where(.ferra) .hljs-meta, +:where(.ferra) .hljs-name, +:where(.ferra) .hljs-regexp, +:where(.ferra) .hljs-selector-class, +:where(.ferra) .hljs-selector-id, +:where(.ferra) .hljs-tag, +:where(.ferra) .hljs-template-variable, +:where(.ferra) .hljs-variable { + color: #fecdb2; +} + +:where(.ferra) .hljs-built_in, +:where(.ferra) .hljs-deletion, +:where(.ferra) .hljs-literal, +:where(.ferra) .hljs-number, +:where(.ferra) .hljs-params, +:where(.ferra) .hljs-type { + color: #f6b6c9; +} + +:where(.ferra) .hljs-attribute, +:where(.ferra) .hljs-section, +:where(.ferra) .hljs-title { + color: #ffa07a; +} + +:where(.ferra) .hljs-addition, +:where(.ferra) .hljs-bullet, +:where(.ferra) .hljs-string, +:where(.ferra) .hljs-symbol { + color: #b1b695; +} + +:where(.ferra) .hljs-keyword, +:where(.ferra) .hljs-selector-tag { + color: #d1d1e0; +} + +:where(.ferra) .hljs-emphasis { + font-style: italic; +} + +:where(.ferra) .hljs-strong { + font-weight: 700; +} diff --git a/fpp-dev/env.html b/fpp-dev/env.html index 5a476df4d..e24be4105 100644 --- a/fpp-dev/env.html +++ b/fpp-dev/env.html @@ -1,42 +1,45 @@ - - - - - Environment - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Environment - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -194,9 +211,9 @@

Reading

sequenceDiagram
     Client->>+Host: Hint preimage (no-op on-chain / read-only mode)
-    Host-->>Host: Prepare Preimage
     Host-->>-Client: Hint acknowledgement
     Client-->>+Host: Preimage Request
+    Host-->>Host: Prepare Preimage
     Host-->>-Client: Preimage Data
 
@@ -228,13 +245,15 @@

Full Example - + - +
@@ -242,13 +261,15 @@

Full Example

@@ -275,5 +296,6 @@

Full Example - + + diff --git a/fpp-dev/epilogue.html b/fpp-dev/epilogue.html index 6631eaeb5..b39a3194e 100644 --- a/fpp-dev/epilogue.html +++ b/fpp-dev/epilogue.html @@ -1,42 +1,45 @@ - - - - - Epilogue - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Epilogue - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -192,13 +209,15 @@

Example

@@ -206,13 +225,15 @@

Example

@@ -239,5 +260,6 @@

Example

- + + diff --git a/fpp-dev/execution.html b/fpp-dev/execution.html index c3cb77596..ecae6b6e9 100644 --- a/fpp-dev/execution.html +++ b/fpp-dev/execution.html @@ -1,42 +1,45 @@ - - - - - Execution - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Execution - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -196,13 +213,15 @@

Example

@@ -210,13 +229,15 @@

Example

@@ -243,5 +264,6 @@

Example

- + + diff --git a/fpp-dev/intro.html b/fpp-dev/intro.html index ce8b5d645..ccc5238f9 100644 --- a/fpp-dev/intro.html +++ b/fpp-dev/intro.html @@ -1,42 +1,45 @@ - - - - - Fault Proof Program Development - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Fault Proof Program Development - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -198,13 +215,15 @@

- + - +
@@ -212,13 +231,15 @@

- - - + + +

@@ -245,5 +266,6 @@

- - - - Prologue - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Prologue - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -202,13 +219,15 @@

Example

@@ -216,13 +235,15 @@

Example

@@ -249,5 +270,6 @@

Example

- + + diff --git a/fpp-dev/targets.html b/fpp-dev/targets.html index 154ec4662..9c59471f0 100644 --- a/fpp-dev/targets.html +++ b/fpp-dev/targets.html @@ -1,42 +1,45 @@ - - - - - Supported Targets - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Supported Targets - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -58,10 +61,10 @@ @@ -176,89 +193,12 @@

The Kona Book

Supported Targets

Kona seeks to support all FPVM targets that LLVM and rustc can offer introductory support for. Below is a matrix of features that Kona offers for each FPVM target:

-
- - +
TargetBuild PipelineIOmallocProgram Stages
cannon & cannon-rs
asterisc
+ +
TargetBuild PipelineIOmalloc
cannon & cannon-rs
asterisc

If there is a feature that you would like to see supported, please open an issue or consider contributing!

-

Cannon (MIPS32r2)

-

Cannon is based off of the mips32r2 target architecture, supporting 55 instructions:

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CategoryInstructionDescription
ArithmeticaddiAdd immediate (with sign-extension).
ArithmeticaddiuAdd immediate unsigned (no overflow).
ArithmeticadduAdd unsigned (no overflow).
LogicalandBitwise AND.
LogicalandiBitwise AND immediate.
BranchbUnconditional branch.
Conditional BranchbeqBranch on equal.
Conditional BranchbeqzBranch if equal to zero.
Conditional BranchbgezBranch on greater than or equal to zero.
Conditional BranchbgtzBranch on greater than zero.
Conditional BranchblezBranch on less than or equal to zero.
Conditional BranchbltzBranch on less than zero.
Conditional BranchbneBranch on not equal.
Conditional BranchbnezBranch if not equal to zero.
LogicalclzCount leading zeros.
ArithmeticdivuDivide unsigned.
Unconditional JumpjJump.
Unconditional JumpjalJump and link.
Unconditional JumpjalrJump and link register.
Unconditional JumpjrJump register.
Data TransferlbLoad byte.
Data TransferlbuLoad byte unsigned.
Data TransferluiLoad upper immediate.
Data TransferlwLoad word.
Data TransferlwrLoad word right.
Data TransfermfhiMove from HI register.
Data TransfermfloMove from LO register.
Data TransfermoveMove between registers.
Data TransfermovnMove conditional on not zero.
Data TransfermovzMove conditional on zero.
Data TransfermtloMove to LO register.
ArithmeticmulMultiply (to produce a word result).
ArithmeticmultuMultiply unsigned.
ArithmeticneguNegate unsigned.
No OpnopNo operation.
LogicalnotBitwise NOT (pseudo-instruction in MIPS).
LogicalorBitwise OR.
LogicaloriBitwise OR immediate.
Data TransfersbStore byte.
LogicalsllShift left logical.
LogicalsllvShift left logical variable.
ComparisonsltSet on less than (signed).
ComparisonsltiSet on less than immediate.
ComparisonsltiuSet on less than immediate unsigned.
ComparisonsltuSet on less than unsigned.
LogicalsraShift right arithmetic.
LogicalsrlShift right logical.
LogicalsrlvShift right logical variable.
ArithmeticsubuSubtract unsigned.
Data TransferswStore word.
Data TransferswrStore word right.
SerializationsyncSynchronize shared memory.
System CallssyscallSystem call.
LogicalxorBitwise XOR.
LogicalxoriBitwise XOR immediate.
-
-

Syscalls

-
- - - - - - - -
$v0system call$a0$a1$a2Effect
4090mmapuint32 addruint32 len🚫Allocates a page from the heap. See heap for details.
4045brk🚫🚫🚫Returns a fixed address for the program break at 0x40000000
4120clone🚫🚫🚫Returns 1
4246exit_groupuint8 exit_code🚫🚫Sets the Exited and ExitCode states to true and $a0 respectively.
4003readuint32 fdchar *bufuint32 countSimilar behavior as Linux/MIPS with support for unaligned reads. See I/O for more details.
4004writeuint32 fdchar *bufuint32 countSimilar behavior as Linux/MIPS with support for unaligned writes. See I/O for more details.
4055fcntluint32 fdint32 cmd🚫Similar behavior as Linux/MIPS. Only the F_GETFL (3) cmd is supported. Sets errno to 0x16 for all other commands
-
-

For all of the above syscalls, an error is indicated by setting the return -register ($v0) to 0xFFFFFFFF (-1) and errno ($a3) is set accordingly. -The VM must not modify any register other than $v0 and $a3 during syscall handling. -For unsupported syscalls, the VM must do nothing except to zero out the syscall return ($v0) -and errno ($a3) registers.

-

Note that the above syscalls have identical syscall numbers and ABIs as Linux/MIPS.

Asterisc (RISC-V)

Asterisc is based off of the rv64gc target architecture, which defines the following extensions:

  • RV64I support
  • -
  • RV64C: Compressed instructions
  • RV32M+RV64M: Multiplication support
  • RV32A+RV64A: Atomics support
  • RV{32,64}{D,F,Q}: no-op: No floating points support (since no IEEE754 determinism with rounding modes etc., nor worth the complexity)
  • @@ -281,13 +220,17 @@

    Asterisc (RIS
  • Ztso: no-op: no need for Total Store Ordering
  • other: revert with error code on unrecognized instructions
  • -

    asterisc supports a plethora of syscalls, documented in the repository. kona offers an interface for +

    asterisc supports a plethora of syscalls, documented in the repository. kona offers an interface for programs to directly invoke a select few syscalls:

    1. EXIT - Terminate the process with the provided exit code.
    2. WRITE - Write the passed buffer to the passed file descriptor.
    3. READ - Read the specified number of bytes from the passed file descriptor.
    +

    Cannon (MIPS32r2)

    +

    Cannon is based off of the mips32r2 target architecture, specified in MIPS32™ Architecture For Programmers Volume III: The MIPS32™ Privileged Resource Architecture

    +

    Syscalls

    +

    Syscalls supported by cannon can be found within the cannon specification here.

    @@ -296,13 +239,15 @@

    Asterisc (RIS @@ -310,13 +255,15 @@

    Asterisc (RIS

    @@ -343,5 +290,6 @@

    Asterisc (RIS - + + diff --git a/glossary.html b/glossary.html index f854edbd3..c6ab464ad 100644 --- a/glossary.html +++ b/glossary.html @@ -1,42 +1,45 @@ - - - - - Glossary - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Glossary - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    @@ -58,10 +61,10 @@ @@ -195,13 +212,15 @@

    Preimage ABI - + - +
    @@ -209,13 +228,15 @@

    Preimage ABI

    @@ -242,5 +263,6 @@

    Preimage ABI - + + diff --git a/index.html b/index.html index e4f32b4d8..2f92f726c 100644 --- a/index.html +++ b/index.html @@ -1,42 +1,45 @@ - - - - - Introduction - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Introduction - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    @@ -58,10 +61,10 @@ @@ -175,7 +192,7 @@

    The Kona Book

    Kona Book

    Documentation for the Kona project.

    -

    +

    📖 kona is in active development, and is not yet ready for use in production. During development, this book will evolve quickly and may contain inaccuracies.

    Please open an issue if you find any errors or have any suggestions for improvements, and also feel free to contribute to the project!

    @@ -217,9 +234,10 @@

    Contributing - +
    @@ -228,9 +246,10 @@

    Contributing - +

    @@ -257,5 +276,6 @@

    Contributing - + + diff --git a/intro.html b/intro.html index e4f32b4d8..2f92f726c 100644 --- a/intro.html +++ b/intro.html @@ -1,42 +1,45 @@ - - - - - Introduction - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Introduction - The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    @@ -58,10 +61,10 @@ @@ -175,7 +192,7 @@

    The Kona Book

    Kona Book

    Documentation for the Kona project.

    -

    +

    📖 kona is in active development, and is not yet ready for use in production. During development, this book will evolve quickly and may contain inaccuracies.

    Please open an issue if you find any errors or have any suggestions for improvements, and also feel free to contribute to the project!

    @@ -217,9 +234,10 @@

    Contributing - +
    @@ -228,9 +246,10 @@

    Contributing - +

    @@ -257,5 +276,6 @@

    Contributing - + + diff --git a/print.html b/print.html index 588135ce0..ac616737d 100644 --- a/print.html +++ b/print.html @@ -1,43 +1,46 @@ - - - - - The Kona Book - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + The Kona Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    @@ -59,10 +62,10 @@ @@ -176,7 +190,7 @@

    The Kona Book

    Kona Book

    Documentation for the Kona project.

    -

    +

    📖 kona is in active development, and is not yet ready for use in production. During development, this book will evolve quickly and may contain inaccuracies.

    Please open an issue if you find any errors or have any suggestions for improvements, and also feel free to contribute to the project!

    @@ -253,9 +267,9 @@

    Reading

    sequenceDiagram
         Client->>+Host: Hint preimage (no-op on-chain / read-only mode)
    -    Host-->>Host: Prepare Preimage
         Host-->>-Client: Hint acknowledgement
         Client-->>+Host: Preimage Request
    +    Host-->>Host: Prepare Preimage
         Host-->>-Client: Preimage Data
     
    @@ -285,89 +299,12 @@

    Full Example

    Supported Targets

    Kona seeks to support all FPVM targets that LLVM and rustc can offer introductory support for. Below is a matrix of features that Kona offers for each FPVM target:

    -
    - - +
    TargetBuild PipelineIOmallocProgram Stages
    cannon & cannon-rs
    asterisc
    + +
    TargetBuild PipelineIOmalloc
    cannon & cannon-rs
    asterisc

    If there is a feature that you would like to see supported, please open an issue or consider contributing!

    -

    Cannon (MIPS32r2)

    -

    Cannon is based off of the mips32r2 target architecture, supporting 55 instructions:

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    CategoryInstructionDescription
    ArithmeticaddiAdd immediate (with sign-extension).
    ArithmeticaddiuAdd immediate unsigned (no overflow).
    ArithmeticadduAdd unsigned (no overflow).
    LogicalandBitwise AND.
    LogicalandiBitwise AND immediate.
    BranchbUnconditional branch.
    Conditional BranchbeqBranch on equal.
    Conditional BranchbeqzBranch if equal to zero.
    Conditional BranchbgezBranch on greater than or equal to zero.
    Conditional BranchbgtzBranch on greater than zero.
    Conditional BranchblezBranch on less than or equal to zero.
    Conditional BranchbltzBranch on less than zero.
    Conditional BranchbneBranch on not equal.
    Conditional BranchbnezBranch if not equal to zero.
    LogicalclzCount leading zeros.
    ArithmeticdivuDivide unsigned.
    Unconditional JumpjJump.
    Unconditional JumpjalJump and link.
    Unconditional JumpjalrJump and link register.
    Unconditional JumpjrJump register.
    Data TransferlbLoad byte.
    Data TransferlbuLoad byte unsigned.
    Data TransferluiLoad upper immediate.
    Data TransferlwLoad word.
    Data TransferlwrLoad word right.
    Data TransfermfhiMove from HI register.
    Data TransfermfloMove from LO register.
    Data TransfermoveMove between registers.
    Data TransfermovnMove conditional on not zero.
    Data TransfermovzMove conditional on zero.
    Data TransfermtloMove to LO register.
    ArithmeticmulMultiply (to produce a word result).
    ArithmeticmultuMultiply unsigned.
    ArithmeticneguNegate unsigned.
    No OpnopNo operation.
    LogicalnotBitwise NOT (pseudo-instruction in MIPS).
    LogicalorBitwise OR.
    LogicaloriBitwise OR immediate.
    Data TransfersbStore byte.
    LogicalsllShift left logical.
    LogicalsllvShift left logical variable.
    ComparisonsltSet on less than (signed).
    ComparisonsltiSet on less than immediate.
    ComparisonsltiuSet on less than immediate unsigned.
    ComparisonsltuSet on less than unsigned.
    LogicalsraShift right arithmetic.
    LogicalsrlShift right logical.
    LogicalsrlvShift right logical variable.
    ArithmeticsubuSubtract unsigned.
    Data TransferswStore word.
    Data TransferswrStore word right.
    SerializationsyncSynchronize shared memory.
    System CallssyscallSystem call.
    LogicalxorBitwise XOR.
    LogicalxoriBitwise XOR immediate.
    -
    -

    Syscalls

    -
    - - - - - - - -
    $v0system call$a0$a1$a2Effect
    4090mmapuint32 addruint32 len🚫Allocates a page from the heap. See heap for details.
    4045brk🚫🚫🚫Returns a fixed address for the program break at 0x40000000
    4120clone🚫🚫🚫Returns 1
    4246exit_groupuint8 exit_code🚫🚫Sets the Exited and ExitCode states to true and $a0 respectively.
    4003readuint32 fdchar *bufuint32 countSimilar behavior as Linux/MIPS with support for unaligned reads. See I/O for more details.
    4004writeuint32 fdchar *bufuint32 countSimilar behavior as Linux/MIPS with support for unaligned writes. See I/O for more details.
    4055fcntluint32 fdint32 cmd🚫Similar behavior as Linux/MIPS. Only the F_GETFL (3) cmd is supported. Sets errno to 0x16 for all other commands
    -
    -

    For all of the above syscalls, an error is indicated by setting the return -register ($v0) to 0xFFFFFFFF (-1) and errno ($a3) is set accordingly. -The VM must not modify any register other than $v0 and $a3 during syscall handling. -For unsupported syscalls, the VM must do nothing except to zero out the syscall return ($v0) -and errno ($a3) registers.

    -

    Note that the above syscalls have identical syscall numbers and ABIs as Linux/MIPS.

    Asterisc (RISC-V)

    Asterisc is based off of the rv64gc target architecture, which defines the following extensions:

  • RV64I support
  • -
  • RV64C: Compressed instructions
  • RV32M+RV64M: Multiplication support
  • RV32A+RV64A: Atomics support
  • RV{32,64}{D,F,Q}: no-op: No floating points support (since no IEEE754 determinism with rounding modes etc., nor worth the complexity)
  • @@ -390,13 +326,17 @@

    Asterisc (RIS
  • Ztso: no-op: no need for Total Store Ordering
  • other: revert with error code on unrecognized instructions
  • -

    asterisc supports a plethora of syscalls, documented in the repository. kona offers an interface for +

    asterisc supports a plethora of syscalls, documented in the repository. kona offers an interface for programs to directly invoke a select few syscalls:

    1. EXIT - Terminate the process with the provided exit code.
    2. WRITE - Write the passed buffer to the passed file descriptor.
    3. READ - Read the specified number of bytes from the passed file descriptor.
    +

    Cannon (MIPS32r2)

    +

    Cannon is based off of the mips32r2 target architecture, specified in MIPS32™ Architecture For Programmers Volume III: The MIPS32™ Privileged Resource Architecture

    +

    Syscalls

    +

    Syscalls supported by cannon can be found within the cannon specification here.

    @@ -456,6 +396,322 @@

    Example

    +

    Kona SDK

    +

    Welcome to the Kona SDK, a powerful set of libraries designed to revolutionize the way developers build proofs for the +OP Stack STF on top of the OP Stack's FPVMs and other verifiable backends like SP-1, Risc0, +Intel TDX, and AMD SEV-SNP. At its core, Kona is built on the principles of modularity, extensibility, +and developer empowerment.

    +

    A Foundation of Flexibility

    +

    The kona repository is more than a fault proof program for the OP Stack — it's an ecosystem of interoperable components, +each crafted with reusability and extensibility as primary goals. While we provide +Fault Proof VM +and "online" backends +for key components like kona-derive and kona-executor, the true power of kona lies in its adaptability.

    +

    Extend Without Forking

    +

    One of Kona's standout features is its ability to support custom features and data sources without requiring you to fork +the entire project. Through careful use of Rust's powerful trait system and abstract interfaces, we've created a +framework that allows you to plug in your own features and ideas seamlessly.

    +

    What You'll Learn

    +

    In this section of the developer book, we'll dive deep into the Kona SDK, covering:

    + +

    Whether you're looking to use Kona as-is, extend its functionality, or create entirely new programs based on its libraries, +this guide is intended to provide you with the knowledge and tools you need to succeed.

    + + + +

    FPVM Backend

    +
    +

    📖 Before reading this section of the book, it is advised to read the Fault Proof Program Environment +section to familiarize yourself with the PreimageOracle IO pattern.

    +
    +

    Kona is effectively split into two parts:

    + +

    This section of the book focuses on the usage of kona-common and kona-preimage to facilitate host<->client +communication for programs running on top of the FPVM targets.

    +

    Host <-> Client Communication API

    +

    The FPVM system API is built on several layers. In this document, we'll cover these layers, from lowest-level to +highest-level API.

    +

    kona-common

    +

    kona-common implements raw syscall dispatch, a default global memory allocator, and a blocking async runtime. +kona-common relies on a minimal linux backend to function, supporting only the syscalls required to implement the +PreimageOracle ABI (read, write, exit_group).

    +

    These syscalls are exposed to the user through the io module directly, with each supported platform implementing the +BasicKernelInterface trait.

    +

    To directly dispatch these syscalls, the io module +exposes a safe API:

    +
    use kona_common::{io, FileDescriptor};
    +
    +// Print to `stdout`. Infalliable, will panic if dispatch fails.
    +io::print("Hello, world!");
    +
    +// Print to `stderr`. Infalliable, will panic if dispatch fails.
    +io::print_err("Goodbye, world!");
    +
    +// Read from or write to a specified file descriptor. Returns a result with the
    +// return value or syscall errno.
    +let _ = io::write(FileDescriptor::StdOut, "Hello, world!".as_bytes());
    +let mut buf = Vec::with_capacity(8);
    +let _ = io::read(FileDescriptor::StdIn, buf.as_mut_slice());
    +
    +// Exit the program with a specified exit code.
    +io::exit(0);
    +
    +

    With this library, you can implement a custom host<->client communication protocol, or extend the existing +PreimageOracle ABI. However, for most developers, we recommend sticking with kona-preimage +when developing programs that target the FPVMs, barring needs like printing directly to +stdout.

    +

    kona-preimage

    +

    kona-preimage is an implementation of the PreimageOracle ABI, built on top of kona-common. This +crate enables synchronous communication between the host and client program, described in +Host <-> Client Communication in the FPP Dev environment section of the +book.

    +

    The crate is built around the PipeHandle, +which serves as a single end of a bidirectional pipe (see: pipe manpage).

    +

    Through this handle, the higher-level constructs can read and write data to the counterparty holding on to the other end +of the pipe, following the protocol below:

    +
    +
    sequenceDiagram
    +    Client->>+Host: Hint preimage (no-op on-chain / read-only mode)
    +    Host-->>-Client: Hint acknowledgement
    +    Client-->>+Host: Preimage Request
    +    Host-->>Host: Prepare Preimage
    +    Host-->>-Client: Preimage Data
    +
    +
    +

    The interfaces of each part of the above protocol are described by the following traits:

    + +

    Each of these traits, however, can be re-implemented to redefine the host<->client communication protocol if the needs +of the consumer are not covered by the to-spec implementations.

    +

    kona-client - Oracle-backed sources (example)

    +

    Finally, in kona-client, implementations of data source traits from kona-derive and kona-executor are implemented +to pull in untyped data from the host by PreimageKey. These data source traits are covered in more detail within +the Custom Backend section, but we'll quickly gloss over them here to build intuition.

    +

    Let's take, for example, OracleL1ChainProvider. +The ChainProvider trait in kona-derive +defines a simple interface for fetching information about the L1 chain. In the OracleL1ChainProvider, this information +is pulled in over the PreimageOracle ABI. There are many other examples of these data source traits, +namely the L2ChainProvider, BlobProvider, TrieProvider, and TrieHinter, which enable the creation of different +data-source backends.

    +

    As an example, let's look at OracleL1ChainProvider::header_by_hash, built on top of the CommsClient trait, which +is a composition trait of the PreimageOracleClient + HintReaderServer traits outlined above.

    +
    #[async_trait]
    +impl<T: CommsClient + Sync + Send> ChainProvider for OracleL1ChainProvider<T> {
    +    type Error = anyhow::Error;
    +
    +    async fn header_by_hash(&mut self, hash: B256) -> Result<Header> {
    +        // Send a hint for the block header.
    +        self.oracle.write(&HintType::L1BlockHeader.encode_with(&[hash.as_ref()])).await?;
    +
    +        // Fetch the header RLP from the oracle.
    +        let header_rlp =
    +            self.oracle.get(PreimageKey::new(*hash, PreimageKeyType::Keccak256)).await?;
    +
    +        // Decode the header RLP into a Header.
    +        Header::decode(&mut header_rlp.as_slice())
    +            .map_err(|e| anyhow!("Failed to decode header RLP: {e}"))
    +    }
    +
    +    // - snip -
    +}
    +
    +

    In header_by_hash, we use the inner HintWriter to send a hint to the host to prepare the block hash preimage. +Then, once we've received an acknowledgement from the host that the preimage has been prepared, we reach out for +the RLP (which is the preimage of the hash). After the RLP is received, we decode the Header type, and return +it to the user.

    + + + +

    Custom Backends

    +

    Understanding the OP Stack STF

    +

    The OP Stack state transition is comprised of two primary components:

    + +

    To prove the correctness of the state transition, Kona composes these two components:

    + +

    kona-client serves as an implementation of this process, capable of deriving and executing a single L2 block in a +verifiable manner.

    +
    +

    📖 Why just a single block by default?

    +

    On the OP Stack, we employ an interactive bisection game that narrows in on the disagreed upon block -> block state +transition before requiring a fault proof to be ran. Because of this, the default implementation only serves +to derive and execute the single block that the participants of the bisection game landed on.

    +
    +

    Backend Traits

    +

    Covered in the FPVM Backend section of the book, kona-client ships with an implementation of +kona-derive and kona-executor's data source traits which pull in data over the PreimageOracle ABI.

    +

    However, running kona-client on top of a different verifiable environment, i.e. a zkVM or TEE, is also possible +through custom implementations of these data source traits.

    +

    op-succinct is an excellent example of both a custom backend and a custom +program, implementing both kona-derive and kona-executor's data source traits backed by sp1_lib::io +in order to:

    +
      +
    1. Execute kona-client verbatim, proving a single block's derivation and execution on SP-1.
    2. +
    3. Derive and execute an entire Span Batch +worth of L2 blocks, using kona-derive and kona-executor.
    4. +
    +

    This section of the book outlines how you can do the same for a different platform.

    +

    Custom kona-derive sources

    +

    Before getting started, we need to create custom implementations of the following traits:

    +
    + + + +
    TraitDescription
    ChainProviderThe ChainProvider trait describes the minimal interface for fetching data from L1 during L2 chain derivation.
    L2ChainProviderThe ChainProvider trait describes the minimal interface for fetching data from the safe L2 chain during L2 chain derivation.
    BlobProviderThe BlobProvider trait describes an interface for fetching EIP-4844 blobs from the L1 consensus layer during L2 chain derivation.
    +
    +

    Once these are implemented, constructing the pipeline is as simple as passing in the data sources to the PipelineBuilder. Keep in mind the requirements for validation of incoming data, depending on your platform. For example, programs +targeting zkVMs must constrain that the incoming data is indeed valid, whereas fault proof programs can offload this validation to the on-chain implementation of the host.

    +
    let chain_provider = ...;
    +let l2_chain_provider = ...;
    +let blob_provider = ...;
    +let l1_origin = ...;
    +
    +let cfg = Arc::new(RollupConfig::default());
    +let attributes = StatefulAttributesBuilder::new(
    +   cfg.clone(),
    +   l2_chain_provider.clone(),
    +   chain_provider.clone(),
    +);
    +let dap = EthereumDataSource::new(
    +   chain_provider.clone(),
    +   blob_provider,
    +   cfg.as_ref()
    +);
    +
    +// Construct a new derivation pipeline.
    +let pipeline = PipelineBuilder::new()
    +   .rollup_config(cfg)
    +   .dap_source(dap)
    +   .l2_chain_provider(l2_chain_provider)
    +   .chain_provider(chain_provider)
    +   .builder(attributes)
    +   .origin(l1_origin)
    +   .build();
    +
    +

    From here, a custom derivation driver is needed to produce the desired execution payload(s). An example of this for +kona-client can be found in the DerivationDriver.

    +

    kona-mpt / kona-executor sources

    +

    Before getting started, we need to create custom implementations of the following traits:

    +
    + + +
    TraitDescription
    TrieDBFetcherThe TrieDBFetcher trait describes the interface for fetching trie node preimages and chain information while executing a payload on the L2 chain.
    TrieDBHinterThe TrieDBHinter trait describes the interface for requesting the host program to prepare trie proof preimages for the client's consumption. For targets with upfront witness generation, i.e. zkVMs, a no-op hinter is exported as NoopTrieDBHinter.
    +
    +

    Once we have those, the StatelessL2BlockExecutor can be constructed like so:

    +
    #![allow(unused)]
    +fn main() {
    +let cfg = RollupConfig::default();
    +let provider = ...;
    +let hinter = ...;
    +
    +let executor = StatelessL2BlcokExecutor::builder(&cfg, provider, hinter)
    +   .with_parent_header(...)
    +   .build();
    +
    +let header = executor.execute_payload(...).expect("Failed execution");
    +}
    +

    Bringing it Together

    +

    Once your custom backend traits for both kona-derive and kona-executor have been implemented, +your final binary may look something like that of kona-client's. +Alternatively, if you're looking to prove a wider range of blocks, op-succinct's range program +offers a good example of running the pipeline and executor across a string of contiguous blocks.

    + + + +

    kona-executor Extensions

    +

    The kona-executor crate offers a to-spec, stateless implementation of the OP Stack STF. However, due to the +power of revm's Handler abstractions, the logic of the STF can be easily modified.

    +

    To register a custom handler, for example to add a custom precompile, modify the behavior of an EVM opcode, +or change the fee handling, StatelessL2BlockExecutorBuilder::with_handle_register is your friend. It accepts a +KonaHandleRegister, which +can be used to take full advantage of revm's Handler API.

    +

    Example - Custom Precompile

    +
    const MY_PRECOMPILE_ADDRESS: Address = u64_to_address(0xFF);
    +
    +fn my_precompile(input: &Bytes, gas_limit: u64) -> PrecompileResult {
    +   Ok(PrecompileOutput::new(50, "hello, world!".as_bytes().into()))
    +}
    +
    +fn custom_handle_register<F, H>(
    +    handler: &mut EvmHandler<'_, (), &mut State<&mut TrieDB<F, H>>>,
    +) where
    +   F: TrieProvider,
    +   H: TrieHinter,
    +{
    +   let spec_id = handler.cfg.spec_id;
    +
    +   handler.pre_execution.load_precompiles = Arc::new(move || {
    +      let mut ctx_precompiles = spec_to_generic!(spec_id, {
    +         revm::optimism::load_precompiles::<SPEC, (), &mut State<&mut TrieDB<F, H>>>()
    +      });
    +
    +      let precompile = PrecompileWithAddress(
    +         MY_PRECOMPILE_ADDRESS,
    +         Precompile::Standard(my_precompile)
    +      );
    +      ctx_precompiles.extend([precompile]);
    +
    +      ctx_precompiles
    +   });
    +}
    +
    +// - snip -
    +
    +let cfg = RollupConfig::default();
    +let provider = ...;
    +let hinter = ...;
    +
    +let executor = StatelessL2BlcokExecutor::builder(&cfg, provider, hinter)
    +   .with_parent_header(...)
    +   .with_handle_register(custom_handle_register)
    +   .build();
    +
    + + +

    Glossary

    This document contains definitions for terms used throughout the Kona book.

    Fault Proof VM

    @@ -475,7 +731,7 @@

    Preimage ABI

    Contributing

    Thank you for wanting to contribute! Before contributing to this repository, please read through this document and -discuss the change you wish to make via issue or in the development telegram.

    +discuss the change you wish to make via issue.

    Dependencies

    Before working with this repository locally, you'll need to install several dependencies: