r/smartcontracts • u/Bloqarl • 1d ago
If the caller can pick the gas that sends your try/catch into the catch, what should the catch decide?
I spent part of this week on the Glamsterdam PoCs Juicebox published, and one pattern keeps bugging me.
A withdraw pays a 2.5% share to another contract inside a try. If that call reverts, the catch skips the share and the user still gets paid. Makes sense, one broken plugin shouldn't lock everyone's funds. On mainnet today there's no gas limit that gets the withdraw through while the inner payment fails. Under the Glamsterdam gas rules there is, anything from about 182k to 294k, because the new prices make the inner call run out first while the outer one still finishes. So the caller picks the gas and the fee is gone.
The EF's invariants repo says don't take a permanent branch on a failed call: revert so it can be retried, or decide from an explicit answer before the call. But reverting is exactly what that catch was there to avoid, a plugin that reverts forever.
What I lean towards now is checking before the call that the callee gets a minimum amount of gas, and reverting if it doesn't, so a broken plugin still gets skipped but a starved one doesn't. Not sure that survives the next repricing though, it's just another hardcoded number, and whatever happens with EIP-8037 it won't be the last one.
If you have a try/catch in a contract you can't upgrade, what does your catch decide, and how do you tell a callee that really failed from one that was just starved?