Skip to content

erhant/frencurve

Repository files navigation

Frencurve

Built on Lens Network for Lens Holiday Hackathon using ConnectKit and Hardhat.

home

Curve Friendship

Every account in EVM has an address, derived from a public key, derived from a private key. Public key is simply a coordinate on an "elliptic-curve", so basically it is a point $(x, y) \in \mathbb{F}_p^2$ for some large prime $p$ such that it satisfies the following curve equation of secp256k1:

$$ y^2 = x^3 + 7 $$

A curve-friendship for a pair of points $p, q$ some value threshold t is defined as a function $\text{Fren} : \mathbb{F}_p^2 \times \mathbb{F}_p^2 \to {0, 1}$ which is given below:

$$ \text{Fren}(p, q) = \begin{cases} 1 & \text{Dist}(p, q) < t \\ 0 & \text{Dist}(p, q) \geq t \end{cases} $$

and the distance function $\text{Dist}: \mathbb{F}_p \times \mathbb{F}_p \mapsto {0, 1}^{256}$ is defined as a generic distance function between two points on the curve over the respective field, such that the distance is mapped to a word in EVM. So now, you and your friends can register on-chain, and unlock new potential use-cases with your mathematically provable friendship!

Here is a picture from learnmeabitcoin, where it shows how the points on a curve look like in a finite field. Basically if you are close to other points on this curve, you are friends with them!

Contracts

Frencurve contract is deployed on Lens Testnet. You can interact with it as follows:

  • register({x, y}) with the coordinates of your public key, using the corresponding wallet.
  • makeFrens(address, address) with another address, permanently marking whether you are frens or not on chain!
  • call frenships(address, address) to read frenships of addresses.

We also have a simple ERC20 implementation called FrenERC20 as an example, that only allows token transfers among frens, and none other!

Usage

Install everything with:

pnpm install

Then run with:

pnpm run dev

The website should be live on http://localhost:5173/.

Contracts

We are using the template, initialized with:

git clone --depth=1 --branch=master [email protected]:lens-protocol/lens-network-hardhat-boilerplate.git contracts

rm -rf ./contracts/.git

For this part, read the README within the contracts folder.

Future Work

  • In the current implementation, Frencurve has a single constant that value for friendship that more or less hits a %70 friendship and %30 non-friendship over random wallets. This threshold value can be adjusted per-app.

  • We have used account public keys as identifiers as they can be used cross-chain as well. However, one can also consider ECDSA signatures as coordinates alone too, making app-specific friendships similar to the bulletpoint above.

  • The distance function to be used has many issues with the integer overflows and safe-math operations, one can definitely come up with a better algorithm!

About

A notion of friendship based on your location on the elliptic curve 🎎.

Topics

Resources

Stars

Watchers

Forks