Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
54b1e17
feat: add NotAuthorizedSponsor error code
aguilar1x Feb 26, 2026
0a74667
feat: add sponsored vault storage keys and helpers
aguilar1x Feb 26, 2026
4a22fc6
feat: add sponsored vault function signatures to trait
aguilar1x Feb 26, 2026
9a3bab1
feat: implement sponsored vault functions
aguilar1x Feb 26, 2026
1d957e2
test: add sponsored vault tests
aguilar1x Feb 26, 2026
5bb86b9
chore: update sdk versión 21.0.0 to 23.4.0
aguilar1x Feb 26, 2026
18411e0
chore: add information of cargotoml-profile
aguilar1x Feb 26, 2026
0f5f9f0
fix: namespace VCStatus by (owner, vc_id) and refactor storage layout
aguilar1x Mar 1, 2026
0e36116
feat: add events module for all state-changing operations
aguilar1x Mar 1, 2026
fe94e05
fix: issuer authorization — clear deny list on re-auth and deduplicate
aguilar1x Mar 1, 2026
32f3a2e
fix: contract entrypoints — multiple security and logic fixes
aguilar1x Mar 1, 2026
c105702
test: add auth guard tests and push regression tests
aguilar1x Mar 1, 2026
a80f18b
fix: scripts — fail-fast, TTL constants and idempotent deployment
aguilar1x Mar 1, 2026
5d1b65d
chore: set crate-type to rlib only
aguilar1x Mar 1, 2026
c1d9de0
chore: ignore fuzz corpus and artifacts
aguilar1x Mar 1, 2026
2064d04
chore: Update of unnecessary comments as they were follow-up for read…
aguilar1x Mar 1, 2026
45e43a2
fix: write VCStatus for destination vault in push
aguilar1x Mar 1, 2026
3891d09
fix: guard push against overwriting existing vc_id in destination vault
aguilar1x Mar 1, 2026
c11e46e
feat: add cargo-fuzz suite for vc-vault
aguilar1x Mar 1, 2026
ea09a0a
docs: add setup and fuzzing guide for vc-vault
aguilar1x Mar 1, 2026
c977375
docs: add security audit report for vc-vault v0.21.0
aguilar1x Mar 2, 2026
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/target
/Cargo.lock
**/target
**/Cargo.lock
tarpaulin-report.html
**/test_snapshots/
.soroban/
**/fuzz/corpus/
**/fuzz/artifacts/
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ resolver = "2"
members = ["contracts/vc-vault"]

[workspace.package]
version = "0.20.0"
version = "0.21.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/ACTA-Team/contracts"

[workspace.dependencies]
soroban-sdk = { version = "21.0.0" }
soroban-sdk = { version = "23.4.0" }

[profile.release]
opt-level = "z"
Expand All @@ -22,6 +22,7 @@ panic = "abort"
codegen-units = 1
lto = true

# For more information about this profile see https://soroban.stellar.org/docs/basic-tutorials/logging#cargotoml-profile
[profile.release-with-logs]
inherits = "release"
debug-assertions = true
2 changes: 1 addition & 1 deletion contracts/vc-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
repository = { workspace = true }

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

[dependencies]
soroban-sdk = { workspace = true }
Expand Down
62 changes: 62 additions & 0 deletions contracts/vc-vault/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[workspace]

[package]
name = "vc-vault-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
arbitrary = { version = "1", features = ["derive"] }

[dependencies.vc-vault-contract]
path = ".."

[dependencies.soroban-sdk]
version = "23.4.0"
features = ["testutils"]

# Disable default features to speed up build; re-enable only what fuzz targets need.
[profile.release]
opt-level = 3
debug = false

[[bin]]
name = "fuzz_issue"
path = "fuzz_targets/fuzz_issue.rs"
test = false
doc = false

[[bin]]
name = "fuzz_revoke"
path = "fuzz_targets/fuzz_revoke.rs"
test = false
doc = false

