Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Dec 7, 2023
1 parent fe18f04 commit b14430e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/zkapps/o1js/foreign-fields.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Foreign Field Arthmetic
title: Foreign Field Arithmetic
hide_title: true
description: Foreign field arithmetic in o1js.
keywords:
Expand All @@ -20,15 +20,15 @@ Please note that zkApp programmability is not yet available on Mina Mainnet, but

A foreign field is a [finite field](https://en.wikipedia.org/wiki/Modular_arithmetic) different from the native field of the proof system. o1js exposes operations like modular addition and multiplication that work in any finite field of size less than 2^259.

Foreign fields are useful for implementing cryptographic algorithms in provable code. For example, you use them for verification of Ethereum-compatible ECDSA signatures ([coming](https://github.com/o1-labs/o1js/pull/1240) [soon](https://github.com/o1-labs/o1js/pull/1291)).
Foreign fields are useful for implementing cryptographic algorithms in provable code. For example, you use them for verification of Ethereum-compatible ECDSA signatures ([coming](https://github.com/o1-labs/o1js/pull/1007) [soon](https://github.com/o1-labs/o1js/pull/1291)).

## Why foreign fields?

If you already know what you need foreign fields for, you can skip this section.

For additional context, recall that the core data type in o1js is `Field`. It represents the field that is _native to the proof system_. In other words, addition and multiplication of `Field`s are the fundamental operations upon which all provable code is built. Because a lot of cryptography uses finite fields, o1js supports several crypto algorithms natively, with high efficiency. See classes and modules like [Poseidon](../o1js-reference/modules#poseidon), [PublicKey](../o1js-reference/classes/Types.PublicKey), [PrivateKey](../o1js-reference/classes/PrivateKey), [Signature](../o1js-reference/classes/Signature) and [Encryption](../o1js-reference/modules/Encryption).

However, none of these are compatible with the cryptography typically used in the wider world: `Signature.verify()` doesn't let you verify a signed JWT or e-mail, and `Encryption.decrypt()` won't help you with your WhatsApp messages. That's because these use different finite fields than our native `Field` (which was chosen primarily to enable efficient zk proofs).
However, none of these are compatible with the cryptography used in the wider world: `Signature.verify()` doesn't let you verify a signed JWT or e-mail, and `Encryption.decrypt()` won't help you with your WhatsApp messages. That's because these use different finite fields than our native `Field` (which was chosen primarily to enable efficient zk proofs).

Here is where foreign fields come in: They let you perform algorithms that connect your zkApp with the outside world of cryptography. Foreign fields come with an efficiency hit compared to the native field, but we heavily engineered them to be efficient enough to unlock many interesting use cases.

Expand Down Expand Up @@ -78,14 +78,14 @@ let zero: ForeignField = Field17.from(0);
let alsoZero: ForeignField = UInt256.from(0);
```

`ForeignField` supports all the basic arithmetic operations:
`ForeignField` supports the basic arithmetic operations:

```ts
x.add(x); // addition
x.sub(2); // subtraction
x.neg(); // negation
x.mul(x); // multiplication
x.div(3); // division
x.mul(3); // multiplication
x.div(x); // division
x.inv(); // inverse
```

Expand All @@ -101,7 +101,7 @@ let bits = x.toBits(); // convert to a `Bool` array of size log2(modulus);
Field17.fromBits(bits); // convert back
```

And non-provable methods for converting to and from JS values:
And there are non-provable methods for converting to and from JS values:

```ts
let y = SmallField.from(5n); // convert from bigint or number
Expand Down

0 comments on commit b14430e

Please sign in to comment.