task: add collision rejection to market id generation#568
Merged
greatest0fallt1me merged 2 commits intoMay 27, 2026
Merged
Conversation
Fold admin address into the SHA-256 seed so two admins calling generate_market_id with the same ledger sequence and global nonce produce different IDs. Previously the admin was only in the counter suffix, not the hash input. Changes: - build_market_id: append admin.to_xdr() bytes after sequence+nonce before hashing; update doc comment with new layout table - generate_market_id: pass admin ref through to build_market_id - Module doc: update entropy table to list admin address as third input Tests added: - test_same_ledger_same_nonce_different_admins_produce_different_ids: resets the global nonce between two calls to prove the admin address alone differentiates the hash - test_forced_registry_collision_triggers_retry: pre-populates storage with the first candidate ID and verifies the generator skips it and returns a distinct, format-valid ID
admin.clone().to_xdr(env) requires the ToXdr trait to be in scope. Without the import the call fails to compile with 'method not found'. Pattern matches audit_trail.rs which uses the same trait inline.
|
@michaelvic123 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #549
Problem
build_market_idhashed onlyledger_sequenceandglobal_nonce. The admin address appeared only in the counter suffix, not in the hash input. Two admins callinggenerate_market_idwith the same sequence and nonce could produce the same 8-char hex prefix and collide if their counters also matched.Additionally,
admin.clone().to_xdr(env)requiresuse soroban_sdk::xdr::ToXdrto be in scope — without it the code does not compile.Changes
market_id_generator.rsuse soroban_sdk::xdr::ToXdrimportmarket_id_generator.rsbuild_market_idnow takesadmin: &Addressand appendsadmin.to_xdr(env)bytes to the SHA-256 input after sequence+noncemarket_id_generator.rsgenerate_market_idpassesadminthrough tobuild_market_idmarket_id_generator.rsmarket_id_generator.rsNew tests
test_same_ledger_same_nonce_different_admins_produce_different_ids— resets the global nonce to 0 between two calls to isolate the admin-address contribution; proves the fix works in the worst casetest_forced_registry_collision_triggers_retry— pre-populates storage with the first candidate ID, then verifies the generator skips it and returns a distinct, format-valid IDAcceptance criteria
InvalidStateerror afterMAX_RETRIESvalidate_market_id_format