Skip to content

test(history): add pending PCT withdrawal gas coverage - #81

Open
BeratOz01 wants to merge 2 commits into
security/crypto-review-fixesfrom
mberatoz/benchmar-withdrawal-at-history-cap
Open

test(history): add pending PCT withdrawal gas coverage#81
BeratOz01 wants to merge 2 commits into
security/crypto-review-fixesfrom
mberatoz/benchmar-withdrawal-at-history-cap

Conversation

@BeratOz01

Copy link
Copy Markdown
Collaborator

What

  • Add test-only harnesses for constructing pending PCT history.
  • Add boundary coverage for the pending-history cap and worst-case pruning.
  • Add an end-to-end converter withdrawal benchmark at 300 pending entries.
  • Extend the existing multi-deposit test timeout for its crypto-heavy workload.

Why

  • Verify that the pending-history cap preserves a user’s ability to exit.
  • Prevent regressions where a full pending-history queue blocks withdrawal or transfer through gas exhaustion.

How

  • EncryptedUserBalancesHarness seeds fully nonzero entries and measures bounded pruning.
  • EncryptedERCHarness seeds a valid 300-entry history, then exercises the real deposit, proof generation, withdrawal, ERC-20 payout, and cleanup path.
  • The full withdrawal test asserts that gas remains below the 15M C-Chain block-gas limit.

Verification

  • Tests run: REPORT_GAS=true npx hardhat test test/EncryptedERC-HistoryGas.ts
  • Tests run: npx tsc --noEmit
  • Manual checks: confirmed the 300-entry withdrawal succeeds, clears history, and transfers the expected ERC-20 amount.

Risk & rollout

  • Risk level: Low
  • Rollout plan: Test-only contracts and tests; no production contract behavior changes.
  • Backout plan: Revert the test-only harnesses and test changes.

Alternatives / follow-ups

  • The full benchmark currently takes about 21 minutes because it writes 299 complete storage entries. Move it to nightly CI or replace setup with direct Hardhat storage injection.

Notes for reviewers

  • Confirm the seeded PCT entries model the expensive storage-cleanup path.
  • Review the 15M gas threshold against the intended deployment chain.
  • Confirm the end-to-end test uses the real withdrawal verifier and payout flow.
  • Check that test-only harnesses remain under contracts/mocks and are never deployed by release scripts.
  • Consider whether the benchmark belongs in the standard CI suite or nightly coverage.

@BeratOz01
BeratOz01 requested review from furkan-ux and a balanced review from Copilot August 21, 2026 11:06
@BeratOz01 BeratOz01 self-assigned this Aug 21, 2026
@BeratOz01 BeratOz01 added the bug Something isn't working label Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds gas and boundary coverage for pending encrypted-balance history and converter withdrawals.

Changes:

  • Adds test-only history-seeding harnesses.
  • Tests the 300-entry cap, pruning, and end-to-end withdrawal gas.
  • Extends test timeouts and adds ts-node.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/EncryptedUserBalances.ts Tests history limits and pruning gas.
test/EncryptedERC-HistoryGas.ts Benchmarks withdrawal with 300 entries.
test/EncryptedERC-Converter.ts Extends a crypto-heavy test timeout.
contracts/mocks/EncryptedUserBalancesHarness.sol Adds history seeding/pruning helpers.
contracts/mocks/EncryptedERCHarness.sol Adds pending-history seeding.
package.json Adds ts-node.
package-lock.json Updates dependency resolution.
Suppressed comments (1)

test/EncryptedERC-HistoryGas.ts:154

  • receipt.gasUsed is calculated after storage-clear refunds, but a transaction must have enough gas to complete before those refunds are applied. Because Hardhat's default block limit is higher than 15M, this test can pass the assertion even when the withdrawal requires a transaction gas limit that C-Chain would reject. Submit the withdrawal with a 15M gasLimit so successful execution proves the advertised bound.
    expect(receipt!.gasUsed).to.be.lessThan(C_CHAIN_BLOCK_GAS_LIMIT);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/EncryptedERC-HistoryGas.ts
Comment thread test/EncryptedUserBalances.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants