fix: add caller authentication and storage pinning to asserter-consumer (#157) - #217
Closed
bilhokista wants to merge 1 commit into
Closed
bilhokista wants to merge 1 commit into
bilhokista wants to merge 1 commit into
Conversation
Collaborator
|
@bilhokista Closing this, issue #157 is assigned to another contributor who asked for it first. Feel free to pick up another open issue. |
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.
Summary
Closes #157.
contracts/asserter-consumer/src/lib.rsallowed any caller to invokecreate_assertion_as_selfwith arbitrarytholos_id,token_id, andoutcome. Because the assertion is posted using the contract's own address as the asserter, an unauthenticated caller could front-run or hijack the contract's bond capital, impersonating the contract without authorization. Additionally,tholos_idandtoken_idwere passed per call rather than pinned.Key Changes
initialize(env, admin, tholos_id, token_id)withadmin.require_auth()and single-initialization guard viaDataKey::Admin.admin,tholos_id, andtoken_idin instance storage viaDataKeyenum.Error::AlreadyInitialized = 5andError::NotInitialized = 6tocontracts/tholos-client/src/lib.rs.admin.require_auth()increate_assertion_as_selfand retrievedtholos_idandtoken_idfrom instance storage.get_statusto query using pinnedtholos_idfrom instance storage instead of accepting an unverified parameter.contracts/asserter-consumer/src/test.rscovering uninitialized rejection, unauthorized caller rejection, double initialization rejection, and valid authenticated flow.Test plan
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings, andcargo testpass locallycargo test -p asserter-consumer: 10 passed, 0 failedcargo test -p demo-consumer: 6 passed, 0 failedcargo clippy -p asserter-consumer -p tholos-client --all-targets -- -D warnings: clean (0 warnings)cargo fmt --check: cleanCONTRACT.mdupdated if the public interface changedscripts/testnet-smoke.shrun against testnet