Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
style: ran linter
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 21, 2024
1 parent f65fa79 commit 26f98b3
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 462 deletions.
62 changes: 22 additions & 40 deletions contracts/script/SP1ICS07Tendermint.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.13;

import "forge-std/console.sol";
import {Script} from "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {SP1ICS07Tendermint} from "../src/SP1ICS07Tendermint.sol";
import {SP1Verifier} from "@sp1-contracts/SP1Verifier.sol";
import {ICS07Tendermint} from "../src/ics07-tendermint/ICS07Tendermint.sol";
import { Script } from "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { SP1ICS07Tendermint } from "../src/SP1ICS07Tendermint.sol";
import { SP1Verifier } from "@sp1-contracts/SP1Verifier.sol";
import { ICS07Tendermint } from "../src/ics07-tendermint/ICS07Tendermint.sol";

struct SP1ICS07TendermintGenesisJson {
bytes trustedClientState;
Expand All @@ -21,24 +21,17 @@ contract SP1TendermintScript is Script {

SP1ICS07Tendermint public ics07Tendermint;

function setUp() public {}
function setUp() public { }

// Deploy the SP1 Tendermint contract with the supplied initialization parameters.
function run() public returns (address) {
// Read the initialization parameters for the SP1 Tendermint contract.
SP1ICS07TendermintGenesisJson memory genesis = loadGenesis(
"genesis.json"
);
SP1ICS07TendermintGenesisJson memory genesis = loadGenesis("genesis.json");

ICS07Tendermint.ConsensusState memory trustedConsensusState = abi
.decode(
genesis.trustedConsensusState,
(ICS07Tendermint.ConsensusState)
);
ICS07Tendermint.ConsensusState memory trustedConsensusState =
abi.decode(genesis.trustedConsensusState, (ICS07Tendermint.ConsensusState));

bytes32 trustedConsensusHash = keccak256(
abi.encode(trustedConsensusState)
);
bytes32 trustedConsensusHash = keccak256(abi.encode(trustedConsensusState));

vm.startBroadcast();

Expand All @@ -54,43 +47,32 @@ contract SP1TendermintScript is Script {

vm.stopBroadcast();

ICS07Tendermint.ClientState memory clientState = ics07Tendermint
.getClientState();
assert(
keccak256(abi.encode(clientState)) ==
keccak256(genesis.trustedClientState)
);
ICS07Tendermint.ClientState memory clientState = ics07Tendermint.getClientState();
assert(keccak256(abi.encode(clientState)) == keccak256(genesis.trustedClientState));

bytes32 consensusHash = ics07Tendermint.getConsensusStateHash(
clientState.latest_height.revision_height
);
bytes32 consensusHash = ics07Tendermint.getConsensusStateHash(clientState.latest_height.revision_height);
assert(consensusHash == keccak256(abi.encode(trustedConsensusState)));

return address(ics07Tendermint);
}

function loadGenesis(
string memory fileName
) public view returns (SP1ICS07TendermintGenesisJson memory) {
function loadGenesis(string memory fileName) public view returns (SP1ICS07TendermintGenesisJson memory) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/contracts/script/", fileName);
string memory json = vm.readFile(path);
bytes memory trustedClientState = json.readBytes(".trustedClientState");
bytes memory trustedConsensusState = json.readBytes(
".trustedConsensusState"
);
bytes memory trustedConsensusState = json.readBytes(".trustedConsensusState");
bytes32 updateClientVkey = json.readBytes32(".updateClientVkey");
bytes32 membershipVkey = json.readBytes32(".membershipVkey");
bytes32 ucAndMembershipVkey = json.readBytes32(".ucAndMembershipVkey");

SP1ICS07TendermintGenesisJson
memory fixture = SP1ICS07TendermintGenesisJson({
trustedClientState: trustedClientState,
trustedConsensusState: trustedConsensusState,
updateClientVkey: updateClientVkey,
membershipVkey: membershipVkey,
ucAndMembershipVkey: ucAndMembershipVkey
});
SP1ICS07TendermintGenesisJson memory fixture = SP1ICS07TendermintGenesisJson({
trustedClientState: trustedClientState,
trustedConsensusState: trustedConsensusState,
updateClientVkey: updateClientVkey,
membershipVkey: membershipVkey,
ucAndMembershipVkey: ucAndMembershipVkey
});

return fixture;
}
Expand Down
17 changes: 12 additions & 5 deletions contracts/src/ISP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {ICS07Tendermint} from "./ics07-tendermint/ICS07Tendermint.sol";
import {UpdateClientProgram} from "./ics07-tendermint/UpdateClientProgram.sol";
import { ICS07Tendermint } from "./ics07-tendermint/ICS07Tendermint.sol";
import { UpdateClientProgram } from "./ics07-tendermint/UpdateClientProgram.sol";

/// @title SP1 ICS07 Tendermint Light Client Interface
/// @author srdtrk
Expand All @@ -26,7 +26,10 @@ interface ISP1ICS07Tendermint {
/// @param proof The encoded proof.
/// @param publicValues The encoded public values.
/// @return The result of the update.
function updateClient(bytes calldata proof, bytes calldata publicValues)
function updateClient(
bytes calldata proof,
bytes calldata publicValues
)
external
returns (UpdateClientProgram.UpdateResult);

Expand All @@ -45,7 +48,9 @@ interface ISP1ICS07Tendermint {
uint32 proofHeight,
bytes calldata trustedConsensusStateBz,
bytes32[] calldata kvPairHashes
) external view;
)
external
view;

/// @notice The entrypoint for updating the client and membership proof.
/// @dev This function verifies the public values and forwards the proof to the SP1 verifier.
Expand All @@ -57,5 +62,7 @@ interface ISP1ICS07Tendermint {
bytes calldata proof,
bytes calldata publicValues,
bytes32[] calldata kvPairHashes
) external returns (UpdateClientProgram.UpdateResult);
)
external
returns (UpdateClientProgram.UpdateResult);
}
37 changes: 26 additions & 11 deletions contracts/src/SP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {ICS07Tendermint} from "./ics07-tendermint/ICS07Tendermint.sol";
import {UpdateClientProgram} from "./ics07-tendermint/UpdateClientProgram.sol";
import {MembershipProgram} from "./ics07-tendermint/MembershipProgram.sol";
import {UpdateClientAndMembershipProgram} from "./ics07-tendermint/UcAndMembershipProgram.sol";
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";
import {ISP1ICS07Tendermint} from "./ISP1ICS07Tendermint.sol";
import { ICS07Tendermint } from "./ics07-tendermint/ICS07Tendermint.sol";
import { UpdateClientProgram } from "./ics07-tendermint/UpdateClientProgram.sol";
import { MembershipProgram } from "./ics07-tendermint/MembershipProgram.sol";
import { UpdateClientAndMembershipProgram } from "./ics07-tendermint/UcAndMembershipProgram.sol";
import { ISP1Verifier } from "@sp1-contracts/ISP1Verifier.sol";
import { ISP1ICS07Tendermint } from "./ISP1ICS07Tendermint.sol";
import "forge-std/console.sol";

/// @title SP1 ICS07 Tendermint Light Client
Expand Down Expand Up @@ -79,7 +79,10 @@ contract SP1ICS07Tendermint is ISP1ICS07Tendermint {
/// @param proof The encoded proof.
/// @param publicValues The encoded public values.
/// @return The result of the update.
function updateClient(bytes calldata proof, bytes calldata publicValues)
function updateClient(
bytes calldata proof,
bytes calldata publicValues
)
public
returns (UpdateClientProgram.UpdateResult)
{
Expand Down Expand Up @@ -120,7 +123,10 @@ contract SP1ICS07Tendermint is ISP1ICS07Tendermint {
uint32 proofHeight,
bytes calldata trustedConsensusStateBz,
bytes32[] calldata kvPairHashes
) public view {
)
public
view
{
MembershipProgram.MembershipOutput memory output =
abi.decode(publicValues, (MembershipProgram.MembershipOutput));

Expand Down Expand Up @@ -154,7 +160,10 @@ contract SP1ICS07Tendermint is ISP1ICS07Tendermint {
bytes calldata proof,
bytes calldata publicValues,
bytes32[] calldata kvPairHashes
) public returns (UpdateClientProgram.UpdateResult) {
)
public
returns (UpdateClientProgram.UpdateResult)
{
UpdateClientAndMembershipProgram.UcAndMembershipOutput memory output =
abi.decode(publicValues, (UpdateClientAndMembershipProgram.UcAndMembershipOutput));

Expand Down Expand Up @@ -205,7 +214,10 @@ contract SP1ICS07Tendermint is ISP1ICS07Tendermint {
bytes32 outputCommitmentRoot,
uint32 proofHeight,
bytes memory trustedConsensusStateBz
) private view {
)
private
view
{
require(clientState.is_frozen == false, "SP1ICS07Tendermint: client is frozen");
require(
consensusStateHashes[proofHeight] == keccak256(trustedConsensusStateBz),
Expand Down Expand Up @@ -274,7 +286,10 @@ contract SP1ICS07Tendermint is ISP1ICS07Tendermint {
function abiPublicTypes(
MembershipProgram.MembershipOutput memory output,
UpdateClientAndMembershipProgram.UcAndMembershipOutput memory output2
) public pure {
)
public
pure
{
// This is a dummy function to generate the ABI for MembershipOutput
// so that it can be used in the SP1 verifier contract.
// The function is not used in the contract.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/ics07-tendermint/MembershipProgram.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ICS07Tendermint} from "./ICS07Tendermint.sol";
import { ICS07Tendermint } from "./ICS07Tendermint.sol";

/// @title MembershipProgram
/// @author srdtrk
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/ics07-tendermint/UcAndMembershipProgram.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ICS07Tendermint} from "./ICS07Tendermint.sol";
import {MembershipProgram} from "./MembershipProgram.sol";
import {UpdateClientProgram} from "./UpdateClientProgram.sol";
import { ICS07Tendermint } from "./ICS07Tendermint.sol";
import { MembershipProgram } from "./MembershipProgram.sol";
import { UpdateClientProgram } from "./UpdateClientProgram.sol";

/// @title UpdateClientAndMembershipProgram
/// @author srdtrk
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/ics07-tendermint/UpdateClientProgram.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ICS07Tendermint} from "./ICS07Tendermint.sol";
import { ICS07Tendermint } from "./ICS07Tendermint.sol";

/// @title UpdateClientProgram
/// @author srdtrk
Expand Down
56 changes: 22 additions & 34 deletions contracts/test/MembershipTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity ^0.8.13;

import "forge-std/console.sol";
import {Test} from "forge-std/Test.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {stdError} from "forge-std/StdError.sol";
import {ICS07Tendermint} from "../src/ics07-tendermint/ICS07Tendermint.sol";
import {SP1ICS07Tendermint} from "../src/SP1ICS07Tendermint.sol";
import {SP1ICS07TendermintTest} from "./SP1ICS07TendermintTest.sol";
import {SP1Verifier} from "@sp1-contracts/SP1Verifier.sol";
import {SP1MockVerifier} from "@sp1-contracts/SP1MockVerifier.sol";
import {MembershipProgram} from "../src/ics07-tendermint/MembershipProgram.sol";
import { Test } from "forge-std/Test.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { stdError } from "forge-std/StdError.sol";
import { ICS07Tendermint } from "../src/ics07-tendermint/ICS07Tendermint.sol";
import { SP1ICS07Tendermint } from "../src/SP1ICS07Tendermint.sol";
import { SP1ICS07TendermintTest } from "./SP1ICS07TendermintTest.sol";
import { SP1Verifier } from "@sp1-contracts/SP1Verifier.sol";
import { SP1MockVerifier } from "@sp1-contracts/SP1MockVerifier.sol";
import { MembershipProgram } from "../src/ics07-tendermint/MembershipProgram.sol";

struct SP1ICS07MembershipFixtureJson {
uint32 proofHeight;
Expand All @@ -28,10 +28,7 @@ abstract contract MembershipTest is SP1ICS07TendermintTest {
SP1ICS07MembershipFixtureJson public fixture;
SP1ICS07MembershipFixtureJson public mockFixture;

function setUpTestWithFixtures(
string memory fileName,
string memory mockFileName
) public {
function setUpTestWithFixtures(string memory fileName, string memory mockFileName) public {
fixture = loadFixture(fileName);
mockFixture = loadFixture(mockFileName);

Expand All @@ -42,40 +39,31 @@ abstract contract MembershipTest is SP1ICS07TendermintTest {
return abi.decode(fixture.kvPairsBz, (MembershipProgram.KVPair[]));
}

function mockKvPairs()
public
view
returns (MembershipProgram.KVPair[] memory)
{
function mockKvPairs() public view returns (MembershipProgram.KVPair[] memory) {
return abi.decode(mockFixture.kvPairsBz, (MembershipProgram.KVPair[]));
}

function loadFixture(
string memory fileName
) public view returns (SP1ICS07MembershipFixtureJson memory) {
function loadFixture(string memory fileName) public view returns (SP1ICS07MembershipFixtureJson memory) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/contracts/fixtures/", fileName);
string memory json = vm.readFile(path);
bytes memory trustedClientState = json.readBytes(".trustedClientState");
bytes memory trustedConsensusState = json.readBytes(
".trustedConsensusState"
);
bytes memory trustedConsensusState = json.readBytes(".trustedConsensusState");
uint32 proofHeight = uint32(json.readUint(".proofHeight"));
bytes32 commitmentRoot = json.readBytes32(".commitmentRoot");
bytes memory publicValues = json.readBytes(".publicValues");
bytes memory proof = json.readBytes(".proof");
bytes memory kvPairsBz = json.readBytes(".kvPairs");

SP1ICS07MembershipFixtureJson
memory fix = SP1ICS07MembershipFixtureJson({
commitmentRoot: commitmentRoot,
trustedClientState: trustedClientState,
trustedConsensusState: trustedConsensusState,
proofHeight: proofHeight,
publicValues: publicValues,
proof: proof,
kvPairsBz: kvPairsBz
});
SP1ICS07MembershipFixtureJson memory fix = SP1ICS07MembershipFixtureJson({
commitmentRoot: commitmentRoot,
trustedClientState: trustedClientState,
trustedConsensusState: trustedConsensusState,
proofHeight: proofHeight,
publicValues: publicValues,
proof: proof,
kvPairsBz: kvPairsBz
});

return fix;
}
Expand Down
Loading

0 comments on commit 26f98b3

Please sign in to comment.