Skip to main content

Shield Contract

The Shield contract manages access policies on the Base blockchain.

Contract Address

Overview

The Shield contract stores access policies that define:
  • Who can access content (recipient)
  • When access expires (timestamp)
  • How many attempts are allowed (maxAttempts)
  • How many attempts have been made (attempts)

Data Structures

AccessPolicy

Storage

Policies are indexed by policyId (keccak256 hash).

Functions

createPolicy

Create a new access policy.
Parameters: Requirements:
  • Policy doesn’t already exist
  • Recipient is not zero address
  • Expiry is in the future
  • maxAttempts > 0
Emits: PolicyCreated Example:

logAttempt

Log an access attempt. Must be called by recipient.
Parameters: Requirements:
  • Policy exists
  • Policy is valid
  • Caller is the recipient
  • Not expired
  • Attempts remaining
Emits: VerificationAttempt Example:

isPolicyValid

Check if a policy is currently valid.
Returns true if:
  • Policy exists
  • valid flag is true
  • Not expired
  • Attempts remaining
Example:

Events

PolicyCreated

Emitted when a new policy is created.

VerificationAttempt

Emitted when an access attempt is logged.

Access Control

Error Messages

Flow Example

Accessing Content

Security Considerations

  • Immutable policies: Once created, cannot be modified
  • Self-enforcing: Rules are enforced by contract, not trust
  • Transparent: All policies and attempts are public
  • Auditable: Complete history on-chain

Gas Costs

Source Code