Skip to content

Commit

Permalink
Harmonize integrity checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Feb 24, 2025
1 parent d3de937 commit a3e93a6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/app/app/api/permissions/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from "next/server"
import { checkIntegrity } from "zodiac-roles-sdk"
import { targetIntegrity } from "zodiac-roles-sdk"
import { kv } from "@vercel/kv"
import { createHash } from "crypto"
import { PermissionsPost, zPermissionsPost } from "./types"
Expand All @@ -18,7 +18,7 @@ export async function POST(req: Request) {

if (validated.targets) {
try {
checkIntegrity(validated.targets)
targetIntegrity(validated.targets)
} catch (e) {
return NextResponse.json({
error: "Targets integrity check failed",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/app/permissions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from "next/navigation"
import {
Annotation,
Target,
checkIntegrity,
targetIntegrity,
processPermissions,
} from "zodiac-roles-sdk"
import styles from "./page.module.css"
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function PermissionsPage() {

if (targets) {
try {
checkIntegrity(targets)
targetIntegrity(targets)
} catch (e) {
errorMessage =
e instanceof Error
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "zodiac-roles-deployments"
*/
export { c, forAll } from "./target/authoring"
export { planApply, planApplyRole, planExtendRole } from "./target/plan"
export { default as targetIntegrity } from "./target/integrity"

/*
*
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/main/target/authoring/c/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumberish, isHexString, ParamType } from "ethers"
import { Condition, Operator, ParameterType } from "zodiac-roles-deployments"

import { coercePermission } from "../../../permission/coercePermission"
import { checkParameterTypeCompatibility } from "../../condition/checkConditionIntegrity"
import { checkParameterTypeCompatibility } from "../../condition/conditionIntegrity"
import { describeStructure } from "../helpers/describeStructure"
import { parameterType } from "../helpers/parameterType"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Operator, ParameterType } from "zodiac-roles-deployments"
import {
checkConditionIntegrity,
checkRootConditionIntegrity,
} from "./checkConditionIntegrity"
} from "./conditionIntegrity"
import { abiEncode } from "../../utils/abiEncode"

suite("checkConditionIntegrity()", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Condition, Operator, ParameterType } from "zodiac-roles-deployments"

export const checkConditionIntegrity = (condition: Condition): void => {
checkConsistentChildrenTypes(condition)
checkConditionIntegrityRecursive(condition)
}

export const checkRootConditionIntegrity = (condition: Condition): void => {
const rootType = checkConsistentChildrenTypes(condition)
if (rootType !== ParameterType.Calldata) {
Expand All @@ -15,6 +10,11 @@ export const checkRootConditionIntegrity = (condition: Condition): void => {
checkConditionIntegrityRecursive(condition)
}

export const checkConditionIntegrity = (condition: Condition): void => {
checkConsistentChildrenTypes(condition)
checkConditionIntegrityRecursive(condition)
}

/**
* Validates that logical condition children have consistent types.
* Since the children conditions address the very same value it does not make sense for them to declare incompatible param types.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Clearance, Function, Target } from "zodiac-roles-deployments"

import { checkRootConditionIntegrity } from "../target/condition/checkConditionIntegrity"
import { checkRootConditionIntegrity } from "./condition/conditionIntegrity"

export const checkIntegrity = (targets: Target[]): void => {
export default (targets: Target[]): void => {
const uniqueAddresses = new Set(
targets.map((target) => target.address.toLowerCase())
)
if (uniqueAddresses.size < targets.length) {
throw new Error("Duplicate target addresses")
}

targets.forEach(checkTargetIntegrity)
targets.forEach(targetIntegrity)
}

const checkTargetIntegrity = (target: Target): void => {
const targetIntegrity = (target: Target): void => {
if (
target.clearance === Clearance.Function &&
target.functions.length === 0
Expand All @@ -36,10 +36,10 @@ const checkTargetIntegrity = (target: Target): void => {
throw new Error(`Duplicate functions in target ${target.address}`)
}

target.functions.forEach(checkFunctionIntegrity)
target.functions.forEach(functionIntegrity)
}

const checkFunctionIntegrity = (func: Function): void => {
const functionIntegrity = (func: Function): void => {
if (func.wildcarded && func.condition) {
throw new Error(
`Wildcarded functions cannot have conditions (function in violation: ${func.selector})`
Expand Down

0 comments on commit a3e93a6

Please sign in to comment.