# Attestation Flow \[How a VaultKit manager action becomes a Newton policy attestation and an onchain Shield execution.]

This is the lifecycle from "a curator wants to call `reallocate(...)`" to "the vault contract receives the call."

```mermaid
sequenceDiagram
    participant Curator as Curator Wallet
    participant SDK as VaultKit SDK
    participant Gateway as Newton Gateway
    participant Operators as Operators + Aggregator
    participant Shield as Shield Clone
    participant Vault as Vault Contract

    Curator->>SDK: Typed manager action
    SDK->>SDK: Build Intent and wasmArgs
    SDK->>Curator: Request EIP-712 intent signature
    SDK->>Gateway: newt_createTask(intent, wasmArgs, signature)
    Gateway->>Operators: Dispatch task
    Operators->>Operators: Evaluate policy WASM
    Operators-->>Gateway: Allow or deny quorum result
    Gateway-->>SDK: TaskResponse or attestation data
    SDK->>Shield: execute(...) or executeDirect(...)
    Shield->>Shield: Validate policy, signature, chain, expiration, replay
    Shield->>Vault: Forward approved calldata
```

## 1. Intent Construction

The vendor module or `sendCall(...)` path produces calldata for the target vault action. Each policy pack prepares its `wasmArgs`: one entry per policy in the Shield's set, in set order, with each module getting its own slice and a pure-Rego policy such as the `_policy` gate getting `0x`. The SDK assembles an `Intent` that binds:

* The curator signer.
* The target contract.
* The calldata and value.
* The chain id.
* The human-readable function signature encoded as bytes.

The curator signs the intent with EIP-712. That signature lets operators and the Shield verify that the approved call originated from the expected curator address.

## 2. Task Submission

The SDK sends the signed intent and the per-policy `wasmArgs` array to Newton Gateway. The gateway freezes the task to the Shield's current policy set, returns a task id, and coordinates policy evaluation. Before submitting onchain, the SDK requires the returned task to be frozen to the same ordered set it built the args for.

## 3. Operator Evaluation

Operators evaluate every policy in the frozen set. For each one, they run its WASM oracle, if it has one, on that policy's `wasmArgs` entry, then its Rego against:

* The intent.
* That policy's own params from the Shield's set.
* That oracle's output only.
* Any allowed external data or encrypted secrets the pack needs.

The response's `allowed` is the AND of every policy's verdict. If any policy denies, the SDK raises `PolicyDeniedError`. The Shield never receives a valid approval for that action.

## 4. Attestation Commit

In standard mode, the aggregator commits the quorum response through the AVS task manager. The SDK then calls `Shield.execute(attestation)`.

In direct mode, the SDK receives the raw `Task`, `TaskResponse`, and signature data, then calls `Shield.executeDirect(...)`. Direct mode avoids waiting for aggregator commit but costs more gas because the Shield verifies signatures inline.

## 5. Onchain Validation and Forwarding

The Shield validates:

* The attestation policy id matches the Shield's current policy id.
* The intent `from` matches the caller.
* The intent chain id matches `block.chainid`.
* The task is approved, unexpired, and not already spent.
* The BLS quorum is valid, either through the task manager or inline direct validation.

If validation passes, the Shield forwards `intent.data` and `intent.value` to `intent.to`. If the vault reverts, the Shield bubbles the target revert reason where possible.

## Replay, Expiration, and Freshness

Task ids are one-shot. Reusing the same attestation reverts. Attestations also expire after their configured block window.

Freshness comes from the policy pack. Packs commonly include hashes or snapshots in `wasmArgs`, then deny if chain state or external data moved beyond the accepted window during evaluation.

## Standard vs Direct

| Trait | Standard `execute` | Direct `executeDirect` |
| --- | --- | --- |
| Aggregator commit | Required | Skipped |
| BLS verification | AVS task manager | Inline in Shield |
| Gas | Lower | Higher |
| Latency | Higher | Lower |
| SDK argument | Not in VaultKit 3.0: the `'ATTESTATION'` mode throws `unimplemented, waiting for merge` | `shield.sendCall(args, 'DIRECT')` |
