Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

nlgripto/begin #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/actions/deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: deps
description: 'Build and cache dependencies'
inputs:
deps-script-path:
description: 'Path of deps.sh script'
required: true
default: './firedancer/deps.sh'
deps-bundle-path:
description: 'Path of deps-bundle.sh script'
required: true
default: './firedancer/contrib/deps-bundle.sh'
outputs: {}
runs:
using: composite
steps:
- name: Has apt-get?
shell: bash
run: |
if command -v apt-get > /dev/null 2>&1; then
echo "HAS_APT_GET=1" >> $GITHUB_ENV
else
echo "HAS_APT_GET=0" >> $GITHUB_ENV
fi

- name: apt-get update
shell: bash
run: sudo apt-get update
if: env.HAS_APT_GET == '1'

- id: deps-sh-hash
shell: bash
run: sha256sum '${{ inputs.deps-script-path }}' | awk '{print "HASH=" $1}' >> "$GITHUB_OUTPUT"

- id: deps-sh-cache
uses: actions/cache@v3
with:
path: deps-bundle.tar.zst
key: ${{ runner.os }}-deps-sh-${{ steps.deps-sh-hash.outputs.HASH }}

- name: Install system level dependencies
shell: bash
run: FD_AUTO_INSTALL_PACKAGES=1 '${{ inputs.deps-script-path }}' check

- name: Install dependencies from cache
shell: bash
run: tar -Izstd -xvf deps-bundle.tar.zst
if: steps.deps-sh-cache.outputs.cache-hit == 'true'

- name: Install dependencies from scratch
shell: bash
run: |
FD_AUTO_INSTALL_PACKAGES=1 '${{ inputs.deps-script-path }}' install
'${{ inputs.deps-bundle-path }}'
if: steps.deps-sh-cache.outputs.cache-hit != 'true'
18 changes: 18 additions & 0 deletions .github/actions/hugepages/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: hugepages
description: 'Setup 1 GiB gigantic pages'
inputs:
count:
description: 'Number of huge pages'
required: true
default: '64'
outputs: {}
runs:
using: composite
steps:
- shell: bash
run: |
set -x
sudo ./firedancer/src/util/shmem/fd_shmem_cfg fini || true
sudo ./firedancer/src/util/shmem/fd_shmem_cfg init 0666 $USER "" || true
sudo ./firedancer/src/util/shmem/fd_shmem_cfg alloc '${{ inputs.count }}' gigantic 0
sudo chown -R $USER:$USER /mnt/.fd
37 changes: 37 additions & 0 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Industry
on:
workflow_call:
workflow_dispatch:
jobs:
publish:
name: Publish Industry Targets
strategy:
matrix:
feature_set: [modern]
runs-on:
ubuntu-22.04
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to verify this works in "real" GHA

steps:
- uses: actions/checkout@v4
with:
submodules: true
# doesnt work locally
# - uses: ./.github/actions/hugepages
# - uses: ./.github/actions/deps

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add back the timestamp

- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.FUZZ_SERVICE_ACCT_JSON_BUNDLE }}