[[bin]]
name = "fuzz_verify_vc"
path = "fuzz_targets/fuzz_verify_vc.rs"
test = false
doc = false

[[bin]]
name = "fuzz_push"
path = "fuzz_targets/fuzz_push.rs"
test = false
doc = false

[[bin]]
name = "fuzz_issuer_ops"
path = "fuzz_targets/fuzz_issuer_ops.rs"
test = false
doc = false

[[bin]]
name = "fuzz_lifecycle"
path = "fuzz_targets/fuzz_lifecycle.rs"
test = false
doc = false
28 changes: 28 additions & 0 deletions contracts/vc-vault/fuzz/fuzz_targets/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! Shared helpers for all fuzz targets.

use soroban_sdk::{testutils::Address as _, Address, Env, String as SStr};
use vc_vault_contract::contract::{VcVaultContract, VcVaultContractClient};

/// Truncate a Rust string to a safe length and convert to a Soroban String.
/// Soroban Strings are limited; 256 bytes is well within bounds.
pub fn s(env: &Env, input: &str) -> SStr {
let safe = &input[..input.len().min(256)];
SStr::from_str(env, safe)
}
Comment on lines +8 to +11
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Potential panic on multi-byte UTF-8 boundary slice.

Slicing &input[..input.len().min(256)] at a byte index can panic if input contains multi-byte UTF-8 characters and the slice boundary falls mid-character. Fuzz inputs from arbitrary can produce arbitrary UTF-8 sequences, making this likely to trigger.

