diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dc0453..048a1a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Format + working-directory: ./server run: cargo fmt --all -- --check clippy: @@ -15,8 +16,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: Clippy + working-directory: ./server run: cargo clippy --fix - name: Check for diff + working-directory: ./server run: git diff --exit-code build: @@ -24,6 +27,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build + working-directory: ./server run: cargo build --verbose test: @@ -34,4 +38,5 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Run tests + working-directory: ./server run: cargo test --workspace --verbose diff --git a/README.md b/README.md index 33c636f..3388146 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,3 @@ -## Run server +## Documentation -`cargo run` - -## Get server's public key - -`GET http://0.0.0.0:3000/info` - -## Get random numbers - -```js -const response = await fetch("http://0.0.0.0:3000/stark_vrf", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ seed: ["0x5733e5c2c8030bc06888747525b1a1f0242ca770c9387b58a4529df0ca55499"] }), -}); -const json = await response.json(); -``` - -which will return: - -```js -{ - "result": { - "gamma_x": "0x6ac32f9b3c0bef88e4e1ba77d2f77fa603bbd4b42cca6405c5bdf7a16821d75", - "gamma_y": "0x50e3875635d84cb0038dbccb309b1134e101aee38c02001e456d5988b39fd43", - "c": "0x111fd321fb9b48c651a871fcfeea71a0f521ba04fe54f81caf2f407cba0979f", - "s": "0x437d280a8eb8e1e57c291af359738118c5b64b00ff5bd209d86ef83b051a2c6", - "sqrt_ratio": "0xa99242633a4f2a7b31c4c7d3bee93dad3bd946a68cfac753dbd4bbd837d8c0", - "rnd": "0x41c6b570b6720f205da6ef692021fe3625bbbab1ef5ea0ecea470e2d93b7982" - } -} -``` - -## Verify proof in Cairo - -See https://github.com/dojoengine/stark-vrf +[Cartridge VRF Documentation](https://docs.cartridge.gg/vrf/overview) \ No newline at end of file diff --git a/contracts/Scarb.lock b/Scarb.lock similarity index 99% rename from contracts/Scarb.lock rename to Scarb.lock index 00129df..386338f 100644 --- a/contracts/Scarb.lock +++ b/Scarb.lock @@ -1,6 +1,17 @@ # Code generated by scarb DO NOT EDIT. version = 1 +[[package]] +name = "cartridge_vrf" +version = "0.1.0" +dependencies = [ + "openzeppelin", + "openzeppelin_testing", + "openzeppelin_utils", + "snforge_std", + "stark_vrf", +] + [[package]] name = "openzeppelin" version = "0.15.0-rc.0" @@ -104,14 +115,3 @@ source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.26.0#50e name = "stark_vrf" version = "0.1.0" source = "git+https://github.com/dojoengine/stark-vrf.git#96d6d2a88b1ef46c4a285d0ccc334237205edae3" - -[[package]] -name = "vrf_contracts" -version = "0.1.0" -dependencies = [ - "openzeppelin", - "openzeppelin_testing", - "openzeppelin_utils", - "snforge_std", - "stark_vrf", -] diff --git a/Scarb.toml b/Scarb.toml index 41f8a96..47ba370 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,12 +1,22 @@ -[workspace] -members = ["contracts"] - -[workspace.package] +[package] +name = "cartridge_vrf" version = "0.1.0" +edition = "2023_10" -[workspace.dependencies] +[dependencies] starknet = "2.7.0" stark_vrf = { git = "https://github.com/dojoengine/stark-vrf.git" } openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" } snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" } -# Scripts are not supported for virtual workspaces. + +[dev-dependencies] +openzeppelin_testing = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" } +openzeppelin_utils = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" } + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" + +[lib] + +[script] +test = "snforge test" diff --git a/contracts/README.md b/contracts/README.md deleted file mode 100644 index cefe924..0000000 --- a/contracts/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# VRF for Cartridge Controller with paymaster - -Randomness is requested by calling `vrf_provider.request_random` with: -- caller : the contract that will call consume_random -- source : one of this 2 options : - -**Source::Nonce(address)** : -- each request_random will generate a unique seed using a nonce by address (nonce is increased after each call) -- (its recommanded to use wallet address to avoid nonce collisions) - -**Source::Salt(salt)** : -- you have to provider you own salt -- using same salt will generate same seed = same randomness - - -## How it works - -caller send multicall : - -``` -[ - vrf_provider.request_random(game_contract.address, Source::Nonce(wallet_address)), - game_contract.you_function_consuming_randomness(...params) -] -``` - -Cartridge backend receive the tx, -retrieve seed using vrf_provider.get_next_seed( caller ), -compute proof for seed -and inject calls to sandwitch caller in a multicall : - -``` -[ - vrf_provider.submit_random( seed, proof), - controller.outside_execution([ - vrf_provider.request_random(game_contract.address, Source::Nonce(wallet_address)), - game_contract.you_function_consuming_randomness(...params) - ]) - vrf_provider.assert_consumed( seed ), -] -``` - -# Notes - -- caller must be a Cartridge Controller -- Randomness must be consume -- Randomness can only be consumed once -- Tx (submit_random / user calls / assert_consumed) is executed atomically by Cartridge backend -- Sumbitted randomness only last for the tx duration -- It's not possible to request_random in a tx and consume_random in another tx -- User cannot probe randomness diff --git a/contracts/Scarb.toml b/contracts/Scarb.toml deleted file mode 100644 index 560fc9b..0000000 --- a/contracts/Scarb.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "cartridge_vrf" -version = "0.1.0" -edition = "2023_10" - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html - -[dependencies] -starknet.workspace = true -stark_vrf.workspace = true -openzeppelin.workspace = true -snforge_std.workspace = true - -[dev-dependencies] -openzeppelin_testing = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" } -openzeppelin_utils = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" } - -[[target.starknet-contract]] -allowed-libfuncs-list.name = "experimental" - -[lib] - -[script] -test = "snforge test" diff --git a/contracts/dojo/buildVrfCalls.ts b/contracts/dojo/buildVrfCalls.ts deleted file mode 100644 index b42168b..0000000 --- a/contracts/dojo/buildVrfCalls.ts +++ /dev/null @@ -1,67 +0,0 @@ - -import { StarkVRF } from "stark-vrf-wasm"; -import { AccountInterface, Call, CallData} from "starknet"; - - -export const buildVrfCalls = async ({ - account, - call, - vrfProviderAddress, - vrfProviderSecret, - }: { - account: AccountInterface; - call: Call; - vrfProviderAddress: string; - vrfProviderSecret?: string; - }): Promise => { - - const [seed] = await account.callContract({ - contractAddress: vrfProviderAddress, - entrypoint: "get_next_seed", - calldata: [account.address], - }); - - const requestRandomCall: Call = { - contractAddress: vrfProviderAddress, - entrypoint: "request_random", - calldata: [], - }; - - let submitRandomCall: Call|undefined = undefined; - let assertConsumedCall: Call|undefined = undefined; - - if (vrfProviderSecret) { - const vrf = StarkVRF.new(vrfProviderSecret); - const proof = vrf.prove(vrfProviderSecret, seed); - const sqrt_ratio_hint = vrf.hashToSqrtRatioHint(seed); - - // fn submit_random( seed: felt252, proof: Proof); - submitRandomCall = { - contractAddress: vrfProviderAddress, - entrypoint: "submit_random", - calldata: CallData.compile([seed, proof, sqrt_ratio_hint]), - }; - - // fn assert_consumed( seed: felt252,); - assertConsumedCall = { - contractAddress: vrfProviderAddress, - entrypoint: "assert_consumed", - calldata: [seed], - }; - } - - let calls = []; - if (vrfProviderSecret) { - calls.push(submitRandomCall as Call); - } - - calls.push(requestRandomCall); - calls.push(call); - - if (vrfProviderSecret) { - calls.push(assertConsumedCall as Call); - } - - console.log("calls", calls); - return calls; - }; \ No newline at end of file diff --git a/contracts/dojo/vrf_consumer_template.cairo b/contracts/dojo/vrf_consumer_template.cairo deleted file mode 100644 index 1f97b48..0000000 --- a/contracts/dojo/vrf_consumer_template.cairo +++ /dev/null @@ -1,52 +0,0 @@ -#[starknet::interface] -trait IVrfConsumerTemplate { - fn dice(ref self: T); -} - -#[dojo::contract] -mod consumer_template { - use starknet::ContractAddress; - use starknet::get_caller_address; - - use cartridge_vrf::vrf_consumer::vrf_consumer_component::VrfConsumerComponent; - use cartridge_vrf::vrf_provider::vrf_provider_component::Source; - - component!(path: VrfConsumerComponent, storage: vrf_consumer, event: VrfConsumerEvent); - - #[abi(embed_v0)] - impl VrfConsumerImpl = VrfConsumerComponent::VrfConsumerImpl; - - impl VrfConsumerInternalImpl = VrfConsumerComponent::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - vrf_consumer: VrfConsumerComponent::Storage, - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - VrfConsumerEvent: VrfConsumerComponent::Event, - } - - #[abi(embed_v0)] - fn dojo_init(ref self: ContractState, vrf_provider: ContractAddress) { - self.vrf_consumer.initializer(vrf_provider); - } - - #[abi(embed_v0)] - impl VrfConsumerTemplateImpl of super::IVrfConsumerTemplate { - fn dice(ref self: ContractState) { - let player_id = get_caller_address(); - let random: u256 = self.vrf_consumer.consume_random(Source::Nonce(player_id)).into(); - let value: u8 = (random % 6).try_into().unwrap() + 1; - // do the right things - } - } - - #[generate_trait] - impl InternalImpl of InternalTrait {} -} - diff --git a/dojo/buildVrfCalls.ts b/dojo/buildVrfCalls.ts new file mode 100644 index 0000000..d0ad756 --- /dev/null +++ b/dojo/buildVrfCalls.ts @@ -0,0 +1,80 @@ + +import { AccountInterface, BlockTag, Call, CallData, hash, selector } from "starknet"; + +enum Source { + Nonce = 0x0, + Salt = 0x1, +} + +export const buildVrfCalls = async ({ + account, + call, + vrfProviderAddress, + vrfProviderSecret, +}: { + account: AccountInterface; + call: Call; + vrfProviderAddress: string; + vrfProviderSecret?: string; +}): Promise => { + // fn request_random(caller: ContractAddress, source: Source) -> felt252; + const requestRandomCall: Call = { + contractAddress: vrfProviderAddress, + entrypoint: "request_random", + calldata: [call.contractAddress, Source.Nonce, account.address], + }; + + let submitRandomCall = undefined; + let assertConsumedCall = undefined; + + if (vrfProviderSecret) { + const chainId = await account.getChainId(); + + const nonceStorageSlot = hash.computePedersenHash( + selector.getSelectorFromName("VrfProvider_nonces"), + account.address, + ); + + const nonce = await account.getStorageAt(vrfProviderAddress, nonceStorageSlot, BlockTag.pending); + const seed = hash.computePoseidonHashOnElements([nonce, call.contractAddress, chainId]); + console.log(chainId); + console.log(nonceStorageSlot); + console.log(nonce); + console.log(seed); + + // const vrf = StarkVRF.new(vrfProviderSecret); + + const vrf = (await import("stark-vrf-wasm")).StarkVRF.new(vrfProviderSecret); + const proof = vrf.prove(vrfProviderSecret, seed); + const sqrt_ratio_hint = vrf.hashToSqrtRatioHint(seed); + + // fn submit_random( seed: felt252, proof: Proof); + submitRandomCall = { + contractAddress: vrfProviderAddress, + entrypoint: "submit_random", + calldata: CallData.compile([seed, proof, sqrt_ratio_hint]), + }; + + // fn assert_consumed( seed: felt252,); + assertConsumedCall = { + contractAddress: vrfProviderAddress, + entrypoint: "assert_consumed", + calldata: [seed], + }; + } + + let calls = []; + if (vrfProviderSecret) { + calls.push(submitRandomCall as Call); + } + + calls.push(requestRandomCall); + calls.push(call); + + if (vrfProviderSecret) { + calls.push(assertConsumedCall as Call); + } + + console.log("calls", calls); + return calls; +}; diff --git a/contracts/dojo/vrf_provider_mock.cairo b/dojo/vrf_provider_mock.cairo similarity index 94% rename from contracts/dojo/vrf_provider_mock.cairo rename to dojo/vrf_provider_mock.cairo index aad5086..fde3850 100644 --- a/contracts/dojo/vrf_provider_mock.cairo +++ b/dojo/vrf_provider_mock.cairo @@ -5,7 +5,7 @@ mod vrf_provider_mock { use openzeppelin::access::ownable::OwnableComponent; use cartridge_vrf::vrf_provider::vrf_provider_component::VrfProviderComponent; - use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey; + use cartridge_vrf::PublicKey; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: VrfProviderComponent, storage: vrf_provider, event: VrfProviderEvent); diff --git a/.dockerignore b/server/.dockerignore similarity index 100% rename from .dockerignore rename to server/.dockerignore diff --git a/Cargo.lock b/server/Cargo.lock similarity index 100% rename from Cargo.lock rename to server/Cargo.lock diff --git a/Cargo.toml b/server/Cargo.toml similarity index 100% rename from Cargo.toml rename to server/Cargo.toml diff --git a/Dockerfile b/server/Dockerfile similarity index 100% rename from Dockerfile rename to server/Dockerfile diff --git a/Oracle.lock b/server/Oracle.lock similarity index 100% rename from Oracle.lock rename to server/Oracle.lock diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..33c636f --- /dev/null +++ b/server/README.md @@ -0,0 +1,39 @@ +## Run server + +`cargo run` + +## Get server's public key + +`GET http://0.0.0.0:3000/info` + +## Get random numbers + +```js +const response = await fetch("http://0.0.0.0:3000/stark_vrf", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ seed: ["0x5733e5c2c8030bc06888747525b1a1f0242ca770c9387b58a4529df0ca55499"] }), +}); +const json = await response.json(); +``` + +which will return: + +```js +{ + "result": { + "gamma_x": "0x6ac32f9b3c0bef88e4e1ba77d2f77fa603bbd4b42cca6405c5bdf7a16821d75", + "gamma_y": "0x50e3875635d84cb0038dbccb309b1134e101aee38c02001e456d5988b39fd43", + "c": "0x111fd321fb9b48c651a871fcfeea71a0f521ba04fe54f81caf2f407cba0979f", + "s": "0x437d280a8eb8e1e57c291af359738118c5b64b00ff5bd209d86ef83b051a2c6", + "sqrt_ratio": "0xa99242633a4f2a7b31c4c7d3bee93dad3bd946a68cfac753dbd4bbd837d8c0", + "rnd": "0x41c6b570b6720f205da6ef692021fe3625bbbab1ef5ea0ecea470e2d93b7982" + } +} +``` + +## Verify proof in Cairo + +See https://github.com/dojoengine/stark-vrf diff --git a/src/main.rs b/server/src/main.rs similarity index 100% rename from src/main.rs rename to server/src/main.rs diff --git a/src/oracle.rs b/server/src/oracle.rs similarity index 100% rename from src/oracle.rs rename to server/src/oracle.rs diff --git a/contracts/src/lib.cairo b/src/lib.cairo similarity index 89% rename from contracts/src/lib.cairo rename to src/lib.cairo index 4a6ba13..ca862f5 100644 --- a/contracts/src/lib.cairo +++ b/src/lib.cairo @@ -5,7 +5,10 @@ pub mod vrf_provider { pub mod vrf_consumer { pub mod vrf_consumer_component; - pub mod vrf_consumer_example; +} + +pub mod mocks { + pub mod vrf_consumer_mock; } pub use vrf_provider::vrf_provider_component::{ diff --git a/contracts/src/vrf_consumer/vrf_consumer_example.cairo b/src/mocks/vrf_consumer_mock.cairo similarity index 88% rename from contracts/src/vrf_consumer/vrf_consumer_example.cairo rename to src/mocks/vrf_consumer_mock.cairo index a0ce4b6..a94d9cd 100644 --- a/contracts/src/vrf_consumer/vrf_consumer_example.cairo +++ b/src/mocks/vrf_consumer_mock.cairo @@ -1,8 +1,6 @@ -// SPDX-License-Identifier: MIT -// Compatible with OpenZeppelin Contracts for Cairo ^0.16.0 #[starknet::interface] -trait IVrfConsumerExample { +trait IVrfConsumerMock { fn dice(ref self: TContractState) -> u8; fn dice_with_salt(ref self: TContractState) -> u8; @@ -24,7 +22,7 @@ mod VrfConsumer { use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl}; use cartridge_vrf::vrf_consumer::vrf_consumer_component::{VrfConsumerComponent}; - use cartridge_vrf::vrf_provider::vrf_provider_component::Source; + use cartridge_vrf::Source; component!(path: VrfConsumerComponent, storage: vrf_consumer, event: VrfConsumerEvent); @@ -52,7 +50,7 @@ mod VrfConsumer { } #[abi(embed_v0)] - impl ConsumerImpl of super::IVrfConsumerExample { + impl ConsumerImpl of super::IVrfConsumerMock { // throw dice fn dice(ref self: ContractState) -> u8 { let player_id = get_caller_address(); @@ -69,7 +67,7 @@ mod VrfConsumer { fn not_consuming(ref self: ContractState) { let _player_id = get_caller_address(); - // do the nothing + // do the nothing } fn set_vrf_provider(ref self: ContractState, new_vrf_provider: ContractAddress) { diff --git a/contracts/src/tests/common.cairo b/src/tests/common.cairo similarity index 84% rename from contracts/src/tests/common.cairo rename to src/tests/common.cairo index 4346445..8b6f2bb 100644 --- a/contracts/src/tests/common.cairo +++ b/src/tests/common.cairo @@ -10,9 +10,9 @@ use cartridge_vrf::vrf_provider::vrf_provider_component::{ IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, }; -use cartridge_vrf::vrf_consumer::vrf_consumer_example::{ - VrfConsumer, IVrfConsumerExample, IVrfConsumerExampleDispatcher, - IVrfConsumerExampleDispatcherTrait +use cartridge_vrf::mocks::vrf_consumer_mock::{ + VrfConsumer, IVrfConsumerMock, IVrfConsumerMockDispatcher, + IVrfConsumerMockDispatcherTrait }; pub fn PROVIDER() -> ContractAddress { @@ -34,8 +34,8 @@ pub fn PLAYER1() -> ContractAddress { #[derive(Drop, Copy, Clone)] pub struct SetupResult { provider: IVrfProviderDispatcher, - consumer1: IVrfConsumerExampleDispatcher, - consumer2: IVrfConsumerExampleDispatcher, + consumer1: IVrfConsumerMockDispatcher, + consumer2: IVrfConsumerMockDispatcher, } // lauch vrf-server : cargo run -r -- -s 420 @@ -65,8 +65,8 @@ pub fn setup() -> SetupResult { SetupResult { provider: IVrfProviderDispatcher { contract_address: PROVIDER() }, - consumer1: IVrfConsumerExampleDispatcher { contract_address: CONSUMER1() }, - consumer2: IVrfConsumerExampleDispatcher { contract_address: CONSUMER2() }, + consumer1: IVrfConsumerMockDispatcher { contract_address: CONSUMER1() }, + consumer2: IVrfConsumerMockDispatcher { contract_address: CONSUMER2() }, } } diff --git a/contracts/src/tests/test_dice.cairo b/src/tests/test_dice.cairo similarity index 91% rename from contracts/src/tests/test_dice.cairo rename to src/tests/test_dice.cairo index 233e3ff..526fd9e 100644 --- a/contracts/src/tests/test_dice.cairo +++ b/src/tests/test_dice.cairo @@ -9,13 +9,13 @@ use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl}; use openzeppelin_utils::serde::SerializedAppend; use cartridge_vrf::vrf_provider::vrf_provider::VrfProvider; -use cartridge_vrf::vrf_provider::vrf_provider_component::{ +use cartridge_vrf::{ IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, Source }; -use cartridge_vrf::vrf_consumer::vrf_consumer_example::{ - VrfConsumer, IVrfConsumerExample, IVrfConsumerExampleDispatcher, - IVrfConsumerExampleDispatcherTrait +use cartridge_vrf::mocks::vrf_consumer_mock::{ + VrfConsumer, IVrfConsumerMock, IVrfConsumerMockDispatcher, + IVrfConsumerMockDispatcherTrait }; use super::common::{setup, submit_random, SetupResult, CONSUMER1, CONSUMER2, PLAYER1}; @@ -25,7 +25,9 @@ use super::common::{setup, submit_random, SetupResult, CONSUMER1, CONSUMER2, PLA const SEED: felt252 = 0x334b8c0ea68406b183b5affd81ce11bec1a0807d3fd68a54ee75ec148053b09; -// curl -X POST -H "Content-Type: application/json" -d '{"seed": ["0x334b8c0ea68406b183b5affd81ce11bec1a0807d3fd68a54ee75ec148053b09"]}' http://0.0.0.0:3000/stark_vrf +// curl -X POST -H "Content-Type: application/json" -d '{"seed": +// ["0x334b8c0ea68406b183b5affd81ce11bec1a0807d3fd68a54ee75ec148053b09"]}' +// http://0.0.0.0:3000/stark_vrf pub fn proof() -> Proof { Proof { gamma: Point { @@ -40,7 +42,9 @@ pub fn proof() -> Proof { const SEED_FROM_SALT: felt252 = 0x767EBFD1241683397A6CB06FDE012811BB27FD6E768D7A4BB8670ED10DF95C0; -// curl -X POST -H "Content-Type: application/json" -d '{"seed": ["0x767EBFD1241683397A6CB06FDE012811BB27FD6E768D7A4BB8670ED10DF95C0"]}' http://0.0.0.0:3000/stark_vrf +// curl -X POST -H "Content-Type: application/json" -d '{"seed": +// ["0x767EBFD1241683397A6CB06FDE012811BB27FD6E768D7A4BB8670ED10DF95C0"]}' +// http://0.0.0.0:3000/stark_vrf pub fn proof_from_salt() -> Proof { Proof { gamma: Point { diff --git a/contracts/src/vrf_consumer/vrf_consumer_component.cairo b/src/vrf_consumer/vrf_consumer_component.cairo similarity index 93% rename from contracts/src/vrf_consumer/vrf_consumer_component.cairo rename to src/vrf_consumer/vrf_consumer_component.cairo index 578c652..ddabab3 100644 --- a/contracts/src/vrf_consumer/vrf_consumer_component.cairo +++ b/src/vrf_consumer/vrf_consumer_component.cairo @@ -1,6 +1,6 @@ use starknet::ContractAddress; use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl}; -use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey; +use cartridge_vrf::PublicKey; #[starknet::interface] trait IVrfConsumer { @@ -18,9 +18,8 @@ pub mod VrfConsumerComponent { use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl}; - use cartridge_vrf::vrf_provider::vrf_provider_component::{ - IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, - PublicKeyIntoPoint, Source + use cartridge_vrf::{ + IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, Source }; #[storage] diff --git a/contracts/src/vrf_provider/vrf_provider.cairo b/src/vrf_provider/vrf_provider.cairo similarity index 96% rename from contracts/src/vrf_provider/vrf_provider.cairo rename to src/vrf_provider/vrf_provider.cairo index be932ab..8c5bd37 100644 --- a/contracts/src/vrf_provider/vrf_provider.cairo +++ b/src/vrf_provider/vrf_provider.cairo @@ -9,7 +9,7 @@ mod VrfProvider { use openzeppelin::upgrades::interface::IUpgradeable; use cartridge_vrf::vrf_provider::vrf_provider_component::VrfProviderComponent; - use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey; + use cartridge_vrf::PublicKey; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); diff --git a/contracts/src/vrf_provider/vrf_provider_component.cairo b/src/vrf_provider/vrf_provider_component.cairo similarity index 98% rename from contracts/src/vrf_provider/vrf_provider_component.cairo rename to src/vrf_provider/vrf_provider_component.cairo index a770dd0..e5f15f4 100644 --- a/contracts/src/vrf_provider/vrf_provider_component.cairo +++ b/src/vrf_provider/vrf_provider_component.cairo @@ -78,7 +78,6 @@ pub mod VrfProviderComponent { pub const PUBKEY_ZERO: felt252 = 'VrfProvider: pubkey is zero'; pub const INVALID_PROOF: felt252 = 'VrfProvider: invalid proof'; pub const NOT_FULFILLED: felt252 = 'VrfProvider: not fulfilled'; - pub const SEED_MISMATCH: felt252 = 'VrfProvider: seed mismatch'; pub const NOT_CONSUMED: felt252 = 'VrfProvider: not consumed'; } @@ -120,7 +119,7 @@ pub mod VrfProviderComponent { poseidon_hash_span(array![salt, caller.into(), tx_info.chain_id].span()) }, }; - + // Always return 0 during fee estimation to avoid leaking vrf info. if tx_info.max_fee == 0 { // simulate consumed