- uses: firedancer-io/fuzzbot-builder@main
name: Build Solana Target
with:
command: apt update && apt install -y zip && pushd rust/diff-sbpf_loader && cargo build &&
mkdir ../../artdir && popd && zip ./labs-industry-bundle.zip rust/target/debug/*.so

- id: 'upload-file'
uses: 'google-github-actions/upload-cloud-storage@v2'
with:
path: './labs-industry-bundle.zip'
destination: firedancer-builds.isol-clusterfuzz.appspot.com/industry-labs/industry-labs.${{ github.sha }}.zip
# - run: gcloud storage cp ./labs-industry-bundle.zip $CF_BUCKET/industry-labs/industry-labs.${{ github.sha }}.zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env

1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
16 changes: 16 additions & 0 deletions rust/diff-sbpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "diff-sbpf_loader"
version = "0.1.0"
edition = "2021"

[lib]
crate-type=["cdylib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
solana-bpf-loader-program = { git = "https://github.com/solana-labs/solana", rev = "ded307adb328a34a56a66b5a04eb662fd590484a", version = "1.17.0" }
solana-logger = { git = "https://github.com/solana-labs/solana", rev = "ded307adb328a34a56a66b5a04eb662fd590484a", version = "1.17.0" }
solana-metrics = { git = "https://github.com/solana-labs/solana", rev = "ded307adb328a34a56a66b5a04eb662fd590484a", version = "1.17.0" }
solana-program-runtime = { git = "https://github.com/solana-labs/solana", rev = "ded307adb328a34a56a66b5a04eb662fd590484a", version = "1.17.0" }
solana-sdk = { git = "https://github.com/solana-labs/solana", rev = "ded307adb328a34a56a66b5a04eb662fd590484a", version = "1.17.0" }
3 changes: 3 additions & 0 deletions rust/diff-sbpf_loader/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:-C llvm-args='-sanitizer-coverage-level=4'");
}
148 changes: 148 additions & 0 deletions rust/diff-sbpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
use solana_program_runtime::compute_budget::ComputeBudget;
use solana_program_runtime::invoke_context::InvokeContext;
use solana_program_runtime::solana_rbpf::elf::Executable;

use std::sync::Arc;
use std::mem;

use std::fmt::Debug;

#[derive(PartialEq)]
pub struct LoadedProgram {
pub rodata: Vec<u8>,
pub entry_pc: u64,
pub text_off: i64,
pub text_sz: u64,
}

impl Debug for LoadedProgram {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
writeln!(f, "Rodata size: 0x{:x}", self.rodata.len())?;
writeln!(f, "Entrypoint: 0x{:x}", self.entry_pc)?;
writeln!(f, "Text offset: 0x{:x}", self.text_off)?;
writeln!(f, "Text size: 0x{:x}", self.text_sz)?;
Ok(())
}
}


#[no_mangle]
pub extern "C" fn industry_init() {
println!("init rust")
}

#[no_mangle]
extern "C" fn industry_test_one(
out_result_sz: *mut usize,
out_result_buf: *mut u8,
result_buf_sz: usize,
data: *const u8,
data_sz: usize,
) -> i32 {

// The layout of result (out_result_buf) is:
// - i32: 0 if unpack succeded, -1 if failed
// - u64: len of rodata:
// - uchar[]: rodata
// - u64: entry_pc
// - i64: text_off
// - u64: text_sz


let elf = unsafe {
if data.is_null() {
let buffer = std::slice::from_raw_parts_mut(out_result_buf, result_buf_sz);
buffer[..mem::size_of::<i32>()].copy_from_slice(&(-1 as i32).to_ne_bytes());
*out_result_sz = mem::size_of::<i32>();
return 0
}

std::slice::from_raw_parts(data, data_sz)
};

let mres = load_program_labs(elf);

if let Err(_e) = mres {
unsafe {
let buffer = std::slice::from_raw_parts_mut(out_result_buf, result_buf_sz);
buffer[..mem::size_of::<i32>()].copy_from_slice(&(-1 as i32).to_ne_bytes());
*out_result_sz = mem::size_of::<i32>();
return 0
}
}

let res = mres.unwrap();
unsafe {
*out_result_sz = 0;
let mut last_sz;

let mut buffer = std::slice::from_raw_parts_mut(out_result_buf, result_buf_sz);

// - i32: 0 if unpack succeded, -1 if failed
last_sz = mem::size_of::<i32>();
buffer[..last_sz].copy_from_slice(&(0 as i32).to_ne_bytes());
buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

// - u64: len of rodata
last_sz = mem::size_of::<u64>();
buffer[..last_sz].copy_from_slice(&(res.rodata.len()).to_ne_bytes());
buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

// - uchar[]: rodata
last_sz = res.rodata.len();
buffer[..last_sz].copy_from_slice(&res.rodata);
buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

// - u64: entry_pc
last_sz = mem::size_of::<u64>();
buffer[..last_sz].copy_from_slice(&(res.entry_pc).to_ne_bytes());
buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

// - i64: text_off
last_sz = mem::size_of::<i64>();
buffer[..last_sz].copy_from_slice(&(res.text_off).to_ne_bytes());
buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

// - u64: text_sz
last_sz = mem::size_of::<u64>();
buffer[..last_sz].copy_from_slice(&(res.text_sz).to_ne_bytes());
// buffer = &mut buffer[last_sz..];
*out_result_sz += last_sz;

0
}
}


fn load_program_labs(elf: &[u8]) -> Result<LoadedProgram, String> {
let feature_set = solana_sdk::feature_set::FeatureSet::all_enabled();
let compute_budget = ComputeBudget::default();

let loader = solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1(
&feature_set,
&compute_budget,
// reject_deployment_of_broken_elfs
true,
// debugging_features
false,
)
.map_err(|e| format!("{:?}", e))?;
let loader = Arc::new(loader);

let executable: Executable<InvokeContext<'_>> =
Executable::load(elf, loader).map_err(|e| format!("Labs load err: {:?}", e))?;

let ro_section = executable.get_ro_section().to_vec();
let (text_vaddr, text_section) = executable.get_text_bytes();
Ok(LoadedProgram {
rodata: ro_section,
entry_pc: executable.get_entrypoint_instruction_offset() as u64,
text_off: (text_vaddr - 0x1_0000_0000) as i64,
text_sz: (text_section.len() as u64) & (!7u64), // not necessarily multiple of 8
})
}