Skip to content

Commit

Permalink
add example proof api contract
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed Dec 9, 2024
1 parent b9f269e commit 33cae1d
Show file tree
Hide file tree
Showing 9 changed files with 1,243 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CONTRACT_NAMES = channel \
IUniversalChannelHandler \
Mars \
Moon \
Venus \
OptimisticLightClient \
OptimisticProofVerifier \
SequencerSoloClient \
Expand Down
524 changes: 524 additions & 0 deletions bindings/go/venus/Venus.go

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions contracts/examples/Venus.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright 2024, Polymer Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.9;

import {ICrossL2Prover} from "../interfaces/ICrossL2Prover.sol";

/**
* @title Venus
* @notice Venus is a simple polymer proof api contract that proves an event happened on another chain.
* @dev This contract is used for only testing and as an example for dapp developers on how to
* integrate with polymer's proof api.
*/
contract Venus {
ICrossL2Prover public immutable prover;

event SuccessfulReceipt(bytes receiptIndex, bytes receiptRLP);
event SuccessfulEvent(uint256 eventIndex, address sender);

error invalidProverAddress();
error invalidReceiptProof();
error invalidEventProof();

constructor(ICrossL2Prover _prover) {
if (address(_prover) == address(0)) {
revert invalidProverAddress();
}
prover = _prover;
}

/**
* * @notice Validates a receipt proof using the ICrossL2Prover contract
* * @param receiptIndex The index of the receipt
* * @param receiptRLPEncodedBytes The RLP encoded receipt
* * @param proof The proof to validate
*/
function receiveReceipt(bytes calldata receiptIndex, bytes calldata receiptRLPEncodedBytes, bytes calldata proof)
external
{
if (!prover.validateReceipt(receiptIndex, receiptRLPEncodedBytes, proof)) {
revert invalidReceiptProof();
}

emit SuccessfulReceipt(receiptIndex, receiptRLPEncodedBytes);
}

/**
* * @notice Validates an event within a receipt proof using the ICrossL2Prover contract
* * @param receiptIndex The index of the receipt
* * @param receiptRLPEncodedBytes The RLP encoded receipt
* * @param proof The proof to validate
*/
function receiveEvent(
bytes calldata receiptIndex,
bytes calldata receiptRLPEncodedBytes,
uint256 logIndex,
bytes calldata logBytes,
bytes calldata proof
) external {
// First we validate receipt to have a more helpful error message if the receipt itself is incorrect

if (!prover.validateReceipt(receiptIndex, receiptRLPEncodedBytes, proof)) {
revert invalidReceiptProof();
}

if (!prover.validateEvent(receiptIndex, receiptRLPEncodedBytes, logIndex, logBytes, proof)) {
revert invalidEventProof();
}

emit SuccessfulEvent(logIndex, msg.sender);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-ibc/vibc-core-smart-contracts",
"version": "4.0.14",
"version": "4.0.15",
"main": "dist/index.js",
"bin": {
"verify-vibc-core-smart-contracts": "./dist/scripts/verify-contract-script.js",
Expand Down
219 changes: 219 additions & 0 deletions src/evm/contracts/Venus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type {
BaseContract,
BigNumberish,
BytesLike,
FunctionFragment,
Result,
Interface,
EventFragment,
AddressLike,
ContractRunner,
ContractMethod,
Listener,
} from "ethers";
import type {
TypedContractEvent,
TypedDeferredTopicFilter,
TypedEventLog,
TypedLogDescription,
TypedListener,
TypedContractMethod,
} from "./common";

export interface VenusInterface extends Interface {
getFunction(
nameOrSignature: "prover" | "receiveEvent" | "receiveReceipt"
): FunctionFragment;

getEvent(
nameOrSignatureOrTopic: "SuccessfulEvent" | "SuccessfulReceipt"
): EventFragment;

encodeFunctionData(functionFragment: "prover", values?: undefined): string;
encodeFunctionData(
functionFragment: "receiveEvent",
values: [BytesLike, BytesLike, BigNumberish, BytesLike, BytesLike]
): string;
encodeFunctionData(
functionFragment: "receiveReceipt",
values: [BytesLike, BytesLike, BytesLike]
): string;

decodeFunctionResult(functionFragment: "prover", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "receiveEvent",
data: BytesLike
): Result;
decodeFunctionResult(
functionFragment: "receiveReceipt",
data: BytesLike
): Result;
}

export namespace SuccessfulEventEvent {
export type InputTuple = [eventIndex: BigNumberish, sender: AddressLike];
export type OutputTuple = [eventIndex: bigint, sender: string];
export interface OutputObject {
eventIndex: bigint;
sender: string;
}
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
export type Filter = TypedDeferredTopicFilter<Event>;
export type Log = TypedEventLog<Event>;
export type LogDescription = TypedLogDescription<Event>;
}

export namespace SuccessfulReceiptEvent {
export type InputTuple = [receiptIndex: BytesLike, receiptRLP: BytesLike];
export type OutputTuple = [receiptIndex: string, receiptRLP: string];
export interface OutputObject {
receiptIndex: string;
receiptRLP: string;
}
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
export type Filter = TypedDeferredTopicFilter<Event>;
export type Log = TypedEventLog<Event>;
export type LogDescription = TypedLogDescription<Event>;
}

export interface Venus extends BaseContract {
connect(runner?: ContractRunner | null): Venus;
waitForDeployment(): Promise<this>;

interface: VenusInterface;

queryFilter<TCEvent extends TypedContractEvent>(
event: TCEvent,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
queryFilter<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;

on<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
on<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;

once<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;

listeners<TCEvent extends TypedContractEvent>(
event: TCEvent
): Promise<Array<TypedListener<TCEvent>>>;
listeners(eventName?: string): Promise<Array<Listener>>;
removeAllListeners<TCEvent extends TypedContractEvent>(
event?: TCEvent
): Promise<this>;

prover: TypedContractMethod<[], [string], "view">;

receiveEvent: TypedContractMethod<
[
receiptIndex: BytesLike,
receiptRLPEncodedBytes: BytesLike,
logIndex: BigNumberish,
logBytes: BytesLike,
proof: BytesLike
],
[void],
"nonpayable"
>;

receiveReceipt: TypedContractMethod<
[
receiptIndex: BytesLike,
receiptRLPEncodedBytes: BytesLike,
proof: BytesLike
],
[void],
"nonpayable"
>;

getFunction<T extends ContractMethod = ContractMethod>(
key: string | FunctionFragment
): T;

getFunction(
nameOrSignature: "prover"
): TypedContractMethod<[], [string], "view">;
getFunction(
nameOrSignature: "receiveEvent"
): TypedContractMethod<
[
receiptIndex: BytesLike,
receiptRLPEncodedBytes: BytesLike,
logIndex: BigNumberish,
logBytes: BytesLike,
proof: BytesLike
],
[void],
"nonpayable"
>;
getFunction(
nameOrSignature: "receiveReceipt"
): TypedContractMethod<
[
receiptIndex: BytesLike,
receiptRLPEncodedBytes: BytesLike,
proof: BytesLike
],
[void],
"nonpayable"
>;

getEvent(
key: "SuccessfulEvent"
): TypedContractEvent<
SuccessfulEventEvent.InputTuple,
SuccessfulEventEvent.OutputTuple,
SuccessfulEventEvent.OutputObject
>;
getEvent(
key: "SuccessfulReceipt"
): TypedContractEvent<
SuccessfulReceiptEvent.InputTuple,
SuccessfulReceiptEvent.OutputTuple,
SuccessfulReceiptEvent.OutputObject
>;

filters: {
"SuccessfulEvent(uint256,address)": TypedContractEvent<
SuccessfulEventEvent.InputTuple,
SuccessfulEventEvent.OutputTuple,
SuccessfulEventEvent.OutputObject
>;
SuccessfulEvent: TypedContractEvent<
SuccessfulEventEvent.InputTuple,
SuccessfulEventEvent.OutputTuple,
SuccessfulEventEvent.OutputObject
>;

"SuccessfulReceipt(bytes,bytes)": TypedContractEvent<
SuccessfulReceiptEvent.InputTuple,
SuccessfulReceiptEvent.OutputTuple,
SuccessfulReceiptEvent.OutputObject
>;
SuccessfulReceipt: TypedContractEvent<
SuccessfulReceiptEvent.InputTuple,
SuccessfulReceiptEvent.OutputTuple,
SuccessfulReceiptEvent.OutputObject
>;
};
}
Loading

0 comments on commit 33cae1d

Please sign in to comment.