Impossible to say where this mess will go without knowing why Iran endorsed this attack in the first place. And no mistake, Hamas would not have moved (and Hezbollah jumped in immediately, so they also knew this was coming) without Tehran at least giving it a thumbs up, if not actively helping plan and execute it.
Most plausible theory I've heard was this was Iran's attempt to drop a turd in the punchbowl of the impending Israeli-Saudi peace deal. KSA was the last big regional Sunni power that wasn't shaking hands with Israel. If the Saudis no longer feel the need to at least act like they're opposing Israel, Iran gets their full attention. Strictly geopolitically speaking, it's not the dumbest strategy for the Iranians, if also incredibly risky. Everything about Hamas' strategy seems designed to generate maximum outrage among the Israeli public. Netanyahu will have a domestic political mandate to go in hard to Gaza and probably also southern Lebanon. Even if he didn't want to (and Bibi isn't exactly a bleeding-heart), the demands from the public will be deafening. So Iran provokes Israeli attacks on Arabs, which historically has been the best way to spike any peace deals; Arab countries don't want to be seen assisting Israeli wars on Arabs, even if it's a non-Arab state that benefits.
The risk to Iran is, they could not have been any more obvious this was a made-in-Tehran production if they'd tried. That pressure on Netanyahu to crack some heads isn't going to end once the immediate situation is under control. I would be shocked if they don't hit Iran directly, or at the very least IRGC facilities outside Iran proper. Question then becomes what happens next. The Iraqis are busy enough with their own mess, Assad doesn't have the bandwidth to get involved with another war, the Jordanians and Egyptians will want no part of fighting on the Shia side. Do the Saudis stand aside? Is the Iranian civil government and regular military cheerleading the IRGC on this?