Skip to content

Commit

Permalink
ci: use mock prover in CI (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk authored Jan 22, 2025
1 parent 0d807a2 commit 5630461
Show file tree
Hide file tree
Showing 37 changed files with 489 additions and 191 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SP1_PROVER=mock
NETWORK_PRIVATE_KEY="PRIVATE_KEY"
# Private key which the operator uses to sign the transactions in Eth Sepolia testnet
PRIVATE_KEY="PRIVATE-KEY"
# Optional address of the sp1 verifier contract to use (if not set, the contract will be deployed)
# Can be set to "mock" to use the mock verifier
VERIFIER=mock

# URL of the Tendermint RPC node
TENDERMINT_RPC_URL=http://public-celestia-mocha4-consensus.numia.xyz/
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ jobs:
runs-on: ubuntu-latest
env:
ETH_TESTNET_TYPE: ${{ github.event.inputs.ethTestnetType || (github.event_name == 'schedule' && 'pos') || 'pow' }}
SP1_PROVER: ${{ (github.event.inputs.ethTestnetType == 'pos' && 'network') || (github.event_name == 'schedule' && 'network') || 'mock' }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
push:
branches: [main]
pull_request:
paths:
- '**.rs'
- '**.toml'
- '**.lock'
- '**.proto'
- 'abi/**'

jobs:
lints:
Expand Down
3 changes: 1 addition & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"named-parameters-mapping": "warn",
"no-console": "off",
"not-rely-on-time": "off",
"one-contract-per-file": "off",
"gas-custom-errors": "off"
"one-contract-per-file": "off"
}
}
113 changes: 62 additions & 51 deletions abi/SP1ICS07Tendermint.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "sp1Verifier",
"type": "address",
"internalType": "address"
},
{
"name": "_clientState",
"type": "bytes",
Expand Down Expand Up @@ -643,74 +648,80 @@
},
{
"type": "function",
"name": "getClientState",
"name": "clientState",
"inputs": [],
"outputs": [
{
"name": "",
"name": "chainId",
"type": "string",
"internalType": "string"
},
{
"name": "trustLevel",
"type": "tuple",
"internalType": "struct IICS07TendermintMsgs.ClientState",
"internalType": "struct IICS07TendermintMsgs.TrustThreshold",
"components": [
{
"name": "chainId",
"type": "string",
"internalType": "string"
},
{
"name": "trustLevel",
"type": "tuple",
"internalType": "struct IICS07TendermintMsgs.TrustThreshold",
"components": [
{
"name": "numerator",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "denominator",
"type": "uint8",
"internalType": "uint8"
}
]
"name": "numerator",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "latestHeight",
"type": "tuple",
"internalType": "struct IICS02ClientMsgs.Height",
"components": [
{
"name": "revisionNumber",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "revisionHeight",
"type": "uint32",
"internalType": "uint32"
}
]
},
"name": "denominator",
"type": "uint8",
"internalType": "uint8"
}
]
},
{
"name": "latestHeight",
"type": "tuple",
"internalType": "struct IICS02ClientMsgs.Height",
"components": [
{
"name": "trustingPeriod",
"name": "revisionNumber",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "unbondingPeriod",
"name": "revisionHeight",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "isFrozen",
"type": "bool",
"internalType": "bool"
},
{
"name": "zkAlgorithm",
"type": "uint8",
"internalType": "enum ISP1Msgs.SupportedZkAlgorithm"
}
]
},
{
"name": "trustingPeriod",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "unbondingPeriod",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "isFrozen",
"type": "bool",
"internalType": "bool"
},
{
"name": "zkAlgorithm",
"type": "uint8",
"internalType": "enum ISP1Msgs.SupportedZkAlgorithm"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getClientState",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"stateMutability": "view"
Expand Down
88 changes: 79 additions & 9 deletions abigen/sp1ics07tendermint/contract.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions contracts/interfaces/ILightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ interface ILightClient is ILightClientMsgs {
/// @notice Upgrading the client
/// @param upgradeMsg The upgrade message
function upgradeClient(bytes calldata upgradeMsg) external;

/// @notice Returns the client state.
/// @return The client state.
function getClientState() external view returns (bytes memory);
}
5 changes: 0 additions & 5 deletions contracts/light-clients/ISP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.28;

import { ILightClient } from "../interfaces/ILightClient.sol";
import { IICS07TendermintMsgs } from "./msgs/IICS07TendermintMsgs.sol";
import { ISP1Verifier } from "@sp1-contracts/ISP1Verifier.sol";

/// @title ISP1ICS07Tendermint
Expand Down Expand Up @@ -32,10 +31,6 @@ interface ISP1ICS07Tendermint is ILightClient {
/// @return The allowed clock drift in seconds.
function ALLOWED_SP1_CLOCK_DRIFT() external view returns (uint16);

/// @notice Returns the client state.
/// @return The client state.
function getClientState() external view returns (IICS07TendermintMsgs.ClientState memory);

/// @notice Returns the consensus state keccak256 hash at the given revision height.
/// @param revisionHeight The revision height.
/// @return The consensus state at the given revision height.
Expand Down
22 changes: 8 additions & 14 deletions contracts/light-clients/SP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { ILightClientMsgs } from "../msgs/ILightClientMsgs.sol";
import { ILightClient } from "../interfaces/ILightClient.sol";

import { ISP1Verifier } from "@sp1-contracts/ISP1Verifier.sol";
import { SP1Verifier as SP1VerifierPlonk } from "@sp1-contracts/v4.0.0-rc.3/SP1VerifierPlonk.sol";
import { SP1Verifier as SP1VerifierGroth16 } from "@sp1-contracts/v4.0.0-rc.3/SP1VerifierGroth16.sol";

import { Multicall } from "@openzeppelin/utils/Multicall.sol";
import { TransientSlot } from "@openzeppelin/utils/TransientSlot.sol";
Expand Down Expand Up @@ -50,26 +48,28 @@ contract SP1ICS07Tendermint is
ISP1Verifier public immutable VERIFIER;

/// @notice The ICS07Tendermint client state
ClientState private clientState;
ClientState public clientState;
/// @notice The mapping from height to consensus state keccak256 hashes.
mapping(uint32 height => bytes32 hash) private consensusStateHashes;

/// @notice Allowed clock drift.
/// @inheritdoc ISP1ICS07Tendermint
uint16 public constant ALLOWED_SP1_CLOCK_DRIFT = 50 minutes;
uint16 public constant ALLOWED_SP1_CLOCK_DRIFT = 30 minutes;

/// @notice The constructor sets the program verification key and the initial client and consensus states.
/// @param updateClientProgramVkey The verification key for the update client program.
/// @param membershipProgramVkey The verification key for the verify (non)membership program.
/// @param updateClientAndMembershipProgramVkey The verification key for the update client and membership program.
/// @param misbehaviourProgramVkey The verification key for the misbehaviour program.
/// @param sp1Verifier The address of the SP1 verifier contract.
/// @param _clientState The encoded initial client state.
/// @param _consensusState The encoded initial consensus state.
constructor(
bytes32 updateClientProgramVkey,
bytes32 membershipProgramVkey,
bytes32 updateClientAndMembershipProgramVkey,
bytes32 misbehaviourProgramVkey,
address sp1Verifier,
bytes memory _clientState,
bytes32 _consensusState
) {
Expand All @@ -81,23 +81,17 @@ contract SP1ICS07Tendermint is
clientState = abi.decode(_clientState, (ClientState));
consensusStateHashes[clientState.latestHeight.revisionHeight] = _consensusState;

if (clientState.zkAlgorithm == SupportedZkAlgorithm.Groth16) {
VERIFIER = new SP1VerifierGroth16();
} else if (clientState.zkAlgorithm == SupportedZkAlgorithm.Plonk) {
VERIFIER = new SP1VerifierPlonk();
} else {
revert UnknownZkAlgorithm(uint8(clientState.zkAlgorithm));
}
VERIFIER = ISP1Verifier(sp1Verifier);

require(
clientState.trustingPeriod <= clientState.unbondingPeriod,
TrustingPeriodTooLong(clientState.trustingPeriod, clientState.unbondingPeriod)
);
}

/// @inheritdoc ISP1ICS07Tendermint
function getClientState() public view returns (ClientState memory) {
return clientState;
/// @inheritdoc ILightClient
function getClientState() external view returns (bytes memory) {
return abi.encode(clientState);
}

/// @inheritdoc ISP1ICS07Tendermint
Expand Down
2 changes: 1 addition & 1 deletion contracts/light-clients/msgs/IICS07TendermintMsgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface IICS07TendermintMsgs is IICS02ClientMsgs, ISP1Msgs {
/// submitted headers are valid for upgrade in seconds.
/// @param unbondingPeriod duration of the staking unbonding period in seconds
/// @param isFrozen whether or not client is frozen (due to misbehavior)
/// @param zkAlgorithm The zk algorithm supported by this contract.
/// @param zkAlgorithm The zk algorithm supported by this contract (for the relayers).
struct ClientState {
string chainId;
TrustThreshold trustLevel;
Expand Down
24 changes: 18 additions & 6 deletions e2e/interchaintestv8/ibc_eureka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,21 @@ func (s *IbcEurekaTestSuite) SetupSuite(ctx context.Context, proofType operator.

prover = os.Getenv(testvalues.EnvKeySp1Prover)
switch prover {
case "":
prover = testvalues.EnvValueSp1Prover_Network
case testvalues.EnvValueSp1Prover_Mock:
case "", testvalues.EnvValueSp1Prover_Mock:
s.T().Logf("Using mock prover")
prover = testvalues.EnvValueSp1Prover_Mock
os.Setenv(testvalues.EnvKeySp1Prover, testvalues.EnvValueSp1Prover_Mock)
os.Setenv(testvalues.EnvKeyVerifier, testvalues.EnvValueVerifier_Mock)

s.Require().Empty(
os.Getenv(testvalues.EnvKeyGenerateSolidityFixtures),
"Fixtures are not supported for mock prover",
)
case testvalues.EnvValueSp1Prover_Network:
s.Require().Empty(
os.Getenv(testvalues.EnvKeyVerifier),
fmt.Sprintf("%s should not be set when using the network prover in e2e tests.", testvalues.EnvKeyVerifier),
)
default:
s.Require().Fail("invalid prover type: %s", prover)
}
Expand Down Expand Up @@ -148,7 +158,8 @@ func (s *IbcEurekaTestSuite) SetupSuite(ctx context.Context, proofType operator.
)
switch prover {
case testvalues.EnvValueSp1Prover_Mock:
s.FailNow("Mock prover not supported")
stdout, err = eth.ForgeScript(s.deployer, testvalues.E2EDeployScriptPath)
s.Require().NoError(err)
case testvalues.EnvValueSp1Prover_Network:
// make sure that the NETWORK_PRIVATE_KEY is set.
s.Require().NotEmpty(os.Getenv(testvalues.EnvKeyNetworkPrivateKey))
Expand Down Expand Up @@ -243,7 +254,8 @@ func (s *IbcEurekaTestSuite) SetupSuite(ctx context.Context, proofType operator.
BeaconAPI: beaconAPI,
SP1PrivateKey: os.Getenv(testvalues.EnvKeyNetworkPrivateKey),
SignerAddress: s.SimdRelayerSubmitter.FormattedAddress(),
Mock: os.Getenv(testvalues.EnvKeyEthTestnetType) == testvalues.EthTestnetTypePoW,
MockWasmClient: os.Getenv(testvalues.EnvKeyEthTestnetType) == testvalues.EthTestnetTypePoW,
MockSP1Client: prover == testvalues.EnvValueSp1Prover_Mock,
}

err := configInfo.GenerateEthCosmosConfigFile(testvalues.RelayerConfigFilePath)
Expand Down Expand Up @@ -293,7 +305,7 @@ func (s *IbcEurekaTestSuite) DeployTest(ctx context.Context, proofType operator.
eth, simd := s.EthChain, s.CosmosChains[0]

s.Require().True(s.Run("Verify SP1 Client", func() {
clientState, err := s.sp1Ics07Contract.GetClientState(nil)
clientState, err := s.sp1Ics07Contract.ClientState(nil)
s.Require().NoError(err)

stakingParams, err := simd.StakingQueryParams(ctx)
Expand Down
Loading

0 comments on commit 5630461

Please sign in to comment.