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

Commit

Permalink
imp: contract
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 10, 2024
1 parent 5f20ad0 commit 3706347
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 44 deletions.
26 changes: 22 additions & 4 deletions contracts/abi/SP1ICS07Tendermint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"type": "constructor",
"inputs": [
{
"name": "_ics07UpdateClientProgramVkey",
"name": "_updateClientProgramVkey",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "_ics07VerifyMembershipProgramVkey",
"name": "_membershipProgramVkey",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "_updateClientAndMembershipProgramVkey",
"type": "bytes32",
"internalType": "bytes32"
},
Expand Down Expand Up @@ -318,7 +323,20 @@
},
{
"type": "function",
"name": "ics07UpdateClientProgramVkey",
"name": "membershipProgramVkey",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "updateClientAndMembershipProgramVkey",
"inputs": [],
"outputs": [
{
Expand All @@ -331,7 +349,7 @@
},
{
"type": "function",
"name": "ics07VerifyMembershipProgramVkey",
"name": "updateClientProgramVkey",
"inputs": [],
"outputs": [
{
Expand Down
28 changes: 13 additions & 15 deletions contracts/src/SP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import "forge-std/console.sol";
/// @custom:poc This is a proof of concept implementation.
contract SP1ICS07Tendermint {
/// @notice The verification key for the update client program.
bytes32 public immutable ics07UpdateClientProgramVkey;
bytes32 public immutable updateClientProgramVkey;
/// @notice The verification key for the verify (non)membership program.
bytes32 public immutable ics07VerifyMembershipProgramVkey;
bytes32 public immutable membershipProgramVkey;
/// @notice The verification key for the update client and membership program.
bytes32 public immutable updateClientAndMembershipProgramVkey;
/// @notice The SP1 verifier contract.
ISP1Verifier public verifier;
ISP1Verifier public immutable verifier;

/// @notice The ICS07Tendermint client state
ICS07Tendermint.ClientState private clientState;
Expand All @@ -31,20 +31,22 @@ contract SP1ICS07Tendermint {
uint64 public constant ALLOWED_SP1_CLOCK_DRIFT = 3000; // 3000 seconds

/// @notice The constructor sets the program verification key and the initial client and consensus states.
/// @param _ics07UpdateClientProgramVkey The verification key for the update client program.
/// @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 _verifier The address of the SP1 verifier contract.
/// @param _clientState The encoded initial client state.
/// @param _consensusState The encoded initial consensus state.
constructor(
bytes32 _ics07UpdateClientProgramVkey,
bytes32 _ics07VerifyMembershipProgramVkey,
bytes32 _updateClientProgramVkey,
bytes32 _membershipProgramVkey,
bytes32 _updateClientAndMembershipProgramVkey,
address _verifier,
bytes memory _clientState,
bytes32 _consensusState
) {
ics07UpdateClientProgramVkey = _ics07UpdateClientProgramVkey;
ics07VerifyMembershipProgramVkey = _ics07VerifyMembershipProgramVkey;
updateClientProgramVkey = _updateClientProgramVkey;
membershipProgramVkey = _membershipProgramVkey;
updateClientAndMembershipProgramVkey = _updateClientAndMembershipProgramVkey;
verifier = ISP1Verifier(_verifier);

Expand Down Expand Up @@ -90,7 +92,7 @@ contract SP1ICS07Tendermint {

// TODO: Make sure that other checks have been made in the proof verification
// such as the consensus state not being outside the trusting period.
verifier.verifyProof(ics07UpdateClientProgramVkey, publicValues, proof);
verifier.verifyProof(updateClientProgramVkey, publicValues, proof);

// adding the new consensus state to the mapping
clientState.latest_height = output.new_height;
Expand Down Expand Up @@ -150,11 +152,7 @@ contract SP1ICS07Tendermint {
trustedConsensusStateBz
);

verifier.verifyProof(
ics07VerifyMembershipProgramVkey,
publicValues,
proof
);
verifier.verifyProof(membershipProgramVkey, publicValues, proof);
}

/// @notice The entrypoint for updating the client and membership proof.
Expand Down Expand Up @@ -212,7 +210,7 @@ contract SP1ICS07Tendermint {
abi.encode(output.update_client_output.new_consensus_state)
);

verifier.verifyProof(ics07UpdateClientProgramVkey, publicValues, proof);
verifier.verifyProof(updateClientProgramVkey, publicValues, proof);
}

/// @notice Validates the MembershipOutput public values.
Expand Down
Loading

0 comments on commit 3706347

Please sign in to comment.