Skip to content

Commit

Permalink
feat(svm): more SBPFv3 support and add Poseidon Hash syscall (#566)
Browse files Browse the repository at this point in the history
* svm: add a CLI for changing the version

* svm: fixup version and add a zig file for `syscall_static.so`

* svm: overhaul the ELF parser for V3 support

* svm: implement poseidon syscall

* svm: implement the rest of the V2 memory operations

* svm: fix up negative call labels

* svm: add the rest of the poseidon syscall tests

* cleanup some random stuff

* svm.elf: cleanup validate

* svm: add some ELF parser tests

* ci: remove cache workaround with `build.zig.zon` update
  • Loading branch information
Rexicon226 authored Feb 14, 2025
1 parent 7c39406 commit 024cd52
Show file tree
Hide file tree
Showing 39 changed files with 1,350 additions and 370 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ jobs:
- attach_workspace:
at: workspace
- restore_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v6
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v7
- run:
name: Build
command: |
apt update && apt install wget -y
./scripts/proxy_workaround.sh workspace/zig/zig
workspace/zig/zig build -Denable-tsan=true -p workspace/zig-out -Dcpu=x86_64_v3 --summary all
- save_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v6
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v7
paths:
- .zig-cache
- ~/.cache/zig
Expand All @@ -99,15 +99,15 @@ jobs:
- attach_workspace:
at: workspace
- restore_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-release-v3
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-release-v4
- run:
name: Build
command: |
apt update && apt install wget -y
./scripts/proxy_workaround.sh workspace/zig/zig
workspace/zig/zig build sig fuzz -Dno-run -Denable-tsan=false -Doptimize=ReleaseSafe -Dcpu=x86_64_v3 -p workspace/zig-out-release --summary all
- save_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-release-v3
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-release-v4
paths:
- .zig-cache
- ~/.cache/zig
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
- attach_workspace:
at: workspace
- restore_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v6
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v7
- run:
name: Build and Test
command: workspace/zig/zig build test -Denable-tsan=true -Dblockstore=hashmap -Dcpu=x86_64_v3 -Dfilter="ledger" --color off --summary all
Expand All @@ -161,7 +161,7 @@ jobs:
# Restore the cache in order to have access to the files which the DWARF info
# is referencing when dumping stack traces.
- restore_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v6
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v7
- run:
name: Test
# Disable network-accessing tests for this job, which behave badly on circleci
Expand All @@ -174,7 +174,7 @@ jobs:
- attach_workspace:
at: workspace
- restore_cache:
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v6
key: linux-x86_64-0.13.0-{{ checksum "build.zig.zon" }}-v7
- run:
name: Build
command: workspace/zig/zig build test -Dcpu=x86_64_v3 -Denable-tsan=false -Dno-run -Dno-network-tests --summary all
Expand Down
6 changes: 6 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub fn build(b: *Build) void {
const zstd_dep = b.dependency("zstd", dep_opts);
const zstd_mod = zstd_dep.module("zstd");

const poseidon_dep = b.dependency("poseidon", dep_opts);
const poseidon_mod = poseidon_dep.module("poseidon");

const rocksdb_dep = b.dependency("rocksdb", dep_opts);
const rocksdb_mod = rocksdb_dep.module("rocksdb-bindings");

Expand All @@ -78,6 +81,8 @@ pub fn build(b: *Build) void {
sig_mod.addImport("base58", base58_mod);
sig_mod.addImport("zig-cli", zig_cli_mod);
sig_mod.addImport("zstd", zstd_mod);
sig_mod.addImport("poseidon", poseidon_mod);

switch (blockstore_db) {
.rocksdb => sig_mod.addImport("rocksdb", rocksdb_mod),
.hashmap => {},
Expand Down Expand Up @@ -146,6 +151,7 @@ pub fn build(b: *Build) void {
unit_tests_exe.root_module.addImport("base58", base58_mod);
unit_tests_exe.root_module.addImport("zig-network", zig_network_mod);
unit_tests_exe.root_module.addImport("zstd", zstd_mod);
unit_tests_exe.root_module.addImport("poseidon", poseidon_mod);
switch (blockstore_db) {
.rocksdb => unit_tests_exe.root_module.addImport("rocksdb", rocksdb_mod),
.hashmap => {},
Expand Down
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
.url = "git+https://github.com/Syndica/base58-zig#e6337e7eb3dc7ca77cad4c3b2fe4a34357bd50ea",
.hash = "122092353c0b494c2a4968c10a527dc90d6e89eaac48637fda1a0af3efd948bf4ee3",
},
.poseidon = .{
.url = "git+https://github.com/Rexicon226/zig-poseidon#82e41845bfc689192359639fef5bb89c452388b2",
.hash = "12208f0d8388111308c919d73c24e9a595c3f2b5f83edf2cebf10598f8439fe33843",
},
},
}
Binary file removed data/test-elfs/bss_section.so
Binary file not shown.
Binary file added data/test-elfs/bss_section_sbpfv0.so
Binary file not shown.
Binary file removed data/test-elfs/data_section.so
Binary file not shown.
Binary file added data/test-elfs/data_section_sbpfv0.so
Binary file not shown.
63 changes: 43 additions & 20 deletions data/test-elfs/elf.ld
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
PHDRS
{
text PT_LOAD ;
rodata PT_LOAD ;
data PT_LOAD ;
dynamic PT_DYNAMIC ;
}
ENTRY ( entrypoint )
SECTIONS
{
. = SIZEOF_HEADERS;
.text : { *(.text*) } :text
.rodata : { *(.rodata*) } :rodata
.data.rel.ro : { *(.data.rel.ro*) } :rodata
.dynamic : { *(.dynamic) } :dynamic
.dynsym : { *(.dynsym) } :data
.dynstr : { *(.dynstr) } :data
.rel.dyn : { *(.rel.dyn) } :data
.data : { *(.data*) } :data
.bss : { *(.bss*) } :data
.text 0x000000000 : {
*(.text*)
} :text
.rodata 0x100000000 : {
*(.rodata*)
*(.data.rel.ro*)
BYTE(0);
. = ALIGN(8);
} :rodata
.bss.stack 0x200000000 (NOLOAD) : {
_stack_start = .;
. = . + 0x1000;
_stack_end = .;
. = ALIGN(8);
} :stack
.bss.heap 0x300000000 (NOLOAD) : {
_heap_start = .;
. = . + 0x1000;
_heap_end = .;
. = ALIGN(8);
} :heap
.dynsym 0xFFFFFFFF00000000 : {
*(.dynsym)
. = ALIGN(8);
} :dynsym
.strtab : { *(.strtab) } :other
.dynstr : { *(.dynstr) } :other
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gnu.hash*)
*(.hash*)
*(*hash*)
*(.bss*)
*(.data*)
*(.rel.dyn*)
*(.dynamic)
}
}

PHDRS
{
text PT_LOAD FLAGS(1);
rodata PT_LOAD FLAGS(4);
stack PT_GNU_STACK FLAGS(6);
heap PT_LOAD FLAGS(6);
dynsym PT_NULL FLAGS(0);
other PT_NULL FLAGS(0);
}
26 changes: 26 additions & 0 deletions data/test-elfs/elf_sbpfv0.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PHDRS
{
text PT_LOAD ;
rodata PT_LOAD ;
data PT_LOAD ;
dynamic PT_DYNAMIC ;
}

SECTIONS
{
. = SIZEOF_HEADERS;
.text : { *(.text*) } :text
.rodata : { *(.rodata*) } :rodata
.data.rel.ro : { *(.data.rel.ro*) } :rodata
.dynamic : { *(.dynamic) } :dynamic
.dynsym : { *(.dynsym) } :data
.dynstr : { *(.dynstr) } :data
.rel.dyn : { *(.rel.dyn) } :data
.data : { *(.data*) } :data
.bss : { *(.bss*) } :data
/DISCARD/ : {
*(.eh_frame*)
*(.gnu.hash*)
*(.hash*)
}
}
Binary file added data/test-elfs/poseidon_test.so
Binary file not shown.
Loading

0 comments on commit 024cd52

Please sign in to comment.