-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
>; | ||
}; | ||
} |
Oops, something went wrong.