ContrastRepair is a novel conversation-based approach for automated program repair (APR) that enhances the effectiveness of large language models (LLMs) by providing contrastive test case pairs. The method leverages both positive and negative feedback to guide LLMs in identifying and fixing bugs. By creating contrastive test pairs, which consist of a failing test and a passing test, ContrastRepair enables LLMs to better isolate the root causes of bugs. The approach involves iteratively interacting with LLMs until plausible patches are generated. The implementation is based on the state-of-the-art LLM, ChatGPT, and it evaluates ContrastRepair on multiple benchmark datasets, including Defects4j, QuixBugs, and HumanEval-Java. The results demonstrate that ContrastRepair significantly outperforms existing methods, achieving a new state-of-the-art in program repair. For instance, among Defects4j 1.2 and 2.0, ContrastRepair correctly repairs 143 out of all 337 bug cases, while the best-performing baseline fixes 124 bugs. The method also shows enhanced efficiency in terms of API calls, with an average reduction of 20.91% compared to CHATREPAIR. The evaluation on three distinct datasets confirms that ContrastRepair achieves new state-of-the-art performance in terms of correct bug fixes, increasing by 15.32% than the best baseline. The method's effectiveness is further supported by its performance on an unseen dataset, HumanEval-Java, where it successfully fixes 137 out of 164 total bugs. The results indicate that ContrastRepair significantly improves the state-of-the-art APR tools, including ChatGPT-based repair methods. The method's success is attributed to its ability to provide informative and specific feedback, which enables LLMs to generate effective bug fixes. The approach also demonstrates superior performance in terms of repair efficiency, with a significant reduction in the number of ChatGPT API queries. The evaluation on various hyperparameters shows that the number of test case pairs and the total number of attempts significantly affect the repair performance of ContrastRepair. The method's effectiveness is further supported by its ability to generate more plausible fixes and improve the success repair rate compared to other methods. Overall, ContrastRepair represents a significant advancement in the field of automated program repair, demonstrating the potential of contrastive test case pairs in enhancing the effectiveness of LLMs in bug fixing.ContrastRepair is a novel conversation-based approach for automated program repair (APR) that enhances the effectiveness of large language models (LLMs) by providing contrastive test case pairs. The method leverages both positive and negative feedback to guide LLMs in identifying and fixing bugs. By creating contrastive test pairs, which consist of a failing test and a passing test, ContrastRepair enables LLMs to better isolate the root causes of bugs. The approach involves iteratively interacting with LLMs until plausible patches are generated. The implementation is based on the state-of-the-art LLM, ChatGPT, and it evaluates ContrastRepair on multiple benchmark datasets, including Defects4j, QuixBugs, and HumanEval-Java. The results demonstrate that ContrastRepair significantly outperforms existing methods, achieving a new state-of-the-art in program repair. For instance, among Defects4j 1.2 and 2.0, ContrastRepair correctly repairs 143 out of all 337 bug cases, while the best-performing baseline fixes 124 bugs. The method also shows enhanced efficiency in terms of API calls, with an average reduction of 20.91% compared to CHATREPAIR. The evaluation on three distinct datasets confirms that ContrastRepair achieves new state-of-the-art performance in terms of correct bug fixes, increasing by 15.32% than the best baseline. The method's effectiveness is further supported by its performance on an unseen dataset, HumanEval-Java, where it successfully fixes 137 out of 164 total bugs. The results indicate that ContrastRepair significantly improves the state-of-the-art APR tools, including ChatGPT-based repair methods. The method's success is attributed to its ability to provide informative and specific feedback, which enables LLMs to generate effective bug fixes. The approach also demonstrates superior performance in terms of repair efficiency, with a significant reduction in the number of ChatGPT API queries. The evaluation on various hyperparameters shows that the number of test case pairs and the total number of attempts significantly affect the repair performance of ContrastRepair. The method's effectiveness is further supported by its ability to generate more plausible fixes and improve the success repair rate compared to other methods. Overall, ContrastRepair represents a significant advancement in the field of automated program repair, demonstrating the potential of contrastive test case pairs in enhancing the effectiveness of LLMs in bug fixing.