We present a machine-checked formalization of elementary abstract algebra in constructive set theory. Our formalization uses an approach where we start by specifying the group axioms as a collection of inference rules, defining a logic for groups. Then we can tell whether a given set with a binary operation is a group or not, and derive all properties of groups constructively from these inference rules as well as the axioms of the set theory. The formalization of all other concepts in abstract algebra is based on that of the group. We give an example of a formalization of a concrete group, the Klein 4-group