Reentrancy, the most notorious vulnerability in smart contracts, has attracted extensive attention. To eliminate reentrancy before deploying contracts, there is a need to locate and repair the contracts. However, existing tools suffer from false positive localization, original semantics destruction, and high gas overhead. In this work, we propose a template-based gas-optimized reentrancy repair method with semantic maintenance. We avoid false positive locations from verifying the attack’s effectiveness, using connectivity and read–write dependencies. We design the semantic equivalence check algorithm based on the def-use chain. We optimize the lock and reordering templates for reentrancy repair and add semantic maintenance operations. We implement our tool, ReenRepair, and compare it with two state-of-the-art detection tools and two repair tools. The results show that ReenRepair yields good location precision, the highest repair rate, and the lowest gas overhead. All semantic changes caused by lock and 89.66% of semantic changes caused by reordering are successfully maintained.