🐛 Proposed fix using char_indices for safe truncation
 pub fn s(env: &Env, input: &str) -> SStr {
-    let safe = &input[..input.len().min(256)];
+    let safe = if input.len() <= 256 {
+        input
+    } else {
+        // Find the last valid char boundary at or before byte 256
+        match input.char_indices().take_while(|(i, _)| *i < 256).last() {
+            Some((i, c)) => &input[..i + c.len_utf8()],
+            None => "",
+        }
+    };
     SStr::from_str(env, safe)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn s(env: &Env, input: &str) -> SStr {
let safe = &input[..input.len().min(256)];
SStr::from_str(env, safe)
}
pub fn s(env: &Env, input: &str) -> SStr {
let safe = if input.len() <= 256 {
input
} else {
// Find the last valid char boundary at or before byte 256
match input.char_indices().take_while(|(i, _)| *i < 256).last() {
Some((i, c)) => &input[..i + c.len_utf8()],
None => "",
}
};
SStr::from_str(env, safe)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contracts/vc-vault/fuzz/fuzz_targets/common.rs` around lines 8 - 11, The
current s function slices input by bytes which can panic on a multi-byte UTF-8
boundary; update s to safely truncate to a valid UTF-8 boundary before calling
SStr::from_str: compute the largest byte index <= 256 that is at a char boundary
(e.g., use input.char_indices() to find the last index < = 256, or fall back to
whole input), create safe from that valid slice, and pass it to
SStr::from_str(env, safe); keep references to the same symbols (s, safe,
SStr::from_str, Env) so reviewers can find the change quickly.


/// Create a fresh environment with all auths mocked, register the contract,
/// initialize it, and return (env, contract_id, admin, owner, issuer, client).
pub fn setup(
env: &Env,
) -> (Address, Address, Address, Address, VcVaultContractClient<'_>) {
env.mock_all_auths();
let admin = Address::generate(env);
let issuer = Address::generate(env);
let owner = Address::generate(env);
let cid = env.register(VcVaultContract, ());
let client = VcVaultContractClient::new(env, &cid);
client.initialize(&admin);
client.create_vault(&owner, &s(env, "did:fuzz:owner"));
client.authorize_issuer(&owner, &issuer);
(admin, issuer, owner, cid, client)
}
41 changes: 41 additions & 0 deletions contracts/vc-vault/fuzz/fuzz_targets/fuzz_issue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Fuzzes issue() with arbitrary vc_id, vc_data, issuer_did, and fee_override.
//!
//! Invariant checked: if issue() succeeds, verify_vc() must return Valid
//! and list_vc_ids() must contain the vc_id.

#![no_main]

mod common;

use arbitrary::Arbitrary;
use common::{s, setup};
use libfuzzer_sys::fuzz_target;
use soroban_sdk::Env;
use vc_vault_contract::model::VCStatus;

#[derive(Arbitrary, Debug)]
struct FuzzInput {
vc_id: String,
vc_data: String,
issuer_did: String,
/// i64 used because arbitrary does not cover all of i128; cast on use.
fee_override: i64,
}

fuzz_target!(|input: FuzzInput| {
let env = Env::default();
let (_admin, issuer, owner, cid, client) = setup(&env);

let vc_id = s(&env, &input.vc_id);
let vc_data = s(&env, &input.vc_data);
let issuer_did = s(&env, &input.issuer_did);
let fee = input.fee_override as i128;

let result = client.try_issue(&owner, &vc_id, &vc_data, &cid, &issuer, &issuer_did, &fee);

if let Ok(Ok(_)) = result {
// Issue succeeded: verify_vc must return Valid and vc_id must be indexed.
assert_eq!(client.verify_vc(&owner, &vc_id), VCStatus::Valid);
assert!(client.list_vc_ids(&owner).contains(vc_id.clone()));
}
});
77 changes: 77 additions & 0 deletions contracts/vc-vault/fuzz/fuzz_targets/fuzz_issuer_ops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Fuzzes sequences of authorize_issuer / revoke_issuer with arbitrary inputs.
//!
//! Invariants checked:
//! - After authorize_issuer succeeds, the issuer must not be in the denied list
//! (i.e. a subsequent issue by that issuer must succeed).
//! - After revoke_issuer succeeds, a subsequent issue by the same issuer must fail.
//! - authorize_issuers deduplication: passing the same issuer N times must leave
//! exactly one entry (re-authorizing a revoked issuer clears the denied list).

#![no_main]

mod common;

use arbitrary::Arbitrary;
use common::{s, setup};
use libfuzzer_sys::fuzz_target;
use soroban_sdk::{testutils::Address as _, vec, Env};

#[derive(Arbitrary, Debug)]
enum IssuerOp {
Authorize,
Revoke,
BulkAuthorize { count: u8 },
}

#[derive(Arbitrary, Debug)]
struct FuzzInput {
ops: Vec<IssuerOp>,
vc_id: String,
}

fuzz_target!(|input: FuzzInput| {
let env = Env::default();
let (_admin, issuer, owner, cid, client) = setup(&env);

// A second issuer for bulk authorize tests.
let issuer2 = soroban_sdk::Address::generate(&env);

for op in &input.ops {
match op {
IssuerOp::Authorize => {
let _ = client.try_authorize_issuer(&owner, &issuer);
}
IssuerOp::Revoke => {
let _ = client.try_revoke_issuer(&owner, &issuer);
}
IssuerOp::BulkAuthorize { count } => {
// Build a list with duplicates proportional to count; dedup must hold.
let n = (*count as usize % 4) + 1;
let mut list = vec![&env, issuer.clone()];
for _ in 1..n {
list.push_back(issuer.clone());
}
list.push_back(issuer2.clone());
let _ = client.try_authorize_issuers(&owner, &list);
}
}
}

// After all ops, try to issue a VC and record whether it succeeded.
let vc_id = s(&env, &input.vc_id);
let issue_result = client.try_issue(
&owner,
&vc_id,
&s(&env, "data"),
&cid,
&issuer,
&s(&env, "did:fuzz:issuer"),
&0_i128,
);

// If issue succeeded, verify_vc must return Valid.
if let Ok(Ok(_)) = issue_result {
use vc_vault_contract::model::VCStatus;
assert_eq!(client.verify_vc(&owner, &vc_id), VCStatus::Valid);
}
});
Loading