diff --git a/.github/workflows/audity.yml b/.github/workflows/audity.yml new file mode 100644 index 000000000..14828a7f3 --- /dev/null +++ b/.github/workflows/audity.yml @@ -0,0 +1,29 @@ +# .github/workflows/libwasmvm_audit.yml +name: libwasmvm_audit + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + libwasmvm_audit: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Install OpenSSL + run: | + sudo apt update + sudo apt install libssl-dev + - name: Show Rust version information + run: rustc --version && cargo --version && rustup --version + - name: Install cargo-audit + run: cargo install --debug cargo-audit --version 0.21.0 + - name: Run cargo-audit + working-directory: libwasmvm + run: cargo audit diff --git a/.github/workflows/libwasmvm-sanity.yml b/.github/workflows/libwasmvm-sanity.yml new file mode 100644 index 000000000..ce8a4f60e --- /dev/null +++ b/.github/workflows/libwasmvm-sanity.yml @@ -0,0 +1,51 @@ +# .github/workflows/libwasmvm_sanity.yml +name: libwasmvm_sanity + +on: + push: + branches: + - main + - 0.14-dev + - GoIter-creation + - release/* + pull_request: + branches: + - main + +jobs: + libwasmvm_sanity: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Show Rust version information + run: rustc --version && cargo --version && rustup --version + - name: Add Rust components + run: rustup component add rustfmt + - name: Ensure libwasmvm/bindings.h is up-to-date + working-directory: libwasmvm + run: | + cargo check + CHANGES_IN_REPO=$(git status --porcelain bindings.h) + if [[ -n "$CHANGES_IN_REPO" ]]; then + echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:" + git status && git --no-pager diff + exit 1 + fi + - name: Ensure internal/api/bindings.h is up to date + run: diff libwasmvm/bindings.h internal/api/bindings.h + - name: Check Rust formatting + working-directory: libwasmvm + run: cargo fmt -- --check + - name: Run unit tests + working-directory: libwasmvm + run: cargo test + - name: Build docs + working-directory: libwasmvm + run: cargo doc --no-deps + - name: Test docs + working-directory: libwasmvm + run: | + sed -i '/^crate-type = \["cdylib"\]/d' Cargo.toml + cargo test --doc diff --git a/libwasmvm/bindings.h b/libwasmvm/bindings.h index 1f356a7fc..1032e17af 100644 --- a/libwasmvm/bindings.h +++ b/libwasmvm/bindings.h @@ -53,9 +53,9 @@ enum GoError { }; typedef int32_t GoError; -typedef struct cache_t { +typedef struct CacheT { -} cache_t; +} CacheT; /** * A view into an externally owned byte slice (Go `[]byte`). @@ -412,33 +412,33 @@ typedef struct GasReport { uint64_t used_internally; } GasReport; -struct cache_t *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg); +struct CacheT *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg); -struct UnmanagedVector store_code(struct cache_t *cache, +struct UnmanagedVector store_code(struct CacheT *cache, struct ByteSliceView wasm, bool checked, bool persist, struct UnmanagedVector *error_msg); -void remove_wasm(struct cache_t *cache, +void remove_wasm(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct UnmanagedVector load_wasm(struct cache_t *cache, +struct UnmanagedVector load_wasm(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -void pin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); +void pin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -void unpin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); +void unpin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct AnalysisReport analyze_code(struct cache_t *cache, +struct AnalysisReport analyze_code(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct Metrics get_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg); +struct Metrics get_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg); -struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg); +struct UnmanagedVector get_pinned_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg); /** * frees a cache reference @@ -448,9 +448,9 @@ struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct Unmanage * This must be called exactly once for any `*cache_t` returned by `init_cache` * and cannot be called on any other pointer. */ -void release_cache(struct cache_t *cache); +void release_cache(struct CacheT *cache); -struct UnmanagedVector instantiate(struct cache_t *cache, +struct UnmanagedVector instantiate(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView info, @@ -463,7 +463,7 @@ struct UnmanagedVector instantiate(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector execute(struct cache_t *cache, +struct UnmanagedVector execute(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView info, @@ -476,7 +476,7 @@ struct UnmanagedVector execute(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector migrate(struct cache_t *cache, +struct UnmanagedVector migrate(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -488,7 +488,7 @@ struct UnmanagedVector migrate(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector migrate_with_info(struct cache_t *cache, +struct UnmanagedVector migrate_with_info(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -501,7 +501,7 @@ struct UnmanagedVector migrate_with_info(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector sudo(struct cache_t *cache, +struct UnmanagedVector sudo(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -513,7 +513,7 @@ struct UnmanagedVector sudo(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector reply(struct cache_t *cache, +struct UnmanagedVector reply(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -525,7 +525,7 @@ struct UnmanagedVector reply(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector query(struct cache_t *cache, +struct UnmanagedVector query(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -537,7 +537,7 @@ struct UnmanagedVector query(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_open(struct cache_t *cache, +struct UnmanagedVector ibc_channel_open(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -549,7 +549,7 @@ struct UnmanagedVector ibc_channel_open(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_connect(struct cache_t *cache, +struct UnmanagedVector ibc_channel_connect(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -561,7 +561,7 @@ struct UnmanagedVector ibc_channel_connect(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_close(struct cache_t *cache, +struct UnmanagedVector ibc_channel_close(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -573,7 +573,7 @@ struct UnmanagedVector ibc_channel_close(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_receive(struct cache_t *cache, +struct UnmanagedVector ibc_packet_receive(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -585,7 +585,7 @@ struct UnmanagedVector ibc_packet_receive(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_ack(struct cache_t *cache, +struct UnmanagedVector ibc_packet_ack(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -597,7 +597,7 @@ struct UnmanagedVector ibc_packet_ack(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache, +struct UnmanagedVector ibc_packet_timeout(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -609,7 +609,7 @@ struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_source_callback(struct cache_t *cache, +struct UnmanagedVector ibc_source_callback(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -621,7 +621,7 @@ struct UnmanagedVector ibc_source_callback(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_destination_callback(struct cache_t *cache, +struct UnmanagedVector ibc_destination_callback(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, diff --git a/libwasmvm/src/cache.rs b/libwasmvm/src/cache.rs index 064abcd5b..2e77dd6a8 100644 --- a/libwasmvm/src/cache.rs +++ b/libwasmvm/src/cache.rs @@ -15,9 +15,9 @@ use crate::querier::GoQuerier; use crate::storage::GoStorage; #[repr(C)] -pub struct cache_t {} +pub struct CacheT {} -pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache> { +pub fn to_cache(ptr: *mut CacheT) -> Option<&'static mut Cache> { if ptr.is_null() { None } else { @@ -30,12 +30,12 @@ pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache, -) -> *mut cache_t { +) -> *mut CacheT { let r = catch_unwind(|| do_init_cache(config)).unwrap_or_else(|err| { handle_vm_panic("do_init_cache", err); Err(Error::panic()) }); - handle_c_error_ptr(r, error_msg) as *mut cache_t + handle_c_error_ptr(r, error_msg) as *mut CacheT } fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache, Error> { @@ -49,7 +49,7 @@ fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache, ) { @@ -110,7 +110,7 @@ fn do_remove_wasm( #[no_mangle] pub extern "C" fn load_wasm( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) -> UnmanagedVector { @@ -140,7 +140,7 @@ fn do_load_wasm( #[no_mangle] pub extern "C" fn pin( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) { @@ -170,7 +170,7 @@ fn do_pin( #[no_mangle] pub extern "C" fn unpin( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) { @@ -278,7 +278,7 @@ fn set_to_csv(set: BTreeSet>) -> String { #[no_mangle] pub extern "C" fn analyze_code( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) -> AnalysisReport { @@ -357,7 +357,7 @@ impl From for Metrics { #[no_mangle] pub extern "C" fn get_metrics( - cache: *mut cache_t, + cache: *mut CacheT, error_msg: Option<&mut UnmanagedVector>, ) -> Metrics { let r = match to_cache(cache) { @@ -412,7 +412,7 @@ impl From for PinnedMetrics { #[no_mangle] pub extern "C" fn get_pinned_metrics( - cache: *mut cache_t, + cache: *mut CacheT, error_msg: Option<&mut UnmanagedVector>, ) -> UnmanagedVector { let r = match to_cache(cache) { @@ -442,7 +442,7 @@ fn do_get_pinned_metrics( /// This must be called exactly once for any `*cache_t` returned by `init_cache` /// and cannot be called on any other pointer. #[no_mangle] -pub extern "C" fn release_cache(cache: *mut cache_t) { +pub extern "C" fn release_cache(cache: *mut CacheT) { if !cache.is_null() { // this will free cache when it goes out of scope let _ = unsafe { Box::from_raw(cache as *mut Cache) }; diff --git a/libwasmvm/src/calls.rs b/libwasmvm/src/calls.rs index b49ac142a..8fcb3b289 100644 --- a/libwasmvm/src/calls.rs +++ b/libwasmvm/src/calls.rs @@ -16,7 +16,7 @@ use cosmwasm_vm::{ use crate::api::GoApi; use crate::args::{ARG1, ARG2, ARG3, CACHE_ARG, CHECKSUM_ARG, GAS_REPORT_ARG}; -use crate::cache::{cache_t, to_cache}; +use crate::cache::{to_cache, CacheT}; use crate::db::Db; use crate::error::{handle_c_error_binary, Error}; use crate::handle_vm_panic::handle_vm_panic; @@ -35,7 +35,7 @@ fn into_backend(db: Db, api: GoApi, querier: GoQuerier) -> Backend