> For the complete documentation index, see [llms.txt](https://onyb.gitbook.io/roll-your-own-crypto/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://onyb.gitbook.io/roll-your-own-crypto/group-theory.md).

# Group Theory

A **group** is a set of elements $$Z = {a, b, c, ...}$$ and one binary operator $$+$$ that satisfies the following axioms:

* **Closure:** for any$$a,b ∈ Z$$, the element $$a + b$$ is in $$Z$$ .
* **Associativity:** for any $$a,b,c ∈ Z$$, $$(a + b) + c = a + (b + c)$$.
* **Identity:** $$a + I = a$$ , for all $$a ∈ Z$$.
* **Invertibility:** $$a + (-a) = I$$, for all $$a ∈ Z$$.

In addition to the above properties, if a group exhibits the commutative property of $$a + b = b + a$$, it is called an **abelian group**.

{% hint style="info" %}
The elliptic curve used in Bitcoin is actually a mathematical group, that is **finite**, **cyclic**, **abelian**, and has a **single-generator** point, defined over the **binary addition operator**. These properties form the bedrock for an efficient signature and verification mechanism in Bitcoin.
{% endhint %}

A single-generator group contains an element $$G ∈ Z$$, called the **generator point**, such that repeated additions of $$G$$ with itself can generate every element in $$Z$$.

{% hint style="info" %}
In fact, in prime order elliptic curves, any point can be a generator point.
{% endhint %}

$$Z = {G, 2G, 3G, 4G, ...}$$&#x20;

Additionally, our group is cyclic, which means it has an order $$n$$, such that $$nG = I$$.

Let us now represent the generator point $$G$$in Python, used in Bitcoin.

```python
# Generator point of the abelian group used in Bitcoin
G = Point(
    x=0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
    y=0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8,
    curve=secp256k1
)

# Order of the group generated by G, such that nG = I
N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
```

#### Resources

* <https://web.stanford.edu/class/ee392d/Chap7.pdf>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://onyb.gitbook.io/roll-your-own-crypto/group-theory.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
