Skip to content

Harden router, pool, and cl-pool contract validation and tests - #1267

Merged
Mimah97 merged 5 commits into
Vatix-Protocol:mainfrom
nanbalkums:drips/1180-1181-1182-1183
Oct 16, 2026
Merged

Mimah97 merged 5 commits into
Vatix-Protocol:mainfrom
nanbalkums:drips/1180-1181-1182-1183

Conversation

@nanbalkums

Copy link
Copy Markdown
Contributor

Summary

Harden router, pool, and cl-pool contract validation and tests

What was solved

#1180 — router (packages/contract): initialize does not validate that factory is a contract address

Add a contract-address validation to the router's initialize in packages/contract/contracts/router/src/lib.rs so a non-contract factory address is rejected before storage, and add tests in packages/contract/contracts/router/src/test.rs covering factory round-trip via get_factory, NotInitialized panics for get_factory/get_admin before initialization, and rejection of a non-contract factory address.

Addressed:

  • Changed: packages/contract/contracts/router/src/lib.rs, packages/contract/contracts/router/src/test.rs
  • initialize must reject a factory address that is not a deployed contract, panicking with an appropriate RouterError (reuse an existing variant if suitable, otherwise append a new one without renumbering existing discriminants).
  • The stored factory must round-trip exactly through get_factory.
  • Add a test asserting get_factory returns the exact address passed to initialize.

#1181 — pool: initialize accepts a zero sqrt_price_x96 and stores a derived tick

Add validation to the pool contract's initialize function so it rejects a zero sqrt_price_x96 and any price whose derived tick falls outside MIN_TICK..=MAX_TICK, using the existing PoolError::InvalidTick variant, and cover the new behavior with tests in the pool test file.

Addressed:

  • Changed: packages/contract/contracts/pool/src/test.rs
  • In packages/contract/contracts/pool/src/lib.rs, after the AlreadyInitialized check in initialize, add a guard that panics with PoolError::InvalidTick when sqrt_price_x96 == 0.
  • In the same guard, panic with PoolError::InvalidTick when sqrt_price_to_tick(sqrt_price_x96) is outside MIN_TICK..=MAX_TICK.
  • Add a #[should_panic] test in packages/contract/contracts/pool/src/test.rs for initialize with sqrt_price_x96 = 0 expecting PoolError::InvalidTick.

#1182 — router (packages/contract): exact_output_single is declared unsupported but the error path is untested

Pin the router contract's exact-output behaviour in tests and document it. Read packages/contract/contracts/router/src/lib.rs to determine whether an exact-output entrypoint exists: if absent, add a test asserting the ExactOutputUnsupported revert (via the closest declared entrypoint) and document the non-goal in the doc comment; if present, add tests asserting amount_in respects amount_in_max and that exceeding it reverts with SlippageExceeded. Keep changes confined to the router crate.

Addressed:

  • Changed: packages/contract/contracts/router/src/lib.rs, packages/contract/contracts/router/src/test.rs
  • Add a test in packages/contract/contracts/router/src/test.rs that pins exact-output behaviour (successful swap honouring amount_in_max, or ExactOutputUnsupported revert).
  • Update the exact-output entrypoint's doc comment to state whether it is supported.
  • Ensure cargo test -p router passes (do not run it here).

#1183 — cl-pool: set_oracle accepts the pool's own address and any contract as the oracle

Harden cl-pool's set_oracle so it requires admin/owner authorization and rejects the pool's own address or either token address, adding a new PoolError::InvalidOracle variant and an Admin/Owner DataKey set during initialize, with tests covering the new paths.

Addressed:

  • Changed: packages/contract/contracts/cl-pool/src/test.rs
  • Add an Admin/Owner DataKey variant and set it in initialize if not present
  • set_oracle must call require_auth on the configured admin/owner before persisting
  • set_oracle must panic with a new PoolError variant (e.g. InvalidOracle) when oracle == env.current_contract_address()

Changes

  • packages/contract/contracts/router/src/lib.rs (modify)
  • packages/contract/contracts/router/src/test.rs (modify)
  • packages/contract/contracts/pool/src/test.rs (modify)
  • packages/contract/contracts/cl-pool/src/test.rs (modify)

Approach

  1. router (packages/contract): initialize does not validate that factory is a contract address #1180 — router (packages/contract): initialize does not validate that factory is a contract address (Changed: packages/contract/contracts/router/src/lib.rs, packages/contract/contracts/router/src/test.rs)
  2. pool: initialize accepts a zero sqrt_price_x96 and stores a derived tick #1181 — pool: initialize accepts a zero sqrt_price_x96 and stores a derived tick (Changed: packages/contract/contracts/pool/src/test.rs)
  3. router (packages/contract): exact_output_single is declared unsupported but the error path is untested #1182 — router (packages/contract): exact_output_single is declared unsupported but the error path is untested (Changed: packages/contract/contracts/router/src/lib.rs, packages/contract/contracts/router/src/test.rs)
  4. cl-pool: set_oracle accepts the pool's own address and any contract as the oracle #1183 — cl-pool: set_oracle accepts the pool's own address and any contract as the oracle (Changed: packages/contract/contracts/cl-pool/src/test.rs)

Issues

Closes #1180
Closes #1181
Closes #1182
Closes #1183

@Mimah97
Mimah97 merged commit 9d1cf3f into Vatix-Protocol:main Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants