Skip to content

test(contract): sandbox coverage + stub verifier for async attestation - #3715

Merged
pbeza merged 28 commits into
3642-async-attestation-corefrom
3642-async-attestation-tests
Jul 22, 2026
Merged

test(contract): sandbox coverage + stub verifier for async attestation#3715
pbeza merged 28 commits into
3642-async-attestation-corefrom
3642-async-attestation-tests

Conversation

@pbeza

@pbeza pbeza commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Second half of the #3664 split, stacked on #3714 (async attestation). Tests only; no production-code changes.

Copilot AI review requested due to automatic review settings June 30, 2026 17:17

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@pbeza
pbeza force-pushed the 3642-async-attestation-tests branch from 0e60532 to 47655a4 Compare July 1, 2026 11:01
@claude

This comment was marked as outdated.

@pbeza

pbeza commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Requirement carried over from review of #3714 (discussion_r3558779901):

Add sandbox coverage for the TLS-key-ownership authorization guard in store_verified_attestation (crates/contract/src/tee/tee_state.rs): a submission whose tls_public_key is already registered to a different account_id must be rejected with TlsKeyOwnedByOtherAccount, and the existing stored attestation must be left unchanged. This is a pre-existing check with no direct test today; #3715 is the right place for it since it owns the async-attestation sandbox coverage and stub verifier.

@pbeza

pbeza commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Note-to-self / tracking from #3714 (#3714 (comment)): the async-attestation gas constants in `crates/contract/src/config.rs` are not benchmarked — `DEFAULT_VERIFIER_TERA_GAS = 100` and `DEFAULT_RESOLVE_VERIFICATION_TERA_GAS = 60` are conservative estimates. I deferred measuring them to this PR since it adds the stub-verifier sandbox coverage.

Proposal: in the `StubResponse::Verified` sandbox test, read the `resolve_verification` receipt's `total_gas_burnt` (per-receipt, via `ExecutionFinalResult::receipt_outcomes()`, same approach as `participants_gas.rs`) and size `resolve_verification_tera_gas` at ~2x the observed burn. Analytically it looks over-provisioned — the post-DCAP work is the same weight class as `clean_tee_status`/`clean_invalid_attestations` (10 Tgas), so ~20 is likely the right ceiling.

Two caveats:

  • `verifier_tera_gas = 100` can't be validated with the stub (it's cheap) — the real cost is the verifier's `dcap-qvl` run, which needs its own benchmark.
  • This measurement is only meaningful once this branch is rebased onto the post-refactor: alternative without yield resume #3766 (no-yield) `resolve_verification`; the current branch still has the yield-resume version.

If it's not trivial here, fine to spin off a follow-up issue (relatedly, other unbenchmarked constants exist, e.g. `VOTE_FOREIGN_CHAIN_GAS` in the e2e tests — #3641 discussion_r3543560094).

@pbeza
pbeza force-pushed the 3642-async-attestation-tests branch from bc1f255 to 7134f67 Compare July 13, 2026 10:00
@near near deleted a comment from claude Bot Jul 13, 2026
@near near deleted a comment from claude Bot Jul 13, 2026
@near near deleted a comment from claude Bot Jul 13, 2026
@near near deleted a comment from claude Bot Jul 13, 2026
@near near deleted a comment from claude Bot Jul 13, 2026
@claude

claude Bot commented Jul 13, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR modifies source code in src/ directories, so the type prefix should probably be feat: instead of test:.

Suggested title: feat(contract): add sandbox coverage and stub verifier for async attestation

@pbeza

pbeza commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

JFYI, I created a follow-up issue #3787 for these two comments, since they’re both blocked on the same missing fixture:

@pbeza
pbeza force-pushed the 3642-async-attestation-tests branch 2 times, most recently from 54d794f to c3ab60b Compare July 14, 2026 14:01
@near near deleted a comment from claude Bot Jul 14, 2026
@pbeza
pbeza requested a review from Copilot July 14, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.

