Skip to content

Commit 33cae1d

Browse files
committed
add example proof api contract
1 parent b9f269e commit 33cae1d

File tree

9 files changed

+1243
-1
lines changed

9 files changed

+1243
-1
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CONTRACT_NAMES = channel \
2020
IUniversalChannelHandler \
2121
Mars \
2222
Moon \
23+
Venus \
2324
OptimisticLightClient \
2425
OptimisticProofVerifier \
2526
SequencerSoloClient \

bindings/go/venus/Venus.go

+524
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/examples/Venus.sol

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
/*
3+
* Copyright 2024, Polymer Labs
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
pragma solidity ^0.8.9;
19+
20+
import {ICrossL2Prover} from "../interfaces/ICrossL2Prover.sol";
21+
22+
/**
23+
* @title Venus
24+
* @notice Venus is a simple polymer proof api contract that proves an event happened on another chain.
25+
* @dev This contract is used for only testing and as an example for dapp developers on how to
26+
* integrate with polymer's proof api.
27+
*/
28+
contract Venus {
29+
ICrossL2Prover public immutable prover;
30+
31+
event SuccessfulReceipt(bytes receiptIndex, bytes receiptRLP);
32+
event SuccessfulEvent(uint256 eventIndex, address sender);
33+
34+
error invalidProverAddress();
35+
error invalidReceiptProof();
36+
error invalidEventProof();
37+
38+
constructor(ICrossL2Prover _prover) {
39+
if (address(_prover) == address(0)) {
40+
revert invalidProverAddress();
41+
}
42+
prover = _prover;
43+
}
44+
45+
/**
46+
* * @notice Validates a receipt proof using the ICrossL2Prover contract
47+
* * @param receiptIndex The index of the receipt
48+
* * @param receiptRLPEncodedBytes The RLP encoded receipt
49+
* * @param proof The proof to validate
50+
*/
51+
function receiveReceipt(bytes calldata receiptIndex, bytes calldata receiptRLPEncodedBytes, bytes calldata proof)
52+
external
53+
{
54+
if (!prover.validateReceipt(receiptIndex, receiptRLPEncodedBytes, proof)) {
55+
revert invalidReceiptProof();
56+
}
57+
58+
emit SuccessfulReceipt(receiptIndex, receiptRLPEncodedBytes);
59+
}
60+
61+
/**
62+
* * @notice Validates an event within a receipt proof using the ICrossL2Prover contract
63+
* * @param receiptIndex The index of the receipt
64+
* * @param receiptRLPEncodedBytes The RLP encoded receipt
65+
* * @param proof The proof to validate
66+
*/
67+
function receiveEvent(
68+
bytes calldata receiptIndex,
69+
bytes calldata receiptRLPEncodedBytes,
70+
uint256 logIndex,
71+
bytes calldata logBytes,
72+
bytes calldata proof
73+
) external {
74+
// First we validate receipt to have a more helpful error message if the receipt itself is incorrect
75+
76+
if (!prover.validateReceipt(receiptIndex, receiptRLPEncodedBytes, proof)) {
77+
revert invalidReceiptProof();
78+
}
79+
80+
if (!prover.validateEvent(receiptIndex, receiptRLPEncodedBytes, logIndex, logBytes, proof)) {
81+
revert invalidEventProof();
82+
}
83+
84+
emit SuccessfulEvent(logIndex, msg.sender);
85+
}
86+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@open-ibc/vibc-core-smart-contracts",
3-
"version": "4.0.14",
3+
"version": "4.0.15",
44
"main": "dist/index.js",
55
"bin": {
66
"verify-vibc-core-smart-contracts": "./dist/scripts/verify-contract-script.js",

src/evm/contracts/Venus.ts

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type {
5+
BaseContract,
6+
BigNumberish,
7+
BytesLike,
8+
FunctionFragment,
9+
Result,
10+
Interface,
11+
EventFragment,
12+
AddressLike,
13+
ContractRunner,
14+
ContractMethod,
15+
Listener,
16+
} from "ethers";
17+
import type {
18+
TypedContractEvent,
19+
TypedDeferredTopicFilter,
20+
TypedEventLog,
21+
TypedLogDescription,
22+
TypedListener,
23+
TypedContractMethod,
24+
} from "./common";
25+
26+
export interface VenusInterface extends Interface {
27+
getFunction(
28+
nameOrSignature: "prover" | "receiveEvent" | "receiveReceipt"
29+
): FunctionFragment;
30+
31+
getEvent(
32+
nameOrSignatureOrTopic: "SuccessfulEvent" | "SuccessfulReceipt"
33+
): EventFragment;
34+
35+
encodeFunctionData(functionFragment: "prover", values?: undefined): string;
36+
encodeFunctionData(
37+
functionFragment: "receiveEvent",
38+
values: [BytesLike, BytesLike, BigNumberish, BytesLike, BytesLike]
39+
): string;
40+
encodeFunctionData(
41+
functionFragment: "receiveReceipt",
42+
values: [BytesLike, BytesLike, BytesLike]
43+
): string;
44+
45+
decodeFunctionResult(functionFragment: "prover", data: BytesLike): Result;
46+
decodeFunctionResult(
47+
functionFragment: "receiveEvent",
48+
data: BytesLike
49+
): Result;
50+
decodeFunctionResult(
51+
functionFragment: "receiveReceipt",
52+
data: BytesLike
53+
): Result;
54+
}
55+
56+
export namespace SuccessfulEventEvent {
57+
export type InputTuple = [eventIndex: BigNumberish, sender: AddressLike];
58+
export type OutputTuple = [eventIndex: bigint, sender: string];
59+
export interface OutputObject {
60+
eventIndex: bigint;
61+
sender: string;
62+
}
63+
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
64+
export type Filter = TypedDeferredTopicFilter<Event>;
65+
export type Log = TypedEventLog<Event>;
66+
export type LogDescription = TypedLogDescription<Event>;
67+
}
68+
69+
export namespace SuccessfulReceiptEvent {
70+
export type InputTuple = [receiptIndex: BytesLike, receiptRLP: BytesLike];
71+
export type OutputTuple = [receiptIndex: string, receiptRLP: string];
72+
export interface OutputObject {
73+
receiptIndex: string;
74+
receiptRLP: string;
75+
}
76+
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
77+
export type Filter = TypedDeferredTopicFilter<Event>;
78+
export type Log = TypedEventLog<Event>;
79+
export type LogDescription = TypedLogDescription<Event>;
80+
}
81+
82+
export interface Venus extends BaseContract {
83+
connect(runner?: ContractRunner | null): Venus;
84+
waitForDeployment(): Promise<this>;
85+
86+
interface: VenusInterface;
87+
88+
queryFilter<TCEvent extends TypedContractEvent>(
89+
event: TCEvent,
90+
fromBlockOrBlockhash?: string | number | undefined,
91+
toBlock?: string | number | undefined
92+
): Promise<Array<TypedEventLog<TCEvent>>>;
93+
queryFilter<TCEvent extends TypedContractEvent>(
94+
filter: TypedDeferredTopicFilter<TCEvent>,
95+
fromBlockOrBlockhash?: string | number | undefined,
96+
toBlock?: string | number | undefined
97+
): Promise<Array<TypedEventLog<TCEvent>>>;
98+
99+
on<TCEvent extends TypedContractEvent>(
100+
event: TCEvent,
101+
listener: TypedListener<TCEvent>
102+
): Promise<this>;
103+
on<TCEvent extends TypedContractEvent>(
104+
filter: TypedDeferredTopicFilter<TCEvent>,
105+
listener: TypedListener<TCEvent>
106+
): Promise<this>;
107+
108+
once<TCEvent extends TypedContractEvent>(
109+
event: TCEvent,
110+
listener: TypedListener<TCEvent>
111+
): Promise<this>;
112+
once<TCEvent extends TypedContractEvent>(
113+
filter: TypedDeferredTopicFilter<TCEvent>,
114+
listener: TypedListener<TCEvent>
115+
): Promise<this>;
116+
117+
listeners<TCEvent extends TypedContractEvent>(
118+
event: TCEvent
119+
): Promise<Array<TypedListener<TCEvent>>>;
120+
listeners(eventName?: string): Promise<Array<Listener>>;
121+
removeAllListeners<TCEvent extends TypedContractEvent>(
122+
event?: TCEvent
123+
): Promise<this>;
124+
125+
prover: TypedContractMethod<[], [string], "view">;
126+
127+
receiveEvent: TypedContractMethod<
128+
[
129+
receiptIndex: BytesLike,
130+
receiptRLPEncodedBytes: BytesLike,
131+
logIndex: BigNumberish,
132+
logBytes: BytesLike,
133+
proof: BytesLike
134+
],
135+
[void],
136+
"nonpayable"
137+
>;
138+
139+
receiveReceipt: TypedContractMethod<
140+
[
141+
receiptIndex: BytesLike,
142+
receiptRLPEncodedBytes: BytesLike,
143+
proof: BytesLike
144+
],
145+
[void],
146+
"nonpayable"
147+
>;
148+
149+
getFunction<T extends ContractMethod = ContractMethod>(
150+
key: string | FunctionFragment
151+
): T;
152+
153+
getFunction(
154+
nameOrSignature: "prover"
155+
): TypedContractMethod<[], [string], "view">;
156+
getFunction(
157+
nameOrSignature: "receiveEvent"
158+
): TypedContractMethod<
159+
[
160+
receiptIndex: BytesLike,
161+
receiptRLPEncodedBytes: BytesLike,
162+
logIndex: BigNumberish,
163+
logBytes: BytesLike,
164+
proof: BytesLike
165+
],
166+
[void],
167+
"nonpayable"
168+
>;
169+
getFunction(
170+
nameOrSignature: "receiveReceipt"
171+
): TypedContractMethod<
172+
[
173+
receiptIndex: BytesLike,
174+
receiptRLPEncodedBytes: BytesLike,
175+
proof: BytesLike
176+
],
177+
[void],
178+
"nonpayable"
179+
>;
180+
181+
getEvent(
182+
key: "SuccessfulEvent"
183+
): TypedContractEvent<
184+
SuccessfulEventEvent.InputTuple,
185+
SuccessfulEventEvent.OutputTuple,
186+
SuccessfulEventEvent.OutputObject
187+
>;
188+
getEvent(
189+
key: "SuccessfulReceipt"
190+
): TypedContractEvent<
191+
SuccessfulReceiptEvent.InputTuple,
192+
SuccessfulReceiptEvent.OutputTuple,
193+
SuccessfulReceiptEvent.OutputObject
194+
>;
195+
196+
filters: {
197+
"SuccessfulEvent(uint256,address)": TypedContractEvent<
198+
SuccessfulEventEvent.InputTuple,
199+
SuccessfulEventEvent.OutputTuple,
200+
SuccessfulEventEvent.OutputObject
201+
>;
202+
SuccessfulEvent: TypedContractEvent<
203+
SuccessfulEventEvent.InputTuple,
204+
SuccessfulEventEvent.OutputTuple,
205+
SuccessfulEventEvent.OutputObject
206+
>;
207+
208+
"SuccessfulReceipt(bytes,bytes)": TypedContractEvent<
209+
SuccessfulReceiptEvent.InputTuple,
210+
SuccessfulReceiptEvent.OutputTuple,
211+
SuccessfulReceiptEvent.OutputObject
212+
>;
213+
SuccessfulReceipt: TypedContractEvent<
214+
SuccessfulReceiptEvent.InputTuple,
215+
SuccessfulReceiptEvent.OutputTuple,
216+
SuccessfulReceiptEvent.OutputObject
217+
>;
218+
};
219+
}

0 commit comments

Comments
 (0)