Skip to content

Commit

Permalink
feat: introduce trusted addresses on report (#95)
Browse files Browse the repository at this point in the history
* feat: introduce trusted addresses on report

* fix: increase timeout

* Update src/govv3/checks/targetsVerified.ts

* fix: update reports
  • Loading branch information
sakulstra committed Jan 16, 2024
1 parent fc259c8 commit 3fa38bd
Show file tree
Hide file tree
Showing 14 changed files with 274,005 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
"access": "public"
},
"dependencies": {
"@bgd-labs/aave-address-book": "2.15.0",
"@bgd-labs/aave-address-book": "2.15.3-89c77b1d7ee3574250b9bef36599806dd7a3bb94.0",
"@bgd-labs/js-utils": "^1.0.3",
"@commander-js/extra-typings": "^11.1.0",
"@inquirer/prompts": "^3.3.0",
"chalk": "^4.1.2",
"commander": "^11.1.0",
"deepmerge": "^4.3.1",
"dotenv": "^16.3.1",
"find-object-paths": "^1.0.2",
"gray-matter": "^4.0.3",
"ipfs-only-hash": "^4.0.0",
"json-bigint": "^1.0.0",
Expand Down
376 changes: 376 additions & 0 deletions src/govv3/__snapshots__/generatePayloadReport.spec.ts.snap

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/govv3/checks/logs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on https://github.com/Uniswap/governance-seatbelt/blob/main/checks/check-logs.ts
// adjusted for viem & aave governance v3
import { getAddress } from 'viem';
import { Address, getAddress } from 'viem';
import { ProposalCheck } from './types';
import { Log } from '../../utils/tenderlyClient';
import { getContractName } from '../utils/solidityUtils';
Expand All @@ -10,22 +10,22 @@ import { getContractName } from '../utils/solidityUtils';
*/
export const checkLogs: ProposalCheck<any> = {
name: 'Reports all events emitted from the proposal',
async checkProposal(proposal, sim, deps) {
async checkProposal(proposal, sim, publicClient) {
let info = [];
const events = sim.transaction.transaction_info.logs?.reduce((logs, log) => {
const addr = getAddress(log.raw.address);
if (!logs[addr]) logs[addr] = [log];
else logs[addr].push(log);
return logs;
}, {} as Record<string, Log[]>);
}, {} as Record<Address, Log[]>);

// Return if no events to show
if (!events || !Object.keys(events).length) return { info: ['No events emitted'], warnings: [], errors: [] };

// Parse each event
for (const [address, logs] of Object.entries(events)) {
// Use contracts array to get contract name of address
info.push(`- ${getContractName(sim.contracts, address)}`);
info.push(`- ${getContractName(sim.contracts, address as Address, publicClient.chain!.id)}`);

// Format log data for report
logs.forEach((log) => {
Expand Down
18 changes: 11 additions & 7 deletions src/govv3/checks/selfDestruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// adjusted for viem & aave governance v3
import { Hex, PublicClient } from 'viem';
import { ProposalCheck } from './types';
import { toAddressLink } from '../utils/markdownUtils';
import { flagKnownAddress, toAddressLink } from '../utils/markdownUtils';
import { PayloadsController } from '../payloadsController';
import { isKnownAddress } from '../utils/checkAddress';

/**
* Check all targets with code if they contain selfdestruct.
Expand Down Expand Up @@ -42,13 +43,16 @@ async function checkNoSelfdestructs(
const error: string[] = [];
for (const addr of addresses) {
const status = await checkNoSelfdestruct(trustedAddrs, addr, provider);
const isAddrKnown = isKnownAddress(addr, provider.chain!.id);
const address = toAddressLink(addr, true, provider);
if (status === 'eoa') info.push(`- ${address}: EOA`);
else if (status === 'empty') warn.push(`- ${address}: EOA (may have code later)`);
else if (status === 'safe') info.push(`- ${address}: Contract (looks safe)`);
else if (status === 'delegatecall') warn.push(`- ${address}: Contract (with DELEGATECALL)`);
else if (status === 'trusted') info.push(`- ${address}: Trusted contract (not checked)`);
else error.push(`- ${address}: Contract (with SELFDESTRUCT)`);
if (status === 'eoa') info.push(`- ${address}: EOA${flagKnownAddress(isAddrKnown)}`);
else if (status === 'empty') warn.push(`- ${address}: EOA (may have code later)${flagKnownAddress(isAddrKnown)}`);
else if (status === 'safe') info.push(`- ${address}: Contract (looks safe)${flagKnownAddress(isAddrKnown)}`);
else if (status === 'delegatecall')
warn.push(`- ${address}: Contract (with DELEGATECALL)${flagKnownAddress(isAddrKnown)}`);
else if (status === 'trusted')
info.push(`- ${address}: Trusted contract (not checked)${flagKnownAddress(isAddrKnown)}`);
else error.push(`- ${address}: Contract (with SELFDESTRUCT)${flagKnownAddress(isAddrKnown)}`);
}
return { info, warn, error };
}
Expand Down
8 changes: 6 additions & 2 deletions src/govv3/checks/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on https://github.com/Uniswap/governance-seatbelt/blob/main/checks/check-state-changes.ts
// adjusted for viem & aave governance v3
import { Hex, getAddress } from 'viem';
import { Address, Hex, getAddress } from 'viem';
import { ProposalCheck } from './types';
import { getContractName } from '../utils/solidityUtils';
import { StateDiff } from '../../utils/tenderlyClient';
Expand Down Expand Up @@ -36,7 +36,11 @@ export const checkStateChanges: ProposalCheck<any> = {
// Parse state changes at each address
for (const [address, diffs] of Object.entries(stateDiffs)) {
// Use contracts array to get contract name of address
stateChanges += `\n\`\`\`diff\n# ${getContractName(simulation.contracts, address)}\n`;
stateChanges += `\n${getContractName(
simulation.contracts,
address as Address,
publicClient.chain!.id
)}\n\`\`\`diff\n`;

// Parse each diff. A single diff may involve multiple storage changes, e.g. a proposal that
// executes three transactions will show three state changes to the `queuedTransactions`
Expand Down
7 changes: 5 additions & 2 deletions src/govv3/checks/targetsVerified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Hex, PublicClient } from 'viem';
import { ProposalCheck } from './types';
import { TenderlySimulationResponse } from '../../utils/tenderlyClient';
import { PayloadsController } from '../payloadsController';
import { isKnownAddress } from '../utils/checkAddress';
import { flagKnownAddress } from '../utils/markdownUtils';

/**
* Check all targets with code are verified on Etherscan
Expand Down Expand Up @@ -39,14 +41,15 @@ async function checkVerificationStatuses(
): Promise<string[]> {
let info: string[] = []; // prepare output
for (const addr of addresses) {
const isAddrKnown = isKnownAddress(addr, provider.chain!.id);
const status = await checkVerificationStatus(sim, addr, provider);
if (status === 'eoa') {
info.push(`- ${addr}: EOA (verification not applicable)`);
} else if (status === 'verified') {
const contract = getContract(sim, addr);
info.push(`- ${addr}: Contract (verified) (${contract?.contract_name})`);
info.push(`- ${addr}: Contract (verified) (${contract?.contract_name}) ${flagKnownAddress(isAddrKnown)}`);
} else {
info.push(`- ${addr}: Contract (not verified)`);
info.push(`- ${addr}: Contract (not verified) ${flagKnownAddress(isAddrKnown)}`);
}
}
return info;
Expand Down
18 changes: 18 additions & 0 deletions src/govv3/generatePayloadReport.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MOCK_PAYLOAD } from './mocks/payload';
import { describe, it, expect } from 'vitest';
import { CHAIN_ID_CLIENT_MAP } from '@bgd-labs/js-utils';
import { generateReport } from './generatePayloadReport.js';

describe('generatePayloadReport', () => {
it(
'should match snapshot',
async () => {
const report = await generateReport({
...(MOCK_PAYLOAD as any),
publicClient: CHAIN_ID_CLIENT_MAP[MOCK_PAYLOAD.simulation.transaction.network_id],
});
expect(report).toMatchSnapshot();
},
{ timeout: 30000 }
);
});
Loading

0 comments on commit 3fa38bd

Please sign in to comment.