Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug caused by circular module chaining #125

Merged
merged 2 commits into from
Jul 26, 2024
Merged
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
4 changes: 4 additions & 0 deletions extension/src/browser/Drawer/RolePermissionCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const simulateRolesTransaction = async (
decodeRolesV2Error(e as JsonRpcError)

if (decodedError) {
if (decodedError.name === 'ModuleTransactionFailed') {
return false
}

if (decodedError.name === 'ConditionViolation') {
return RolesV2Status[decodedError.args.status]
}
Expand Down
13 changes: 9 additions & 4 deletions extension/src/integrations/zodiac/useZodiacModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const useZodiacModules = (
const [modules, setModules] = useState<Module[]>([])

const { chainId } = useRoute(connectionId)

useEffect(() => {
setLoading(true)
setError(false)
Expand All @@ -57,8 +56,15 @@ export const useZodiacModules = (

async function fetchModules(
safeOrModifierAddress: string,
chainId: ChainId
chainId: ChainId,
previous: Set<string> = new Set()
): Promise<Module[]> {
if (previous.has(safeOrModifierAddress.toLowerCase())) {
// circuit breaker in case of circular module references
return []
}
previous.add(safeOrModifierAddress.toLowerCase())

const provider = getReadOnlyProvider(chainId)

const mastercopyAddresses = ContractAddresses[chainId] || {}
Expand All @@ -67,7 +73,6 @@ async function fetchModules(
AvatarInterface,
provider
)

const moduleAddresses = (
await contract.getModulesPaginated(ADDRESS_ONE, 100)
)[0] as string[]
Expand Down Expand Up @@ -115,7 +120,7 @@ async function fetchModules(
if (MODIFIERS.includes(type)) {
// recursively fetch modules from modifier
try {
modules = await fetchModules(moduleAddress, chainId)
modules = await fetchModules(moduleAddress, chainId, previous)
} catch (e) {
console.error(
`Could not fetch sub modules of ${type} modifier ${moduleAddress}`,
Expand Down
Loading