# Shield Reference \[Public contract surface for Shield and ShieldFactory.]

This page summarizes the onchain surface VaultKit uses. Solidity names are shown for integrators, indexers, and auditors.

## `Shield`

### Constants

```solidity
uint256 public constant MIN_BYPASS_DELAY = 1 days;
```

### Public Reads

```solidity
uint256 public bypassDelaySeconds;
mapping(bytes32 id => BypassEntry) public bypasses;
```

`bypasses(id)` returns the queued bypass target, value, calldata, eta, and existence flag.

### `initialize`

```solidity
function initialize(
    address policyTaskManager,
    address policy,
    address policyClientOwner,
    uint256 bypassDelaySeconds
) external initializer;
```

Called once by `ShieldFactory.createShield`. Reverts if the bypass delay is below `MIN_BYPASS_DELAY`, and with `PolicySetRequired()` if `policy != address(0)`. A 0.7 Shield binds a policy set, so a clone is born unbound and the owner binds the set afterwards with the inherited `setPolicies`. Until then its `policyId` is `bytes32(0)`, and `execute` or `executeDirect` from an approved delegate reverts `InvalidAttestation()`.

### `execute`

```solidity
function execute(
    NewtonMessage.Attestation calldata attestation
) external nonReentrant onlyApprovedDelegate returns (bytes memory);
```

Validates an AVS-issued attestation, forwards the approved intent, emits `ShieldExecuted`, and returns target `returnData`. Reverts with `NotApprovedDelegate(caller)` when `msg.sender` is not approved.

### `executeDirect`

```solidity
function executeDirect(
    INewtonProverTaskManager.Task calldata task,
    INewtonProverTaskManager.TaskResponse calldata taskResponse,
    bytes calldata signatureData
) external nonReentrant onlyApprovedDelegate returns (bytes memory);
```

Validates the task response and signature data inline, forwards the approved intent, emits `ShieldExecutedDirect`, and returns target `returnData`. The task intent and task-response intent must match byte-for-byte or the call reverts with `IntentMismatch()`.

### Delegates

`execute` and `executeDirect` are gated by the `approvedDelegates` map. The policy-client owner controls that map separately from bypass and policy ownership.

```solidity
mapping(address delegate => bool approved) public approvedDelegates;

function setApprovedDelegate(
    address delegate,
    bool approved
) external onlyPolicyClientOwner;

function isApprovedDelegate(address delegate) external view returns (bool);
```

The initial `policyClientOwner` is approved during `initialize`, so the owner can execute immediately after deployment. There is no implicit live-owner overlay after ownership changes: if ownership is handed to a Safe or another EOA, the new executor must be approved with `setApprovedDelegate(newExecutor, true)`, and old delegates should be revoked with `setApprovedDelegate(oldDelegate, false)`.

### Bypass Methods

```solidity
function queueBypass(
    address to,
    uint256 value,
    bytes calldata data
) external onlyPolicyClientOwner returns (bytes32 id);

function executeBypass(
    bytes32 id
) external nonReentrant onlyPolicyClientOwner returns (bytes memory);

function cancelBypass(bytes32 id) external onlyPolicyClientOwner;
```

Bypass entries are one-shot. `executeBypass` is only valid after the queued eta, and `cancelBypass` permanently removes the entry.

### Events

```solidity
event ShieldExecuted(bytes32 indexed taskId, NewtonMessage.Intent intent, bytes returnData);
event ShieldExecutedDirect(bytes32 indexed taskId, NewtonMessage.Intent intent, bytes returnData);
event BypassQueued(bytes32 indexed id, address indexed to, uint256 value, bytes data, uint256 eta);
event BypassExecuted(bytes32 indexed id, address indexed to, uint256 value, bytes data, bytes returnData);
event BypassCancelled(bytes32 indexed id);
event DelegateUpdated(address indexed delegate, bool indexed approved);
```

### Common Errors

```solidity
error InvalidAttestation();
error IntentExecutionFailed();
error IntentMismatch();
error NotApprovedDelegate(address caller);
error BypassDelayBelowMinimum(uint256 provided, uint256 minimum);
error BypassAlreadyQueued(bytes32 id);
error BypassUnknown(bytes32 id);
error BypassNotReady(bytes32 id, uint256 eta);
```

The SDK surfaces many of these through `ShieldExecutionError.cause`.

## Inherited Policy Client Methods

VaultKit 3.0.0 targets a policy-set Shield built from the 0.7 contracts. Upgrading the protocol does not automatically upgrade an existing Shield; see [Smart Contract Integration](/developers/guides/smart-contract-integration#api-reference).

```solidity
// INewtonPolicyClient.PolicySpec / INewtonPolicy.PolicyConfig
struct PolicySpec   { address policy; PolicyConfig config; }
struct PolicyConfig { bytes policyParams; uint32 expireAfter; }

// Owner-gated writers
function setPolicies(PolicySpec[] calldata policies)
    external onlyPolicyClientOwner returns (bytes32 policyId);
function setPolicyClientOwner(address policyClientOwner) public onlyPolicyClientOwner;

// Public reads
function getPolicies()          external view returns (PolicySpec[] memory);
function getPolicyId()          external view returns (bytes32);
function policyRevision()       external view returns (uint64);
function getPolicySetSnapshot() external view
    returns (bytes32 policyId, uint64 revision, PolicySpec[] memory policies);

// Events
event PoliciesUpdated(
    bytes32 indexed previousPolicyId, bytes32 indexed newPolicyId, uint64 revision, PolicySpec[] policies
);
```

`setPolicies(...)` replaces the clone's whole policy set atomically and returns the new `policyId`. The set holds 1 to 8 entries, evaluated as a fail-closed AND. Each entry's policy must be registered by the TaskManager's policy factory, with a nonzero `expireAfter` and `policyParams` of at most 64 KiB. Every call bumps `policyRevision`, so rewriting identical entries still mints a new `policyId` and invalidates outstanding attestations. `getPolicySetSnapshot()` returns the id, revision, and set in one call; it is what the SDK and the gateway read. `setPolicyClientOwner(...)` transfers owner authority, commonly to a Safe.

The pre-0.7 single-policy surface (`setPolicy`, `setPolicyAddress`, `getPolicyAddress`, `getPolicyConfig`) no longer exists on the mixin.

## `ShieldFactory`

### Immutables

```solidity
address public immutable beacon;
address public immutable taskManager;
```

### `createShield`

```solidity
function createShield(
    address curator,
    address vault,
    uint64 version,
    address policy,
    uint256 bypassDelaySeconds
) external returns (address shield);
```

Deploys a `BeaconProxy` for the beacon with CREATE2 and initializes it. Reverts if curator or vault is zero, if the predicted clone already exists, or if initialization fails. Pass `policy = address(0)`: the factory forwards it unchanged, and a 0.7 Shield rejects anything else with `PolicySetRequired()`. The curator binds the policy set afterwards with `setPolicies`, which VaultKit's `setParams(...)` calls.

### View Helpers

```solidity
function predictShieldAddress(
    address curator,
    address vault,
    uint64 version
) external view returns (address);

function isDeployed(
    address curator,
    address vault,
    uint64 version
) external view returns (bool);
```

The SDK uses these helpers to predict addresses and make `createShield(...)` idempotent.
