# Zero-Knowledge Proofs: Full Guide, Part IV

## From Zero to Knowledge: Modulus arithmetics

We’ve all been there, scratching our heads, trying to make sense of numbers that seem to grow out of control in the computation of complex algorithms. When it comes to Zero-Knowledge Proofs (ZKPs), a foundational concept in blockchain security and cryptography, the need for managing large numbers is paramount. Enter the fascinating world of modular arithmetic.

In this article, we’ll dive into the workings of modular arithmetic, illustrate its applications in ZKPs, and explore how it helps simplify computations without losing the essential characteristics required for secure transactions.

# Introduction to Modular Arithmetic

Modular arithmetic is often described as “clock arithmetic” because it operates in a cyclical manner, much like the hands of a clock. It’s a powerful mathematical tool used extensively in cryptography, computer science, and, of course, ZKPs.

# The Basic Concept

Imagine dividing two integers, A*A* and B*B*, in the standard way:

A÷B=Q+R*A*÷*B*=*Q*+*R*

Here, Q*Q* is the quotient, and R*R* is the remainder. In modular arithmetic, we’re interested in the remainder. The expression Amod B*A*mod*B* yields the remainder R*R*, so:

Amod B=R*A*mod*B*=*R*

For example, 10mod 3=110mod3=1.

## Range of Remainders

An intriguing aspect of modular arithmetic is that for any given modulus n*n*, the remainder can range from 00 to n−1*n*−1.

Let’s illustrate this with an example using modulus 7. Here’s a set of integers: [1,5,10,15,22][1,5,10,15,22]. When we perform mod 7 on each of these numbers, the resulting values will fall within the range of 00 to 66:

[1mod 7,5mod 7,10mod 7,15mod 7,22mod 7]=[1,5,3,1,1][1mod7,5mod7,10mod7,15mod7,22mod7]=[1,5,3,1,1]

# Congruence: A Closer Look

Congruence is a vital concept in modular arithmetic, represented by the ≡ symbol. Two integers, a*a* and b*b*, are said to be congruent mod n*n* if their remainders when divided by n*n* are the same.

## Example 1:

25≡5 (mod 10)25≡5(mod10)

Because both 25 and 5 leave a remainder of 5 when divided by 10.

## Example 2:

81≡9 (mod 12)81≡9(mod12)

Because both 81 and 9 leave a remainder of 9 when divided by 12.

Both 37 and 17, when divided by 10, leave a remainder of 7, so they are congruent mod 10.

# Performing Arithmetic Operations with Modulus

Modular arithmetic isn’t just about remainders; it’s a full-fledged system allowing addition, subtraction, multiplication, and even a form of division.

# Addition

In modular addition, you simply add two numbers and then take the remainder when dividing by the modulus.

## Example 1:

4+7≡1 (mod 5)4+7≡1(mod5)

## Example 2:

9+14≡8 (mod 15)9+14≡8(mod15)

# Subtraction

Subtraction works similarly to addition. If the result is negative, you continue adding the modulus until you get a non-negative answer.

## Example 1:

6−10≡2 (mod 4)6−10≡2(mod4)

## Example 2:

17−22≡8 (mod 9)17−22≡8(mod9)

# Multiplication

Multiplication is just as straightforward. Multiply the numbers and then take the remainder when dividing by the modulus.

## Example 1:

4×5≡6 (mod 7)4×5≡6(mod7)

## Example 2:

9×14≡11 (mod 19)9×14≡11(mod19)

# Division: Modular Inverses

Division isn’t directly defined in modular arithmetic. Instead, we have the concept of modular inverses.

The modular inverse of A (mod C)*A*(mod*C*) is A−1*A*−1, such that:

A×A−1≡1 (mod C)*A*×*A*−1≡1(mod*C*)

To “divide” a number X*X* by A*A* in modular arithmetic, we multiply X*X* by the multiplicative inverse of A*A*:

*AX*(mod*C*)=*X*×*A*−1(mod*C*)

## Example:

If we want to divide 10 by 3 (mod 7), we first find the modular inverse of 3 (mod 7), which is 5. Then we multiply 10 by 5:

10×5≡6 (mod 7)10×5≡6(mod7)

# Why Modular Arithmetic is Essential in ZKPs

Now that we’ve got the basics down, let’s examine why modular arithmetic is so crucial in ZKPs.

# 1. Handling Large Numbers

Modular arithmetic offers a finite set of numbers to work with. This avoids overflow issues and ensures that computations with large numbers remain manageable.

## Example:

When working with 1024-bit numbers in cryptography, using a modulus keeps the numbers within a manageable range, reducing computational overhead.

# 2. Homomorphic Properties

The ability to perform operations on encrypted values without decryption is vital in ZKPs. Modular arithmetic’s homomorphic properties enable the proof generation without revealing the underlying values.

## Example:

In a voting system, homomorphic encryption can be used to add encrypted votes together, and the result can be decrypted to reveal the final tally without exposing individual votes.

# 3. Computational Efficiency

As all computations are within a fixed range, modular arithmetic is typically faster and more resource-efficient. This is especially beneficial in blockchain systems and embedded devices.

## Example:

In blockchain systems, fast modular computations ensure that transactions are processed quickly, even on resource-constrained devices.

# Conclusion

Modular arithmetic is more than a mathematical curiosity; it’s a powerful tool that plays a pivotal role in modern cryptography and blockchain technologies. Its elegance in dealing with numbers, its rich set of operations, and its vital role in Zero-Knowledge Proofs make it an indispensable part of our digital world.

For those looking to delve deeper into modular math, the Euclidean algorithm for finding modular inverses and advanced cryptographic applications are exciting areas to explore. With a solid understanding of modular arithmetic, the world of cryptography and secure computing opens up with new possibilities and challenges.