Skip to content

fix: add caller authentication and storage pinning to asserter-consumer (#157) - #217

Closed
bilhokista wants to merge 1 commit into
drydocs:mainfrom
bilhokista:fix/issue-157-asserter-consumer-auth-guard
Closed

bilhokista wants to merge 1 commit into
drydocs:mainfrom
bilhokista:fix/issue-157-asserter-consumer-auth-guard

Conversation

@bilhokista

Copy link
Copy Markdown

Summary

Closes #157.

contracts/asserter-consumer/src/lib.rs allowed any caller to invoke create_assertion_as_self with arbitrary tholos_id, token_id, and outcome. 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_id and token_id were passed per call rather than pinned.

Key Changes

  • Added initialize(env, admin, tholos_id, token_id) with admin.require_auth() and single-initialization guard via DataKey::Admin.
  • Stored admin, tholos_id, and token_id in instance storage via DataKey enum.
  • Added Error::AlreadyInitialized = 5 and Error::NotInitialized = 6 to contracts/tholos-client/src/lib.rs.
  • Required admin.require_auth() in create_assertion_as_self and retrieved tholos_id and token_id from instance storage.
  • Updated get_status to query using pinned tholos_id from instance storage instead of accepting an unverified parameter.
  • Added regression tests in contracts/asserter-consumer/src/test.rs covering uninitialized rejection, unauthorized caller rejection, double initialization rejection, and valid authenticated flow.

Test plan

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test pass locally
    • cargo test -p asserter-consumer: 10 passed, 0 failed
    • cargo test -p demo-consumer: 6 passed, 0 failed
    • cargo clippy -p asserter-consumer -p tholos-client --all-targets -- -D warnings: clean (0 warnings)
    • cargo fmt --check: clean
  • CONTRACT.md updated if the public interface changed
  • scripts/testnet-smoke.sh run against testnet
  • What you manually verified: verified unauthorized caller revert, double init revert, and successful assertion flow under pinned storage.

@collinsezedike

Copy link
Copy Markdown
Collaborator

@bilhokista Closing this, issue #157 is assigned to another contributor who asked for it first. Feel free to pick up another open issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] create_assertion_as_self has no caller authentication

2 participants