-
Notifications
You must be signed in to change notification settings - Fork 0
audit: security fixes and fuzzing infrastructure for vc-vault v1 acta #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 0a74667
feat: add sponsored vault storage keys and helpers
aguilar1x 4a22fc6
feat: add sponsored vault function signatures to trait
aguilar1x 9a3bab1
feat: implement sponsored vault functions
aguilar1x 1d957e2
test: add sponsored vault tests
aguilar1x 5bb86b9
chore: update sdk versión 21.0.0 to 23.4.0
aguilar1x 18411e0
chore: add information of cargotoml-profile
aguilar1x 0f5f9f0
fix: namespace VCStatus by (owner, vc_id) and refactor storage layout
aguilar1x 0e36116
feat: add events module for all state-changing operations
aguilar1x fe94e05
fix: issuer authorization — clear deny list on re-auth and deduplicate
aguilar1x 32f3a2e
fix: contract entrypoints — multiple security and logic fixes
aguilar1x c105702
test: add auth guard tests and push regression tests
aguilar1x a80f18b
fix: scripts — fail-fast, TTL constants and idempotent deployment
aguilar1x 5d1b65d
chore: set crate-type to rlib only
aguilar1x c1d9de0
chore: ignore fuzz corpus and artifacts
aguilar1x 2064d04
chore: Update of unnecessary comments as they were follow-up for read…
aguilar1x 45e43a2
fix: write VCStatus for destination vault in push
aguilar1x 3891d09
fix: guard push against overwriting existing vc_id in destination vault
aguilar1x c11e46e
feat: add cargo-fuzz suite for vc-vault
aguilar1x ea09a0a
docs: add setup and fuzzing guide for vc-vault
aguilar1x c977375
docs: add security audit report for vc-vault v0.21.0
aguilar1x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
|
|
||
| /// 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential panic on multi-byte UTF-8 boundary slice.
Slicing
&input[..input.len().min(256)]at a byte index can panic ifinputcontains multi-byte UTF-8 characters and the slice boundary falls mid-character. Fuzz inputs fromarbitrarycan 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
🤖 Prompt for AI Agents