What does Iran really gain if they are attacking merchant ships?
Very rough analysis of their possible goals:
Main Goal: Retaliation for sanctions and a bid for bargening power in any negotiations. The US has been saying that the increased sanctioins and curtailing of Iran's oil exports will force them back to the table on their nuke program, and do so in a supplicant role. Iran is not so subtly telling us that they can hurt our interests as far as oil as well, and are willing to do so. If they come back to any negotiations it will be with a wink and nod towards "Treat us right, we can reach out and touch oil shipping in our region".
Secondary bonuses:
* Propaganda at home. They poked the US and we're too scared to do anything about it. See how powerful they are.
* The Iranian Republican Guard Corps Navy (IRGCN) is NOT the Iranian Navy (IRN) They are relatively new, filled with folks picked more for their Revolutionary fervor then military prowess, and use untested equipment and doctrine. This was an opportunity to do some real world testing on whether the ideas and equipment work. If they used a torp or small anti-ship missile as well as mines then they got to test two weapons systems. Plus they have real world Bomb Damage Assessments.
* Non-US countries now know their shipping is at risk due to (predominantly) US actions. With some careful diplomacy that could be leveraged into our allies pressuring us to resolve this issue.
*Intra-mid east rivals (UAE, Oman, KSA) were shown that the IRGCN absolutely CAN strike targets both in foreign ports (last month) and in the Gulf of Oman, which
is was considered to be outside their Area of Operations.
They got all of that done with an attack that has (semi) plausible deniability for diplomacy purposes, while everyone *knows* they did it. It's actually a pretty slick op.