@guardefi/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +31 -2
- package/assurance/cli-check.js +446 -0
- package/assurance/cli-project-paths.js +56 -0
- package/assurance/cli-storage.js +289 -0
- package/assurance/cli-ui.js +617 -0
- package/assurance/guardefi-public.js +66 -0
- package/assurance/release-policy.js +212 -0
- package/core/behavioral-diff.js +555 -0
- package/core/canonical-json.js +9 -0
- package/core/engine/abi.js +99 -0
- package/core/engine/assumptions.json +86 -0
- package/core/engine/bytecode.js +119 -0
- package/core/engine/callee-binding.js +140 -0
- package/core/engine/deployment.js +175 -0
- package/core/engine/external-effects.js +40 -0
- package/core/engine/harness.js +503 -0
- package/core/engine/index.js +638 -0
- package/core/engine/integrity.js +124 -0
- package/core/engine/model.js +369 -0
- package/core/engine/policy.js +59 -0
- package/core/engine/proof-certificate.js +69 -0
- package/core/engine/provenance.js +354 -0
- package/core/engine/screen.js +117 -0
- package/core/engine/upgrade-authority.js +327 -0
- package/core/generic.js +334 -0
- package/core/hardhat.js +114 -0
- package/core/isl/behavior-profile.js +169 -0
- package/core/isl/behavior-solidity.js +267 -0
- package/core/isl/behavior-storage.js +151 -0
- package/core/isl/behavior-verify.js +223 -0
- package/core/isl/getter-profile.js +149 -0
- package/core/isl/vendor/NOTICE.md +38 -0
- package/core/isl/vendor/isl-parser.cjs +5872 -0
- package/core/isl-compiler.js +19 -0
- package/core/isl-firewall.js +1396 -0
- package/core/keccak.js +89 -0
- package/core/prove.js +376 -0
- package/core/release-receipt.js +793 -0
- package/core/rpc.js +74 -0
- package/core/tools.js +129 -0
- package/core/verdict-policy.js +195 -0
- package/docs/public-cli.md +32 -0
- package/package.json +29 -4
package/core/rpc.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const HASH = /^0x[0-9a-f]{64}$/i;
|
|
2
|
+
const RESPONSE_LIMIT = 8 * 1024 * 1024;
|
|
3
|
+
|
|
4
|
+
function quantity(value) {
|
|
5
|
+
if (typeof value !== 'string' || !/^0x(?:0|[1-9a-f][0-9a-f]{0,63})$/i.test(value)) {
|
|
6
|
+
throw new Error('RPC returned an invalid block or chain quantity.');
|
|
7
|
+
}
|
|
8
|
+
return BigInt(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const hex = (value) => '0x' + value.toString(16);
|
|
12
|
+
|
|
13
|
+
function rpcEndpoint(endpoint) {
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(endpoint);
|
|
17
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.hash) throw new Error();
|
|
18
|
+
} catch {
|
|
19
|
+
throw new Error('Enter an HTTP or HTTPS RPC URL without embedded credentials.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function rpcReader(endpoint) {
|
|
26
|
+
const url = rpcEndpoint(endpoint);
|
|
27
|
+
let id = 0;
|
|
28
|
+
return async function read(method, params = []) {
|
|
29
|
+
const requestId = ++id;
|
|
30
|
+
let result;
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(url, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
redirect: 'error',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: requestId, method, params }),
|
|
37
|
+
signal: AbortSignal.timeout(12_000),
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok || Number(response.headers.get('content-length')) > RESPONSE_LIMIT) {
|
|
40
|
+
await response.body?.cancel();
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let size = 0;
|
|
45
|
+
for await (const chunk of response.body) {
|
|
46
|
+
size += chunk.byteLength;
|
|
47
|
+
if (size > RESPONSE_LIMIT) throw new Error();
|
|
48
|
+
chunks.push(chunk);
|
|
49
|
+
}
|
|
50
|
+
result = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
51
|
+
} catch {
|
|
52
|
+
throw new Error('Could not read from the RPC endpoint. Check the URL and try again.');
|
|
53
|
+
}
|
|
54
|
+
if (result?.id !== requestId || result.jsonrpc !== '2.0') throw new Error('RPC returned an invalid response.');
|
|
55
|
+
if (result.error) {
|
|
56
|
+
const error = new Error(method === 'eth_getLogs'
|
|
57
|
+
? 'RPC could not return proxy logs for this range. Try a smaller range or a provider with historical logs.'
|
|
58
|
+
: 'RPC could not read the requested block or chain.');
|
|
59
|
+
error.rpcCode = result.error.code;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
if (!Object.hasOwn(result, 'result')) throw new Error('RPC response is missing a result.');
|
|
63
|
+
return result.result;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function blockRef(block, expected) {
|
|
68
|
+
if (!block || typeof block.hash !== 'string' || !HASH.test(block.hash)) throw new Error('RPC could not find the requested block.');
|
|
69
|
+
const number = quantity(block.number);
|
|
70
|
+
if (expected !== undefined && number !== expected) throw new Error('RPC returned a different block than requested.');
|
|
71
|
+
return { number, hash: block.hash.toLowerCase() };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { HASH, quantity, hex, rpcEndpoint, rpcReader, blockRef };
|
package/core/tools.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Thin wrappers around the external tools (forge, cast, halmos).
|
|
2
|
+
// Everything goes through execFile with an argument array: no shell.
|
|
3
|
+
const { execFile } = require('node:child_process');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { createHash } = require('node:crypto');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
const home = os.homedir();
|
|
10
|
+
// Windows spells the variable `Path`; update that key rather than adding a second one.
|
|
11
|
+
const pathKey = Object.keys(process.env).find((key) => key.toUpperCase() === 'PATH') || 'PATH';
|
|
12
|
+
const env = {
|
|
13
|
+
...process.env,
|
|
14
|
+
[pathKey]: [path.join(home, '.foundry', 'bin'), path.join(home, '.local', 'bin'), process.env[pathKey]]
|
|
15
|
+
.filter(Boolean).join(path.delimiter),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Run a tool. Never throws: returns { code, stdout, stderr }. */
|
|
19
|
+
function run(cmd, args, { input, ...opts } = {}) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const child = execFile(cmd, args, { env, maxBuffer: 64 * 1024 * 1024, timeout: 10 * 60 * 1000, ...opts }, (err, stdout, stderr) => {
|
|
22
|
+
resolve({
|
|
23
|
+
code: err ? (typeof err.code === 'number' ? err.code : 1) : 0,
|
|
24
|
+
interrupted: Boolean(err && typeof err.code !== 'number'),
|
|
25
|
+
stdout: String(stdout),
|
|
26
|
+
stderr: String(stderr || (err && typeof err.code !== 'number' ? err.message : '')),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
if (input !== undefined) {
|
|
30
|
+
// execFile reports the command failure even if the child closes stdin early.
|
|
31
|
+
child.stdin.on('error', () => {});
|
|
32
|
+
child.stdin.end(input);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Run cast and return trimmed stdout, or throw with cast's own message. */
|
|
38
|
+
async function cast(args, { execPath = 'cast', ...opts } = {}) {
|
|
39
|
+
const r = await run(execPath, args, opts);
|
|
40
|
+
if (r.code !== 0) throw new Error((r.stderr || r.stdout).trim().split('\n').pop() || `cast ${args[0]} failed`);
|
|
41
|
+
return r.stdout.trim();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Run Halmos on one harness. Returns a map: property name -> { proven, counterexample }.
|
|
46
|
+
* Properties missing from Halmos' output are absent from the map, so callers
|
|
47
|
+
* must treat "absent" as not proven.
|
|
48
|
+
*/
|
|
49
|
+
async function runHalmos(dir, harness, extraArgs = [], options = {}) {
|
|
50
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'guardefi-'));
|
|
51
|
+
const json = path.join(tmp, 'halmos.json');
|
|
52
|
+
try {
|
|
53
|
+
const { receipt, includeRaw = false, executable = 'halmos', ...execOptions } = options;
|
|
54
|
+
const r = await run(executable, ['--root', dir, '--contract', harness, '--json-output', json, ...extraArgs], execOptions);
|
|
55
|
+
if (process.env.GUARDEFI_DEBUG) console.error(r.stdout + r.stderr);
|
|
56
|
+
const diagnostic = (r.stderr || r.stdout).trim().slice(0, 4000);
|
|
57
|
+
if (!fs.existsSync(json)) {
|
|
58
|
+
receipt?.({ exitCode: r.code, interrupted: r.interrupted, outputSha256: null, diagnostic });
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
const raw = fs.readFileSync(json);
|
|
62
|
+
receipt?.({
|
|
63
|
+
exitCode: r.code, interrupted: r.interrupted, outputSha256: createHash('sha256').update(raw).digest('hex'),
|
|
64
|
+
...(r.interrupted ? { diagnostic } : {}),
|
|
65
|
+
...(includeRaw ? { output: raw.toString('base64') } : {}),
|
|
66
|
+
});
|
|
67
|
+
return r.interrupted ? {} : parseHalmosOutput(raw);
|
|
68
|
+
} finally {
|
|
69
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function parseHalmosOutput(raw) {
|
|
74
|
+
// Keep 256-bit counterexample values lossless.
|
|
75
|
+
const text = raw.toString('utf8').replace(/"value":\s*(-?\d+)/g, '"value":"$1"');
|
|
76
|
+
const results = Object.create(null);
|
|
77
|
+
const count = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
78
|
+
for (const tests of Object.values(JSON.parse(text)?.test_results || {})) {
|
|
79
|
+
for (const t of tests) {
|
|
80
|
+
const name = t.name.replace(/\(.*/, '');
|
|
81
|
+
if (Object.hasOwn(results, name)) throw new Error(`Ambiguous checker result name: ${name}`);
|
|
82
|
+
const models = (t.models || []).map((m) => {
|
|
83
|
+
const counterexample = Object.create(null);
|
|
84
|
+
for (const v of Object.values(m.model || {})) {
|
|
85
|
+
if (v.variable_name) counterexample[v.variable_name] = formatValue(v);
|
|
86
|
+
}
|
|
87
|
+
return { counterexample, valid: m.is_valid === true };
|
|
88
|
+
});
|
|
89
|
+
const best = models.find((m) => m.valid) || models[0];
|
|
90
|
+
const paths = Array.isArray(t.num_paths) && t.num_paths.length === 3 && t.num_paths.every(count) ? t.num_paths : null;
|
|
91
|
+
const boundedLoops = count(t.num_bounded_loops) ? t.num_bounded_loops : null;
|
|
92
|
+
const proven = t.exitcode === 0 && t.num_models === 0 && models.length === 0 &&
|
|
93
|
+
boundedLoops !== null && paths !== null && paths[1] > 0 && paths[0] >= paths[1] && paths[2] === 0;
|
|
94
|
+
results[name] = {
|
|
95
|
+
proven,
|
|
96
|
+
counterexample: best?.counterexample || {},
|
|
97
|
+
exitcode: t.exitcode === 0 && !proven ? 5 : t.exitcode,
|
|
98
|
+
boundedLoops,
|
|
99
|
+
paths,
|
|
100
|
+
validModel: best?.valid === true,
|
|
101
|
+
seconds: Array.isArray(t.time) ? t.time[0] : 0,
|
|
102
|
+
models,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function checkerStatus(result) {
|
|
110
|
+
if (!result) return 'error';
|
|
111
|
+
if (result.exitcode === 0 && Number.isSafeInteger(result.boundedLoops) && result.boundedLoops >= 0) {
|
|
112
|
+
return result.boundedLoops > 0 ? 'bounded' : 'proven';
|
|
113
|
+
}
|
|
114
|
+
if (result.exitcode === 1) return result.validModel ? 'violated' : 'timeout';
|
|
115
|
+
if (result.exitcode === 2) return 'timeout';
|
|
116
|
+
return 'error';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function formatValue(v) {
|
|
120
|
+
const n = BigInt(v.value);
|
|
121
|
+
if (v.solidity_type === 'address') return '0x' + n.toString(16).padStart(40, '0');
|
|
122
|
+
return n > 0xffffffffn ? '0x' + n.toString(16) : n.toString();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const isAddress = (s) => typeof s === 'string' && /^0x[0-9a-fA-F]{40}$/.test(s);
|
|
126
|
+
const isName = (s) => typeof s === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(s);
|
|
127
|
+
const isRpcUrl = (s) => typeof s === 'string' && /^https?:\/\/[^\s]+$/.test(s);
|
|
128
|
+
|
|
129
|
+
module.exports = { run, cast, runHalmos, parseHalmosOutput, checkerStatus, isAddress, isName, isRpcUrl };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Authoritative Verdict & Authorization Policy (guardefi.verdict-policy.v1).
|
|
2
|
+
// Resolves all verdict vocabulary across prover, firewall, differential engine,
|
|
3
|
+
// ISL Intent Firewall, Audit Continuity, Dependency Intelligence, and Release
|
|
4
|
+
// Receipts into ONE fail-closed authorization lattice.
|
|
5
|
+
//
|
|
6
|
+
// Invariant: No UNKNOWN, UNVERIFIED, UNSUPPORTED, or BOUNDED mandatory claim
|
|
7
|
+
// may ever silently produce SHIP or unattended execution authorization.
|
|
8
|
+
|
|
9
|
+
const POLICY_VERSION = 'guardefi.verdict-policy.v1';
|
|
10
|
+
const CANONICAL_DECISIONS = Object.freeze(['SHIP', 'REVIEW', 'NO_SHIP']);
|
|
11
|
+
const AUTHORIZATION_MODES = Object.freeze([
|
|
12
|
+
'VERIFIED_SHIP',
|
|
13
|
+
'WAIVER_AUTHORIZED',
|
|
14
|
+
'BLOCKED_REVIEW_REQUIRED',
|
|
15
|
+
'BLOCKED_NO_SHIP',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Normalize legacy subsystem verdict strings and property lists into the
|
|
20
|
+
* authoritative three-state decision (SHIP | REVIEW | NO_SHIP).
|
|
21
|
+
*/
|
|
22
|
+
function normalizeSubsystemVerdict({
|
|
23
|
+
verdict,
|
|
24
|
+
properties = [],
|
|
25
|
+
findings = [],
|
|
26
|
+
reasons = [],
|
|
27
|
+
} = {}) {
|
|
28
|
+
const hasFailedProperty = properties.some((p) =>
|
|
29
|
+
p?.status === 'failed' ||
|
|
30
|
+
p?.status === 'violated' ||
|
|
31
|
+
p?.outcome === 'violated' ||
|
|
32
|
+
Boolean(p?.counterexample)
|
|
33
|
+
);
|
|
34
|
+
const hasViolationFinding = findings.some((f) => !f?.accepted);
|
|
35
|
+
const hasExplicitViolationReason = reasons.some((r) =>
|
|
36
|
+
typeof r === 'string' && /^(function not in spec:|spec check .* did not refute|Incompatible storage)/.test(r)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (verdict === 'NO_SHIP' || hasFailedProperty || hasViolationFinding || hasExplicitViolationReason) {
|
|
40
|
+
return 'NO_SHIP';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const hasUnresolvedOrBounded =
|
|
44
|
+
verdict === 'UNVERIFIED' ||
|
|
45
|
+
verdict === 'UNKNOWN' ||
|
|
46
|
+
verdict === 'UNSUPPORTED' ||
|
|
47
|
+
verdict === 'INCONCLUSIVE' ||
|
|
48
|
+
verdict === 'REVIEW' ||
|
|
49
|
+
properties.some((p) => {
|
|
50
|
+
const st = String(p?.status || '').toLowerCase();
|
|
51
|
+
return (
|
|
52
|
+
p?.epistemicClass === 'BOUNDED' ||
|
|
53
|
+
p?.epistemicClass === 'UNKNOWN' ||
|
|
54
|
+
['bounded', 'unknown', 'unresolved', 'unsupported', 'timeout', 'error', 'accepted'].includes(st) ||
|
|
55
|
+
p?.proven === false
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (hasUnresolvedOrBounded) return 'REVIEW';
|
|
60
|
+
if (verdict === 'SHIP' && properties.length > 0 && properties.every((p) => p.proven === true || p.status === 'proven')) {
|
|
61
|
+
return 'SHIP';
|
|
62
|
+
}
|
|
63
|
+
return 'REVIEW';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Evaluate the complete, authoritative release gate across:
|
|
68
|
+
* - Epistemic claim summary
|
|
69
|
+
* - Expiration & revocation state
|
|
70
|
+
* - Transaction execution envelope match
|
|
71
|
+
* - Live state & dependency assumption health
|
|
72
|
+
* - Audit continuity status
|
|
73
|
+
* - Organization release policy & signed review waivers
|
|
74
|
+
*/
|
|
75
|
+
function evaluateAuthoritativeReleaseGate({
|
|
76
|
+
epistemicSummary,
|
|
77
|
+
expired = false,
|
|
78
|
+
revoked = false,
|
|
79
|
+
revocationReason = null,
|
|
80
|
+
envelopeMismatchReasons = [],
|
|
81
|
+
assumptionStatus = 'ASSUMPTIONS_HOLD', // ASSUMPTIONS_HOLD | INCOMPLETE_OBSERVATION | ASSUMPTION_INVALIDATED | UNPINNED
|
|
82
|
+
auditContinuityStatus = null, // null | PRESERVED | PARTIAL_CONTINUITY | INVALIDATED
|
|
83
|
+
orgPolicy = null,
|
|
84
|
+
validAttesterCount = 0,
|
|
85
|
+
hasValidReviewWaiver = false,
|
|
86
|
+
} = {}) {
|
|
87
|
+
const blockingReasons = [];
|
|
88
|
+
const reviewReasons = [];
|
|
89
|
+
|
|
90
|
+
if (!epistemicSummary || typeof epistemicSummary.total !== 'number' || epistemicSummary.total < 1) {
|
|
91
|
+
blockingReasons.push('No verification claims recorded.');
|
|
92
|
+
} else {
|
|
93
|
+
if (epistemicSummary.violated > 0) {
|
|
94
|
+
blockingReasons.push(`${epistemicSummary.violated} verification claim(s) violated.`);
|
|
95
|
+
}
|
|
96
|
+
if (epistemicSummary.unknown > 0) {
|
|
97
|
+
reviewReasons.push(`${epistemicSummary.unknown} claim(s) have UNKNOWN epistemic status.`);
|
|
98
|
+
}
|
|
99
|
+
if (epistemicSummary.boundedMandatory > 0) {
|
|
100
|
+
reviewReasons.push(`${epistemicSummary.boundedMandatory} mandatory claim(s) rely on BOUNDED exploration.`);
|
|
101
|
+
}
|
|
102
|
+
if (epistemicSummary.openObligations > 0) {
|
|
103
|
+
reviewReasons.push(`${epistemicSummary.openObligations} open deployment obligation(s) remain undischarged.`);
|
|
104
|
+
}
|
|
105
|
+
if (epistemicSummary.proven === 0 && epistemicSummary.observed === 0 && epistemicSummary.bounded === 0) {
|
|
106
|
+
reviewReasons.push('Zero proven, bounded, or observed claims established.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (revoked) {
|
|
111
|
+
blockingReasons.push(`Evidence revoked${revocationReason ? `: ${revocationReason}` : '.'}`);
|
|
112
|
+
}
|
|
113
|
+
if (expired) {
|
|
114
|
+
blockingReasons.push('Evidence has expired past its authorized TTL.');
|
|
115
|
+
}
|
|
116
|
+
for (const mismatch of envelopeMismatchReasons) {
|
|
117
|
+
blockingReasons.push(`Execution binding mismatch: ${mismatch}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (assumptionStatus === 'ASSUMPTION_INVALIDATED') {
|
|
121
|
+
blockingReasons.push('Previously verified on-chain or dependency assumption drifted (stale evidence).');
|
|
122
|
+
} else if (assumptionStatus === 'INCOMPLETE_OBSERVATION' || assumptionStatus === 'UNPINNED') {
|
|
123
|
+
reviewReasons.push(`Live state assumptions are ${assumptionStatus.toLowerCase()}.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (auditContinuityStatus === 'INVALIDATED') {
|
|
127
|
+
blockingReasons.push('Prior audit guarantee invalidated by candidate upgrade.');
|
|
128
|
+
} else if (auditContinuityStatus === 'PARTIAL_CONTINUITY') {
|
|
129
|
+
if (orgPolicy?.requireFullAuditContinuity) {
|
|
130
|
+
blockingReasons.push('Organization policy forbids partial audit continuity without re-audit.');
|
|
131
|
+
} else {
|
|
132
|
+
reviewReasons.push('Audit continuity is partial; modified paths lack discharging ISL proofs.');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (orgPolicy) {
|
|
137
|
+
const minAttesters = Number(orgPolicy.minAttesters ?? 0);
|
|
138
|
+
if (validAttesterCount < minAttesters) {
|
|
139
|
+
reviewReasons.push(`Attester quorum incomplete (${validAttesterCount}/${minAttesters} verified).`);
|
|
140
|
+
}
|
|
141
|
+
if (orgPolicy.requirePinnedAssumptions && assumptionStatus !== 'ASSUMPTIONS_HOLD') {
|
|
142
|
+
if (assumptionStatus !== 'ASSUMPTION_INVALIDATED') {
|
|
143
|
+
reviewReasons.push('Organization policy requires block-pinned live assumptions.');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (blockingReasons.length > 0) {
|
|
149
|
+
return {
|
|
150
|
+
policyVersion: POLICY_VERSION,
|
|
151
|
+
decision: 'NO_SHIP',
|
|
152
|
+
executionAuthorized: false,
|
|
153
|
+
authorizationMode: 'BLOCKED_NO_SHIP',
|
|
154
|
+
blockingReasons,
|
|
155
|
+
reviewReasons,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (reviewReasons.length > 0) {
|
|
160
|
+
const unknownForbidden = orgPolicy?.forbidUnknownInWaiver !== false && (epistemicSummary?.unknown > 0);
|
|
161
|
+
const quorumMet = !orgPolicy || validAttesterCount >= Number(orgPolicy.minAttesters ?? 0);
|
|
162
|
+
const canWaive = Boolean(
|
|
163
|
+
orgPolicy?.allowBoundedReviewWaiver === true &&
|
|
164
|
+
!unknownForbidden &&
|
|
165
|
+
quorumMet &&
|
|
166
|
+
hasValidReviewWaiver
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
policyVersion: POLICY_VERSION,
|
|
171
|
+
decision: 'REVIEW',
|
|
172
|
+
executionAuthorized: canWaive,
|
|
173
|
+
authorizationMode: canWaive ? 'WAIVER_AUTHORIZED' : 'BLOCKED_REVIEW_REQUIRED',
|
|
174
|
+
blockingReasons: [],
|
|
175
|
+
reviewReasons,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
policyVersion: POLICY_VERSION,
|
|
181
|
+
decision: 'SHIP',
|
|
182
|
+
executionAuthorized: true,
|
|
183
|
+
authorizationMode: 'VERIFIED_SHIP',
|
|
184
|
+
blockingReasons: [],
|
|
185
|
+
reviewReasons: [],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = {
|
|
190
|
+
POLICY_VERSION,
|
|
191
|
+
CANONICAL_DECISIONS,
|
|
192
|
+
AUTHORIZATION_MODES,
|
|
193
|
+
normalizeSubsystemVerdict,
|
|
194
|
+
evaluateAuthoritativeReleaseGate,
|
|
195
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# GuardeFi CLI
|
|
2
|
+
|
|
3
|
+
Check Solidity upgrades and review storage layouts locally or in CI. GuardeFi supports Foundry projects and Hardhat projects with compiled artifacts containing storage layout and AST metadata.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Use Node.js 22.12 or later. Foundry supplies `forge` and `cast`. Install Halmos for symbolic upgrade checks.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @guardefi/cli
|
|
11
|
+
guardefi --help
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Check an upgrade
|
|
15
|
+
|
|
16
|
+
From your project's root, pass the candidate contract followed by the baseline contract.
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
guardefi check . VaultV2 VaultV1 --json
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Use `--isl FILE` to add an Intent Specification Language policy. Repeat `--isl` for multiple files. `--fast` runs artifact checks and holds otherwise compatible results for review. Exit codes work in CI: `0` for success, `1` for a failed check, `2` for an input or runtime error, and `3` when review is required.
|
|
23
|
+
|
|
24
|
+
## Review storage layout
|
|
25
|
+
|
|
26
|
+
Provide one contract to inspect its layout. For a comparison, pass the baseline first.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
guardefi storage . VaultV1 VaultV2 --json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
[GuardeFi website](https://guardefi.net/) · [Known limitations](https://guardefi.net/known-limitations.html) · [Contact](https://guardefi.net/#contact)
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardefi/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Offline smart-contract upgrade checks and storage layout review.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://guardefi.net/",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://guardefi.net/#contact"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ethereum",
|
|
12
|
+
"solidity",
|
|
13
|
+
"foundry",
|
|
14
|
+
"hardhat",
|
|
15
|
+
"smart-contracts",
|
|
16
|
+
"formal-verification",
|
|
17
|
+
"security",
|
|
18
|
+
"defi",
|
|
19
|
+
"upgrades",
|
|
20
|
+
"halmos"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.12.0"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"guardefi": "assurance/guardefi-public.js"
|
|
30
|
+
}
|
|
31
|
+
}
|