Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to axiom-std #23

Merged
merged 7 commits into from
Feb 13, 2024
Merged
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
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/axiom-v2-periphery"]
path = lib/axiom-v2-periphery
url = https://github.com/axiom-crypto/axiom-v2-periphery
[submodule "lib/axiom-std"]
path = lib/axiom-std
url = https://github.com/axiom-crypto/axiom-std
13 changes: 10 additions & 3 deletions app/axiom/average.circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ import {
getAccount,
} from "@axiom-crypto/client";

/// For type safety, define the input types to your circuit here.
/// These should be the _variable_ inputs to your circuit. Constants can be hard-coded into the circuit itself.
// For type safety, define the input types to your circuit here.
// These should be the _variable_ inputs to your circuit. Constants can be hard-coded into the circuit itself.
export interface CircuitInputs {
blockNumber: CircuitValue;
address: CircuitValue;
}

// Default inputs to use for compiling the circuit. These values should be different than the inputs fed into
// the circuit at proving time.
export const defaultInputs = {
"blockNumber": 4000000,
"address": "0xEaa455e4291742eC362Bc21a8C46E5F2b5ed4701"
};

// The function name `circuit` is searched for by default by our Axiom CLI; if you decide to
// change the function name, you'll also need to ensure that you also pass the Axiom CLI flag
// `-f <circuitFunctionName>` for it to work
export const circuit = async (inputs: CircuitInputs) => {
// Number of samples to take. Note that this must be a constant value and NOT an input because the size of
// the circuit must be known at compile time.
const samples = 8;
const samples = 8;

// Number of blocks between each sample.
const spacing = 900;
Expand Down
4 changes: 0 additions & 4 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const axiomMain = async (input: UserInput<CircuitInputs>) => {
const axiom = new Axiom({
circuit: circuit,
compiledCircuit: compiledCircuit,
inputSchema: {
blockNumber: "uint32",
address: "address",
},
chainId: "11155111", // Sepolia
provider: process.env.PROVIDER_URI_SEPOLIA as string,
privateKey: process.env.PRIVATE_KEY_SEPOLIA as string,
Expand Down
3 changes: 1 addition & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ src = "src"
out = "out"
solc = "0.8.19"
libs = ["node_modules", "lib"]
remappings = ["@axiom-crypto/v2-periphery/=lib/axiom-v2-periphery/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/"]
remappings = ["@axiom-crypto/axiom-std/=lib/axiom-std/src/"]
ffi = true
fs_permissions = [{ access = "read-write", path = ".axiom" }]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
[rpc_endpoints]
Expand Down
1 change: 1 addition & 0 deletions lib/axiom-std
Submodule axiom-std added at 28faed
1 change: 0 additions & 1 deletion lib/axiom-v2-periphery
Submodule axiom-v2-periphery deleted from 8ce739
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from ae570f
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Intrinsic Technologies",
"license": "MIT",
"dependencies": {
"@axiom-crypto/client": "2.0.3",
"@axiom-crypto/client": "2.0.4",
"dotenv": "^16.3.1",
"ethers": "^6.10.0"
},
Expand Down
54 changes: 31 additions & 23 deletions test/AverageBalance.t.sol
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { AxiomTest, AxiomVm } from "@axiom-crypto/v2-periphery/test/AxiomTest.sol";
import { IAxiomV2Query } from "@axiom-crypto/v2-periphery/interfaces/query/IAxiomV2Query.sol";
import "@axiom-crypto/axiom-std/AxiomTest.sol";

import { AverageBalance } from "../src/AverageBalance.sol";

contract AverageBalanceTest is AxiomTest {
using Axiom for Query;

struct AxiomInput {
uint64 blockNumber;
address addr;
}

AverageBalance public averageBalance;
AxiomInput public input;
bytes32 public querySchema;

function setUp() public {
_createSelectForkAndSetupAxiom("sepolia", 5_103_100);

inputPath = "app/axiom/data/inputs.json";
querySchema = axiomVm.compile("app/axiom/average.circuit.ts", inputPath);
input =
AxiomInput({ blockNumber: 4_205_938, addr: address(0x8018fe32fCFd3d166E8b4c4E37105318A84BA11b) });
querySchema = axiomVm.readCircuit("app/axiom/average.circuit.ts");
averageBalance = new AverageBalance(axiomV2QueryAddress, uint64(block.chainid), querySchema);
}

function test_axiomSendQuery() public {
AxiomVm.AxiomSendQueryArgs memory args =
axiomVm.sendQueryArgs(inputPath, address(averageBalance), callbackExtraData, feeData);

axiomV2Query.sendQuery{ value: args.value }(
args.sourceChainId,
args.dataQueryHash,
args.computeQuery,
args.callback,
args.feeData,
args.userSalt,
args.refundee,
args.dataQuery
);
}
/// @dev Simple demonstration of testing an Axiom client contract using Axiom cheatcodes
function test_simple_example() public {
// create a query into Axiom with default parameters
Query memory q = query(querySchema, abi.encode(input), address(averageBalance));

// send the query to Axiom
q.send();

// prank fulfillment of the query, returning the Axiom results
bytes32[] memory results = q.prankFulfill();

// parse Axiom results and verify length is as expected
assertEq(results.length, 3);
uint256 blockNumber = uint256(results[0]);
address addr = address(uint160(uint256(results[1])));
uint256 avg = uint256(results[2]);

function test_axiomCallback() public {
AxiomVm.AxiomFulfillCallbackArgs memory args =
axiomVm.fulfillCallbackArgs(inputPath, address(averageBalance), callbackExtraData, feeData, msg.sender);
axiomVm.prankCallback(args);
// verify the average balance recorded in AverageBalance is as expected
assertEq(avg, averageBalance.provenAverageBalances(blockNumber, addr));
}
}
Loading