Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add Kestrova action provider (Solidity security scan, x402)
  • Loading branch information
som2026-commits committed Nov 19, 2026
commit 81decb8de0dabe66a3f2354d71dbf6f199d732ab
5 changes: 5 additions & 0 deletions typescript/.changeset/kestrova-solidity-scan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": patch
---

Added a Kestrova action provider for free Solidity security previews and x402-paid scans with pinned payment terms
1 change: 1 addition & 0 deletions typescript/agentkit/src/action-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./erc721";
export * from "./erc8004";
export * from "./farcaster";
export * from "./jupiter";
export * from "./kestrova";
export * from "./messari";
export * from "./pyth";
export * from "./moonwell";
Expand Down
54 changes: 54 additions & 0 deletions typescript/agentkit/src/action-providers/kestrova/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Kestrova Action Provider

This directory contains the **KestrovaActionProvider**, which lets an agent check Solidity smart contracts for known
vulnerability patterns with [Kestrova](https://kestrova-api.onrender.com) (Slither static analysis) before it deploys
them. The preview is free; full results are paid per call with x402 in USDC on Base or Solana mainnet.

Kestrova is automated static analysis, not an audit: zero findings does not mean a contract is safe.

## Directory Structure

```
kestrova/
├── constants.ts # Service URL, tiers and the only payment terms that may be signed
├── kestrovaActionProvider.test.ts # Tests for the provider
├── kestrovaActionProvider.ts # Main provider
├── index.ts # Main exports
├── README.md # Documentation
└── schemas.ts # Action schemas and configuration
```

## Configuration

```typescript
import { kestrovaActionProvider } from "@coinbase/agentkit";

const provider = kestrovaActionProvider({
maxPaymentUsdc: 1.0, // default 1.0 (or KESTROVA_MAX_PAYMENT_USDC)
});
```

## Actions

- `kestrova_scan_preview` (free, no wallet): severity counts, High/Medium detector names, one example finding and
`behind_paywall` (exactly what a paid result would add for this code).
- `kestrova_get_scan_price` (free): live price of a tier for the wallet's network, checked against Kestrova's
published terms. Show it to the user before buying.
- `kestrova_buy_scan` (paid, x402):
- `findings` (0.25 USDC): every finding with detector, severity, confidence, file/line locations and Slither's
description, as JSON.
- `full` (1 USDC): adds a plain-English explanation and fix per finding, plus PDF and SARIF report files.

## Payment safety

- The x402 client gets a payment policy that keeps only Kestrova's exact published terms: scheme `exact`, USDC, the
published recipient and network, and the tier's amount. Anything else is never signed.
- `maxPaymentUsdc` caps every call.
- Charged only if the scan succeeds. If a payment was made but the outcome is unclear, the action returns
`doNotPayAgain: true`: recover the paid report for free with a wallet signature (`POST /scan/recover`), never by paying
again.

## Network Support

The preview works on any network. Paid scans need an EVM wallet on `base-mainnet` or an SVM wallet on
`solana-mainnet`.
46 changes: 46 additions & 0 deletions typescript/agentkit/src/action-providers/kestrova/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Kestrova public API (Solidity security scanning with Slither, paid per call with x402).
*/
export const KESTROVA_DEFAULT_BASE_URL = "https://kestrova-api.onrender.com";

/**
* Paid result tiers. Amounts are USDC atomic units (6 decimals).
*/
export const KESTROVA_TIERS = {
findings: {
path: "/scan/findings",
amount: "250000",
description:
"every finding with detector, severity, confidence, file/line locations and Slither's description (JSON)",
},
full: {
path: "/scan",
amount: "1000000",
description:
"every finding plus a plain-English explanation and fix for each, with PDF and SARIF report files",
},
} as const;

export type KestrovaTier = keyof typeof KESTROVA_TIERS;

/**
* The only payment terms the provider will sign, per AgentKit network ID.
* Any other network, asset, recipient or amount is refused before a payment is created.
*/
export const KESTROVA_PAYMENT_TERMS: Record<
string,
{ network: string; asset: string; payTo: string }
> = {
"base-mainnet": {
network: "eip155:8453",
asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
payTo: "0xB40d2B1B0717dA534e4A98463546cA3E58206cA0",
},
"solana-mainnet": {
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
asset: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
payTo: "CWJdBXpfaARqqWA6XrDXsVGVcZMM8rMcQbSfLqFwNeqc",
},
};

export const KESTROVA_SOURCE_TAG = "agentkit";
2 changes: 2 additions & 0 deletions typescript/agentkit/src/action-providers/kestrova/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./kestrovaActionProvider";
export * from "./schemas";
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { EvmWalletProvider, WalletProvider } from "../../wallet-providers";
import { kestrovaActionProvider, matchesPinnedTerms } from "./kestrovaActionProvider";
import { KESTROVA_PAYMENT_TERMS } from "./constants";

const BASE = KESTROVA_PAYMENT_TERMS["base-mainnet"];
const SOLANA = KESTROVA_PAYMENT_TERMS["solana-mainnet"];

/**
* A 402 response carrying x402 v2 payment terms in the PAYMENT-REQUIRED header.
*
* @param accepts - The payment requirements
* @param url - The resource URL
* @returns A Response
*/
function paymentRequired(accepts: Record<string, unknown>[], url: string): Response {
const body = {
x402Version: 2,
accepts,
resource: { url, description: "scan", mimeType: "application/json" },
};
return new Response("{}", {
status: 402,
headers: {
"content-type": "application/json",
"payment-required": Buffer.from(JSON.stringify(body)).toString("base64"),
},
});
}

/**
* Base mainnet exact terms as Kestrova publishes them, with optional overrides.
*
* @param overrides - Fields to change
* @returns A payment requirement
*/
function baseTerms(overrides: Record<string, unknown> = {}): Record<string, unknown> {
return {
scheme: "exact",
network: BASE.network,
asset: BASE.asset,
payTo: BASE.payTo,
amount: "250000",
maxTimeoutSeconds: 300,
extra: { name: "USD Coin", version: "2" },
...overrides,
};
}

/**
* A wallet provider stub on the given network (never used to sign for the free actions).
*
* @param networkId - AgentKit network id
* @returns A WalletProvider
*/
function walletOn(networkId: string): WalletProvider {
return { getNetwork: () => ({ networkId, protocolFamily: "evm" }) } as unknown as WalletProvider;
}

/**
* An EvmWalletProvider backed by a throwaway local key: it signs locally only; fetch is mocked.
*
* @returns The wallet provider
*/
function localEvmWallet(): EvmWalletProvider {
const account = privateKeyToAccount(generatePrivateKey());
const wallet = Object.create(EvmWalletProvider.prototype) as EvmWalletProvider;
Object.assign(wallet, {
getNetwork: () => ({ networkId: "base-mainnet", protocolFamily: "evm", chainId: "8453" }),
toSigner: () => account,
readContract: jest.fn(),
});
return wallet;
}

describe("matchesPinnedTerms", () => {
it("accepts exactly the published terms", () => {
expect(matchesPinnedTerms(baseTerms(), BASE, "250000")).toBe(true);
expect(matchesPinnedTerms(baseTerms({ payTo: BASE.payTo.toLowerCase() }), BASE, "250000")).toBe(
true,
);
});

it.each([
["another recipient", { payTo: "0x0000000000000000000000000000000000000001" }],
["another asset", { asset: "0x0000000000000000000000000000000000000002" }],
["another amount", { amount: "1000000" }],
["another network", { network: "eip155:84532" }],
["another scheme", { scheme: "upto" }],
])("refuses %s", (_label, overrides) => {
expect(matchesPinnedTerms(baseTerms(overrides), BASE, "250000")).toBe(false);
});

it("compares Solana addresses exactly", () => {
const sol = {
scheme: "exact",
network: SOLANA.network,
asset: SOLANA.asset,
payTo: SOLANA.payTo,
amount: "1000000",
};
expect(matchesPinnedTerms(sol, SOLANA, "1000000")).toBe(true);
expect(
matchesPinnedTerms({ ...sol, payTo: SOLANA.payTo.toLowerCase() }, SOLANA, "1000000"),
).toBe(false);
});
});

describe("KestrovaActionProvider", () => {
const fetchMock = jest.fn();
const realFetch = global.fetch;

beforeEach(() => {
fetchMock.mockReset();
global.fetch = fetchMock as unknown as typeof fetch;
});

afterAll(() => {
global.fetch = realFetch;
});

it("runs the free preview without a wallet or payment", async () => {
const preview = { counts: { High: 1 }, detectors: ["reentrancy-eth"] };
fetchMock.mockResolvedValue(new Response(JSON.stringify(preview), { status: 200 }));
const result = JSON.parse(
await kestrovaActionProvider().scanPreview(walletOn("base-mainnet"), {
sources: { "A.sol": "x" },
}),
);
expect(result).toEqual(preview);
const [url, init] = fetchMock.mock.calls[0];
expect(url).toBe("https://kestrova-api.onrender.com/preview?src=agentkit");
expect(JSON.parse(init.body)).toEqual({ sources: { "A.sol": "x" } });
expect(init.headers["PAYMENT-SIGNATURE"]).toBeUndefined();
});

it("reports the price and whether the live terms match, without paying", async () => {
fetchMock.mockResolvedValue(
paymentRequired([baseTerms()], "https://kestrova-api.onrender.com/scan/findings"),
);
const result = JSON.parse(
await kestrovaActionProvider().getScanPrice(walletOn("base-mainnet"), { tier: "findings" }),
);
expect(result.priceUsdc).toBe(0.25);
expect(result.payable).toBe(true);
expect(result.paymentOption.payTo).toBe(BASE.payTo);
expect(fetchMock).toHaveBeenCalledTimes(1);
});

it("flags tampered live terms as not payable", async () => {
fetchMock.mockResolvedValue(
paymentRequired([baseTerms({ payTo: "0x0000000000000000000000000000000000000009" })], "u"),
);
const result = JSON.parse(
await kestrovaActionProvider().getScanPrice(walletOn("base-mainnet"), { tier: "findings" }),
);
expect(result.payable).toBe(false);
expect(result.paymentOption).toBeNull();
});

it("refuses unsupported networks and prices above the cap before any request", async () => {
const p = kestrovaActionProvider({ maxPaymentUsdc: 0.5 });
const wrongNet = JSON.parse(
await p.buyScan(walletOn("base-sepolia"), { sources: {}, tier: "findings" }),
);
expect(wrongNet.paid).toBe(false);
const overCap = JSON.parse(await p.buyScan(localEvmWallet(), { sources: {}, tier: "full" }));
expect(overCap.paid).toBe(false);
expect(overCap.message).toContain("maxPaymentUsdc");
expect(fetchMock).not.toHaveBeenCalled();
});

it("never signs terms that differ from the published ones", async () => {
fetchMock.mockResolvedValue(
paymentRequired([baseTerms({ payTo: "0x0000000000000000000000000000000000000009" })], "u"),
);
const result = JSON.parse(
await kestrovaActionProvider().buyScan(localEvmWallet(), {
sources: { "A.sol": "x" },
tier: "findings",
}),
);
expect(result.success).toBe(false);
expect(result.doNotPayAgain).toBe(false);
expect(fetchMock).toHaveBeenCalledTimes(1); // no second request carrying a payment
});

it("pays exactly the published terms once and returns the findings", async () => {
const url = "https://kestrova-api.onrender.com/scan/findings?src=agentkit";
const findings = { tier: "findings", findings: [{ detector: "reentrancy-eth" }] };
fetchMock
.mockResolvedValueOnce(paymentRequired([baseTerms()], url))
.mockResolvedValueOnce(new Response(JSON.stringify(findings), { status: 200 }));
const result = JSON.parse(
await kestrovaActionProvider().buyScan(localEvmWallet(), {
sources: { "A.sol": "x" },
tier: "findings",
}),
);
expect(result.success).toBe(true);
expect(result.result).toEqual(findings);
expect(fetchMock).toHaveBeenCalledTimes(2);
const paid = fetchMock.mock.calls[1][0] as Request;
const header = paid.headers.get("payment-signature") ?? paid.headers.get("x-payment");
expect(header).toBeTruthy();
const payload = JSON.parse(Buffer.from(header as string, "base64").toString("utf8"));
expect(payload.accepted.amount).toBe("250000");
expect(payload.accepted.payTo).toBe(BASE.payTo);
expect(payload.payload.authorization.to.toLowerCase()).toBe(BASE.payTo.toLowerCase());
expect(payload.payload.authorization.value).toBe("250000");
});

it("tells the agent not to pay again when a payment was made but the outcome is unclear", async () => {
fetchMock
.mockResolvedValueOnce(paymentRequired([baseTerms()], "u"))
.mockResolvedValueOnce(new Response(JSON.stringify({ status: "pending" }), { status: 202 }));
const result = JSON.parse(
await kestrovaActionProvider().buyScan(localEvmWallet(), {
sources: { "A.sol": "x" },
tier: "findings",
}),
);
expect(result.success).toBe(false);
expect(result.doNotPayAgain).toBe(true);
expect(result.recovery).toContain("/scan/recover");
});
});
Loading
Loading