# Meet Chicory ## exploit the power of WebAssembly on the server side!
Andrea Peruffo
X: @and_prf
GitHub: #andreaTP
# WebAssembly sometimes abbreviated Wasm
defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment. [https://en.wikipedia.org/wiki/WebAssembly](https://en.wikipedia.org/wiki/WebAssembly)
# Binary Format ``` 00000000 00 61 73 6d 0b 00 00 00 04 74 79 70 65 87 80 80 |.asm.....type...| 00000010 80 00 01 40 02 01 01 01 01 08 66 75 6e 63 74 69 |...@......functi| 00000020 6f 6e 82 80 80 80 00 01 00 06 6d 65 6d 6f 72 79 |on........memory| 00000030 85 80 80 80 00 80 02 80 02 01 06 65 78 70 6f 72 |...........expor| 00000040 74 86 80 80 80 00 01 00 03 61 64 64 04 63 6f 64 |t........add.cod| 00000050 65 8c 80 80 80 00 01 86 80 80 80 00 00 14 00 14 |e...............| 00000060 01 40 04 6e 61 6d 65 86 80 80 80 00 01 03 61 64 |.@.name.......ad| 00000070 64 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ |d.| ```
# Text Format ``` (module (type $0 (func (param i32 i32) (result i32))) (export "add" $add) (func $add (type $0) (param $var$0 i32) (param $var$1 i32) (result i32) (i32.add (get_local $var$0) (get_local $var$1) ) ) ) ```
# Executable programs ``` execute add 1 2 > 3 ```
# Executable programs - `get_local $var$0` | push 1
| 1 |
# Executable programs - `get_local $var$1` | push 2
| 2 |
| 1 |
# Executable programs - `i32.add` | pop 2
| 1 |
# Executable programs - `i32.add` | pop 1
# Executable programs - `i32.add` | push 3
| 3 |
# Java Bytecode ``` public int add(int, int); Code: 0: iload_1 1: iload_2 2: iadd 3: ireturn ```
# Facilitating interactions
image source
# The problems it solves - sandboxed execution - memory control - speed - standard (W3C)
# Where is it used? - Web Browsers - FaaS - Extensions
# The two sides of it
- compile to Wasm - execute Wasm code
image source
# Demo compile to wasm
# Demo run the compiled wasm
# Demo run the compiled wasm in a Spring app
# Demo -optional- run the compiled wasm in a wasm interpreter within a Spring app
# Spring -> Chicory -> wasm-interp -> Go func
# Demo - real world - OPA https://www.openpolicyagent.org/ - Write a rule https://play.openpolicyagent.org/p/0FjgydMuVo - Compile to Wasm - Use in an interceptor for authz
# More use-cases
# Thanks and Q&A
https://github.com/dylibso/chicory
https://github.com/andreaTP/devoxxbe-2024-deck