Comment thread docs/localnet/tee-localnet.md Outdated
@near near deleted a comment from claude Bot Jul 14, 2026
@pbeza
pbeza requested a review from Copilot July 14, 2026 17:09
@pbeza
pbeza force-pushed the 3642-async-attestation-tests branch from 6afae04 to b21cc1e Compare July 18, 2026 10:51
@pbeza

pbeza commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@kevindeforth @gilcu3 @netrome, I’ve addressed all the nits. Feel free to take another look.

Sorry for the force-pushes. The base PR, #3714, tends to run into conflicts with main, so I need to regularly merge origin/main into it and then rebase this PR on top. I could also merge 3642-async-attestation-core into 3642-async-attestation-tests instead, if you’d prefer. Let me know.

Hopefully, we can merge everything into main early next week once this is approved and the verifier contract is deployed.

@near near deleted a comment from claude Bot Jul 18, 2026
@pbeza
pbeza requested review from gilcu3 and kevindeforth July 18, 2026 12:25

@kevindeforth kevindeforth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@gilcu3 gilcu3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!


// Then
// assert_matches! requires Debug, which PromiseOrValue doesn't implement
assert!(matches!(result, PromiseOrValue::Promise(_)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: we generally prefer assert_matches

Comment on lines 96 to 100
#[expect(clippy::large_enum_variant)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
#[derive(
Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize, BorshSerialize,
)]
#[cfg_attr(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I saw this comment saying some traits were removed, but here I still see 2 included. Were this needed then?

Comment thread crates/tee-context/Cargo.toml Outdated

@barakeinav1 barakeinav1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

added a few comments

let dtos::Attestation::Dstack(dstack) = &mut attestation else {
panic!("fixture must be a Dstack attestation");
};
dstack.quote = dtos::HexVec(vec![0u8; 16]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is where the real-DCAP gas cost slips through: the quote here is 16 zero bytes, which dcap_qvl rejects at parse, so verify_quote returns almost immediately and costs next to nothing. A valid quote runs the full verification (sig + cert chain + TCB), which is far heavier — and in an e2e run on a real TDX cluster that path blows past the verifier_tera_gas = 100 default (see #3714), so attestation never completes.

Since no test here feeds a valid quote, the gas budget isn't actually covered. Might be worth a case with a real quote fixture at production gas, asserting a stored attestation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pbeza for reference, there's already a test that runs a real valid quote through verify_quote and gets Verified: crates/tee-verifier/tests/verify_quote.rs::verify_quote__should_return_verified_td10_report_for_valid_fixture. It uses the real test_utils::attestation::quote() + collateral() fixtures and pins the VM block timestamp to VALID_ATTESTATION_TIMESTAMP so the collateral is in its validity window.

That's the fixture setup this sandbox coverage could borrow to drive the full DCAP path (and its real gas cost) instead of the 16-byte quote that's rejected at parse. One catch is the clock: that test pins it via testing_env!; in a near-workspaces sandbox you'd need the block time inside the fixture's window (time fast-forward) for it to verify rather than expire.

@barakeinav1 barakeinav1 Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pbeza I opened a follow-up issue.
#3897

@barakeinav1 barakeinav1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

need to add a test that check the real gas used by the contract (since this just failed in an E2E test).
see #3715 (comment)

…o 3642-async-attestation-tests

# Conflicts:
#	crates/tee-context/Cargo.toml
@claude

claude Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR modifies source code files in addition to test files. When source code changes alongside test changes, the type should typically be something other than test:. Consider chore: since the primary intent appears to be test infrastructure/maintenance work.

Suggested title: chore(contract): add sandbox coverage + stub verifier for async attestation

…o 3642-async-attestation-tests

# Conflicts:
#	crates/tee-context/Cargo.toml

@barakeinav1 barakeinav1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I opened a follow-up issue.
#3897

@pbeza
pbeza requested review from gilcu3 and kevindeforth July 22, 2026 13:06
@claude

claude Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR title type suggestion: Since source code files are modified (e.g., crates/contract/src/, crates/mpc-attestation/src/), the type should probably be feat: or refactor: instead of test:.
Suggested title: feat(contract): sandbox coverage + stub verifier for async attestation

@kevindeforth kevindeforth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

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.

5 participants