Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/contents/guardrail-ai-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ However, a critical problem remains: the current meta of AI agents lacks verifia

Zero Knowledge, provides two distinct capabilities: privacy and scalability.

For this particular case, we’ll focus on the second one. It's currently impossible to verify on-chain the computation of a Machine Learning (ML) model by normal means because it's too expensive and in most cases won't even fit in a an Ethereum block. Instead, we’ll compute the ML model off-chain and use ZK to generate a proof of that computation. This proof can then be verified cheaply on-chain by a Solidity smart contract, ensuring trust without requiring full on-chain execution.
For this particular case, we’ll focus on the second one. It's currently impossible to verify on-chain the computation of a Machine Learning (ML) model by normal means because it's too expensive and in most cases won't even fit in an Ethereum block. Instead, we’ll compute the ML model off-chain and use ZK to generate a proof of that computation. This proof can then be verified cheaply on-chain by a Solidity smart contract, ensuring trust without requiring full on-chain execution.

## Building a Verifiable Tipper AI Agent

Expand All @@ -46,7 +46,7 @@ EZKL provides convenient Google Colab notebooks to help you get started quickly.

## Step 0: Generate an AI model

A model can, for example, decide who deserves a tip based who has the best comments on Farcaster, buy a token based on market conditions, or [mint an NFT based on your singing skills](https://cryptoidol.tech/). There are endless possibilities in terms of what an AI model can do on-chain.
A model can, for example, decide who deserves a tip based on who has the best comments on Farcaster, buy a token based on market conditions, or [mint an NFT based on your singing skills](https://cryptoidol.tech/). There are endless possibilities in terms of what an AI model can do on-chain.

In this example we'll keep it simple, we'll generate a model that just decides who deserves a `1000` token tip deterministically to an address provided.

Expand Down Expand Up @@ -159,7 +159,7 @@ res = ezkl.encode_evm_calldata(
calldata,
)

# Optionally, print the the JSON data
# Optionally, print the JSON data
# print(res)

# Convert the proof from json format to hexadecimal bytes
Expand Down Expand Up @@ -208,9 +208,9 @@ interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
}

// The Tipper contract acts as a guardrail for the AI agent, only allows to perform an action is a valid ZKML proof was submitted
// The Tipper contract acts as a guardrail for the AI agent, only allows to perform an action if a valid ZKML proof was submitted
contract Tipper {
// Replace the following two address with the two contracts you just deployed
// Replace the following two addresses with the two contracts you just deployed
address HALO2_VERIFIER = 0x84fBBc680F4aB4240e8cF6C488aEca03bfF91d2E;
address TIP_TOKEN = 0x84fBBc680F4aB4240e8cF6C488aEca03bfF91d2E;

Expand Down Expand Up @@ -243,4 +243,4 @@ Now call `verifyAndSendTip` by submitting the proof as parameter in the calldata

## Next steps

With ZK, we can develop secure, autonomous and trustless AI agents that operate on-chain. The next steps include mastering ZK concepts and training AI models to be able to create innovative new projects. Get started with ZK at the [Level Up ZK content](https://www.levelup.xyz/content) and learn AI by doing exercises at [Kaggle's Intro to Machine Learning](https://www.kaggle.com/learn/intro-to-machine-learning).
With ZK, we can develop secure, autonomous and trustless AI agents that operate on-chain. The next steps include mastering ZK concepts and training AI models to be able to create innovative new projects. Get started with ZK at the [Level Up ZK content](https://www.levelup.xyz/content) and learn AI by doing exercises at [Kaggle's Intro to Machine Learning](https://www.kaggle.com/learn/intro-to-machine-learning).
10 changes: 5 additions & 5 deletions src/contents/l1sload-guide-read-the-l1-state-from-l2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ labels: ["Protocol"]

Seamless cross-chain account abstraction features will be possible thanks to the [Keystore](https://notes.ethereum.org/@vbuterin/minimal_keystore_rollup). Where users will be able to control multiple smart contract accounts, on multiple chains, with a single key. This will bring rollups closer and provide the so long waited good UX for end users in a [rollup centric Ethereum](https://ethereum-magicians.org/t/a-rollup-centric-ethereum-roadmap/4698).

In order to make this happen, we need to be able to read the L1 data from L2 rollups which is currently a very expensive process. That's why Scroll [introduced](https://scroll.io/blog/towards-the-wallet-endgame-with-keystore) the `L1SLOAD` precompile that is able to read the L1 State fast and cheap. Safe wallet is already creating [a proof of concept](https://github.com/5afe/safe-scroll-keystore) [introduced at Safecon Berlin 2024](https://www.youtube.com/watch?v=hHmOo7A3vNU) of this work and I think this is just the begining: DeFi, gaming, social and many more types of cross-chain applications are possible with this.
In order to make this happen, we need to be able to read the L1 data from L2 rollups which is currently a very expensive process. That's why Scroll [introduced](https://scroll.io/blog/towards-the-wallet-endgame-with-keystore) the `L1SLOAD` precompile that is able to read the L1 State fast and cheap. Safe wallet is already creating [a proof of concept](https://github.com/5afe/safe-scroll-keystore) [introduced at Safecon Berlin 2024](https://www.youtube.com/watch?v=hHmOo7A3vNU) of this work and I think this is just the beginning: DeFi, gaming, social and many more types of cross-chain applications are possible with this.

Let's now learn, with examples, the basics of this new primitive that is set to open the door to a new way of interacting with Ethereum.

Expand Down Expand Up @@ -79,7 +79,7 @@ Next, on the Deploy & Run tab connect the following contract address: `0x9810147

You can now send ETH by calling the `sendMessage` function. As explained below:

- to: Your EOA wallet address. The the ETH recipient on L2
- to: Your EOA wallet address. The ETH recipient on L2
- value: The amount you wish to receive on L2 in wei. For example, if you want to send `0.01` ETH you should pass `10000000000000000`
- message: Leave this empty, just pass `0x00`
- gasLimit: `1000000` should be fine
Expand Down Expand Up @@ -151,11 +151,11 @@ function latestBlockNumber() external view returns (uint256);
}

contract L2Storage {
// This precompile returns the latest block accesible by L2, it is not mandatory to use this precompile but it can help to keep track of the L2 progress
// This precompile returns the latest block accessible by L2, it is not mandatory to use this precompile but it can help to keep track of the L2 progress
address constant L1_BLOCKS_ADDRESS = 0x5300000000000000000000000000000000000001;
// This is the L1SLOAD precompile address
address constant L1_SLOAD_ADDRESS = 0x0000000000000000000000000000000000000101;
// The number varaiable is stored at the slot 0
// The number variable is stored at the slot 0
uint256 constant NUMBER_SLOT = 0;
address immutable l1StorageAddr;

Expand Down Expand Up @@ -302,7 +302,7 @@ pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// In our final example, we'll read the balance of any ERC20 holder on L1
// Please note that we will be using OpenZeppelin's implementation which puts the balance mapping on slot 0, is is not enforced by the ERC20 standard
// Please note that we will be using OpenZeppelin's implementation which puts the balance mapping on slot 0, it is not enforced by the ERC20 standard
contract SimpleToken is ERC20 {
constructor() ERC20("Simple Token", "STKN") {
\_mint(msg.sender, 21_000_000 ether);
Expand Down
2 changes: 1 addition & 1 deletion src/contents/privacy-interfaces-on-soldity-zk-wasm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npm install -g snarkjs

## 1. Create a circuit

We'll create a very simple example: generating a computation proof for a multiplication a*b=c while keeping a and b private. If you're interested in a more advanced example with a real use case, visit my [my previous article](https://www.levelup.xyz/content/private-smart-contracts-with-solidity-and-circom).
We'll create a very simple example: generating a computation proof for a multiplication a*b=c while keeping a and b private. If you're interested in a more advanced example with a real use case, visit [my previous article](https://www.levelup.xyz/content/private-smart-contracts-with-solidity-and-circom).

Circom allows us to create circuits that generate execution proofs while obfuscating the parameters.

Expand Down