From e3d173596f7bb0c0d3af722fd5a627bc3a983f3b Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Mon, 27 Nov 2023 10:28:55 -0800 Subject: [PATCH] add uri to fortuna --- fortuna/Cargo.lock | 2 +- fortuna/src/abi.json | 646 +++++++++++++---------- fortuna/src/command/register_provider.rs | 1 + fortuna/src/config/register_provider.rs | 6 + 4 files changed, 368 insertions(+), 287 deletions(-) diff --git a/fortuna/Cargo.lock b/fortuna/Cargo.lock index ef6ae7aa9c..6788f703f2 100644 --- a/fortuna/Cargo.lock +++ b/fortuna/Cargo.lock @@ -1486,7 +1486,7 @@ dependencies = [ [[package]] name = "fortuna" -version = "1.1.0" +version = "2.0.0" dependencies = [ "anyhow", "axum", diff --git a/fortuna/src/abi.json b/fortuna/src/abi.json index 13b4aa9b38..86175d0366 100644 --- a/fortuna/src/abi.json +++ b/fortuna/src/abi.json @@ -1,482 +1,556 @@ [ { - "anonymous": false, + "type": "constructor", "inputs": [ { - "components": [ - { - "internalType": "uint256", - "name": "feeInWei", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "accruedFeesInWei", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "originalCommitment", - "type": "bytes32" - }, - { - "internalType": "uint64", - "name": "originalCommitmentSequenceNumber", - "type": "uint64" - }, - { - "internalType": "bytes", - "name": "commitmentMetadata", - "type": "bytes" - }, - { - "internalType": "uint64", - "name": "endSequenceNumber", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "sequenceNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "currentCommitment", - "type": "bytes32" - }, - { - "internalType": "uint64", - "name": "currentCommitmentSequenceNumber", - "type": "uint64" - } - ], - "indexed": false, - "internalType": "struct EntropyStructs.ProviderInfo", - "name": "provider", - "type": "tuple" - } - ], - "name": "Registered", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "provider", - "type": "address" - }, - { - "internalType": "uint64", - "name": "sequenceNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "userCommitment", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "providerCommitment", - "type": "bytes32" - }, - { - "internalType": "uint64", - "name": "providerCommitmentSequenceNumber", - "type": "uint64" - }, - { - "internalType": "uint256", - "name": "blockNumber", - "type": "uint256" - } - ], - "indexed": false, - "internalType": "struct EntropyStructs.Request", - "name": "request", - "type": "tuple" - } - ], - "name": "Requested", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "provider", - "type": "address" - }, - { - "internalType": "uint64", - "name": "sequenceNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "userCommitment", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "providerCommitment", - "type": "bytes32" - }, - { - "internalType": "uint64", - "name": "providerCommitmentSequenceNumber", - "type": "uint64" - }, - { - "internalType": "uint256", - "name": "blockNumber", - "type": "uint256" - } - ], - "indexed": false, - "internalType": "struct EntropyStructs.Request", - "name": "request", - "type": "tuple" + "name": "pythFeeInWei", + "type": "uint256", + "internalType": "uint256" }, { - "indexed": false, - "internalType": "bytes32", - "name": "userRevelation", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "providerRevelation", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "blockHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "randomNumber", - "type": "bytes32" + "name": "defaultProvider", + "type": "address", + "internalType": "address" } ], - "name": "Revealed", - "type": "event" + "stateMutability": "nonpayable" }, { + "type": "function", + "name": "combineRandomValues", "inputs": [ { - "internalType": "bytes32", "name": "userRandomness", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bytes32", "name": "providerRandomness", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bytes32", "name": "blockHash", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "name": "combineRandomValues", "outputs": [ { - "internalType": "bytes32", "name": "combinedRandomness", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "stateMutability": "pure", - "type": "function" + "stateMutability": "pure" }, { + "type": "function", + "name": "constructUserCommitment", "inputs": [ { - "internalType": "bytes32", "name": "userRandomness", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "name": "constructUserCommitment", "outputs": [ { - "internalType": "bytes32", "name": "userCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "stateMutability": "pure", - "type": "function" + "stateMutability": "pure" }, { - "inputs": [], + "type": "function", "name": "getAccruedPythFees", + "inputs": [], "outputs": [ { - "internalType": "uint256", "name": "accruedPythFeesInWei", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" } ], - "stateMutability": "view", - "type": "function" + "stateMutability": "view" }, { - "inputs": [ + "type": "function", + "name": "getDefaultProvider", + "inputs": [], + "outputs": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" } ], + "stateMutability": "view" + }, + { + "type": "function", "name": "getFee", + "inputs": [ + { + "name": "provider", + "type": "address", + "internalType": "address" + } + ], "outputs": [ { - "internalType": "uint256", "name": "feeAmount", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" } ], - "stateMutability": "view", - "type": "function" + "stateMutability": "view" }, { + "type": "function", + "name": "getProviderInfo", "inputs": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" } ], - "name": "getProviderInfo", "outputs": [ { + "name": "info", + "type": "tuple", + "internalType": "struct EntropyStructs.ProviderInfo", "components": [ { - "internalType": "uint256", "name": "feeInWei", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" }, { - "internalType": "uint256", "name": "accruedFeesInWei", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" }, { - "internalType": "bytes32", "name": "originalCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "uint64", "name": "originalCommitmentSequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "bytes", "name": "commitmentMetadata", - "type": "bytes" + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "uri", + "type": "bytes", + "internalType": "bytes" }, { - "internalType": "uint64", "name": "endSequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "uint64", "name": "sequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "bytes32", "name": "currentCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "uint64", "name": "currentCommitmentSequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" } - ], - "internalType": "struct EntropyStructs.ProviderInfo", - "name": "info", - "type": "tuple" + ] } ], - "stateMutability": "view", - "type": "function" + "stateMutability": "view" }, { + "type": "function", + "name": "getRequest", "inputs": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" }, { - "internalType": "uint64", "name": "sequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" } ], - "name": "getRequest", "outputs": [ { + "name": "req", + "type": "tuple", + "internalType": "struct EntropyStructs.Request", "components": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" }, { - "internalType": "uint64", "name": "sequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "bytes32", "name": "userCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bytes32", "name": "providerCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "uint64", "name": "providerCommitmentSequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "uint256", "name": "blockNumber", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" } - ], - "internalType": "struct EntropyStructs.Request", - "name": "req", - "type": "tuple" + ] } ], - "stateMutability": "view", - "type": "function" + "stateMutability": "view" }, { + "type": "function", + "name": "register", "inputs": [ { - "internalType": "uint256", "name": "feeInWei", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" }, { - "internalType": "bytes32", "name": "commitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bytes", "name": "commitmentMetadata", - "type": "bytes" + "type": "bytes", + "internalType": "bytes" }, { - "internalType": "uint64", "name": "chainLength", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "uri", + "type": "bytes", + "internalType": "bytes" } ], - "name": "register", "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + "stateMutability": "nonpayable" }, { + "type": "function", + "name": "request", "inputs": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" }, { - "internalType": "bytes32", "name": "userCommitment", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bool", "name": "useBlockHash", - "type": "bool" + "type": "bool", + "internalType": "bool" } ], - "name": "request", "outputs": [ { - "internalType": "uint64", "name": "assignedSequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" } ], - "stateMutability": "payable", - "type": "function" + "stateMutability": "payable" }, { + "type": "function", + "name": "reveal", "inputs": [ { - "internalType": "address", "name": "provider", - "type": "address" + "type": "address", + "internalType": "address" }, { - "internalType": "uint64", "name": "sequenceNumber", - "type": "uint64" + "type": "uint64", + "internalType": "uint64" }, { - "internalType": "bytes32", "name": "userRandomness", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" }, { - "internalType": "bytes32", "name": "providerRevelation", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "name": "reveal", "outputs": [ { - "internalType": "bytes32", "name": "randomNumber", - "type": "bytes32" + "type": "bytes32", + "internalType": "bytes32" } ], - "stateMutability": "nonpayable", - "type": "function" + "stateMutability": "nonpayable" }, { + "type": "function", + "name": "withdraw", "inputs": [ { - "internalType": "uint256", "name": "amount", - "type": "uint256" + "type": "uint256", + "internalType": "uint256" } ], - "name": "withdraw", "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "Registered", + "inputs": [ + { + "name": "provider", + "type": "tuple", + "indexed": false, + "internalType": "struct EntropyStructs.ProviderInfo", + "components": [ + { + "name": "feeInWei", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "accruedFeesInWei", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "originalCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "originalCommitmentSequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "commitmentMetadata", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "uri", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "endSequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "sequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "currentCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "currentCommitmentSequenceNumber", + "type": "uint64", + "internalType": "uint64" + } + ] + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Requested", + "inputs": [ + { + "name": "request", + "type": "tuple", + "indexed": false, + "internalType": "struct EntropyStructs.Request", + "components": [ + { + "name": "provider", + "type": "address", + "internalType": "address" + }, + { + "name": "sequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "userCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "providerCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "providerCommitmentSequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "blockNumber", + "type": "uint256", + "internalType": "uint256" + } + ] + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Revealed", + "inputs": [ + { + "name": "request", + "type": "tuple", + "indexed": false, + "internalType": "struct EntropyStructs.Request", + "components": [ + { + "name": "provider", + "type": "address", + "internalType": "address" + }, + { + "name": "sequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "userCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "providerCommitment", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "providerCommitmentSequenceNumber", + "type": "uint64", + "internalType": "uint64" + }, + { + "name": "blockNumber", + "type": "uint256", + "internalType": "uint256" + } + ] + }, + { + "name": "userRevelation", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + }, + { + "name": "providerRevelation", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + }, + { + "name": "blockHash", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + }, + { + "name": "randomNumber", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "AssertionFailure", + "inputs": [] + }, + { + "type": "error", + "name": "IncorrectProviderRevelation", + "inputs": [] + }, + { + "type": "error", + "name": "IncorrectUserRevelation", + "inputs": [] + }, + { + "type": "error", + "name": "InsufficientFee", + "inputs": [] + }, + { + "type": "error", + "name": "NoSuchProvider", + "inputs": [] + }, + { + "type": "error", + "name": "OutOfRandomness", + "inputs": [] } ] diff --git a/fortuna/src/command/register_provider.rs b/fortuna/src/command/register_provider.rs index 240ef25a12..fe7127fde5 100644 --- a/fortuna/src/command/register_provider.rs +++ b/fortuna/src/command/register_provider.rs @@ -55,6 +55,7 @@ pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> { commitment, bincode::serialize(&commitment_metadata)?.into(), commitment_length, + bincode::serialize(&opts.uri)?.into(), ) .send() .await? diff --git a/fortuna/src/config/register_provider.rs b/fortuna/src/config/register_provider.rs index 9fa3ed37aa..c6281cdc61 100644 --- a/fortuna/src/config/register_provider.rs +++ b/fortuna/src/config/register_provider.rs @@ -36,4 +36,10 @@ pub struct RegisterProviderOptions { #[arg(long = "pyth-contract-fee")] #[arg(default_value = "100")] pub fee: U256, + + /// The URI where clients can retrieve random values from this provider, + /// i.e., wherever fortuna for this provider will be hosted. + #[arg(long = "uri")] + #[arg(default_value = "")] + pub uri: String, }