AxiomREPL Code
The code for AxiomREPL
Introduction
AxiomREPL allows users to write custom ZK circuits in Javascript. We use it here to generate a circuit that proves our request for the parameters from the Swap
event and the same transaction's to
field.
The goal of writing the AxiomREPL code in this section is to export it for use in our Web App that we'll build after this.
AxiomREPL is located at https://repl.axiom.xyz/
Inputs
We have the following inputs to our AxiomREPL code. These inputs are variables that can later be changed (outside of AxiomREPL) in your app. Once the circuit has been exported outside of AxiomREPL into your web app, a different blockNumber
, txIdx
, and logIdx
for a different user's Swap
transaction can be inserted by your web app and used in the circuit.
{
"blockNumber": 9610835,
"txIdx": 6,
"logIdx": 3
}
Note: every transaction hash maps to a unique blockNumber
and txIdx
combination.
Code
The following code implements logic for getting blockchain data and running compute over that data. The inputs from the input box are used here, but this code cannot be changed once it is exported into your web app. Only the variables in the input field above may be changed by your web app.
// `Swap(address,address,int256,int256,uint160,uint128,int24)` event schema
const eventSchema =
"0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67";
// specify and fetch the data you want Axiom to verify
let receipt = getReceipt(blockNumber, txIdx);
let receiptLog = receipt.log(logIdx); //get the log at index 3
// get the topic at index 0 (event schema)
let swapSchema = receiptLog.topic(0, eventSchema);
// get the topic at index 2
let swapTo = receiptLog.topic(2, eventSchema).toCircuitValue();
// get the block number for receipt
let blockNum = receipt.blockNumber().toCircuitValue();
// get the `to` field of the transaction
let tx = getTx(blockNumber, txIdx);
let txTo = tx.to().toCircuitValue();
// adds each of our desired variables to the callback. The callback returns the
// values as an array in the order that `addToCallback` was called.
addToCallback(swapSchema);
addToCallback(swapTo);
addToCallback(blockNum);
addToCallback(txTo);
// logs all of the variables to the right side output panel for sanity check
log(swapSchema);
log(swapTo);
log(blockNum);
log(txTo);
Last updated