Skip to content

Stack too deep when migrating Gnosis Safe #142

@sekisamu

Description

@sekisamu

Description

Safe extensively uses the proxy pattern in its contract architecture, which easily triggers the maximum call stack depth limit. For example, the simulation feature for multi-sig transactions (essential for Safe usage) involves the following call stack:

SafeProxy 
  └─(delegatecall)→ SafeSingleton
      └─(call)→ CompatibilityFallbackHandler
          └─(call)→ SafeProxy
              └─(delegatecall)→ SafeSingleton
                  └─(delegatecall)→ SimulateTxAccessor
                      └─(call/delegatecall)→ targetContract

The current maximum call stack depth in Revive is insufficient to support this basic use case.

How to Reproduce

  1. Clone and setup the repository
git clone https://github.com/papermoonio/safe-polkadot-poc
cd safe-polkadot-poc
pnpm install
  1. Create .env file
    Create a .env file in the project root:
LOCAL_PRIV_KEY=0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133
LOCAL_PRIV_KEY_2=0xxxx
  1. Run the scripts
# 1. Deploy all contracts
USE_POLKAVM=true npx hardhat run scripts/deployAll.ts --network local
# 2. Execute simulation script
USE_POLKAVM=true npx hardhat run scripts/simulate.ts --network local

Error Messages

Hardhat reports:

ProviderError: execution reverted: 

Substrate node logs show:

2025-07-29 22:53:37.001 TRACE tokio-runtime-worker runtime::revive::strace: call(flags_and_callee: 34359935056, ref_time_limit: 18446744073709551615, proof_size_limit: 18446744073709551615, deposit_and_value: 18446172606835849216, input_data: 131312, output_data: 18446172465102192720) = Err(TrapReason::SupervisorError(Module(ModuleError { index: 80, error: [5, 0, 0, 0], message: Some("MaxCallDepthReached") }))) gas_consumed: Weight { ref_time: 554262959, proof_size: 9078 }

Impact

  • Gnosis Safe cannot function properly on Polkadot
  • Multi-sig wallets and DAOs using Safe infrastructure are blocked
  • Any protocol using similar proxy patterns may face the same limitation

Proposed Solution

Increase the maximum call stack depth limit in Revive to support complex but legitimate contract patterns like those used in Gnosis Safe.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions