Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
A first-price sealed-bid auction, also known as a "blind auction", is a type of auction in which all bidders simultaneously submit sealed bids so that no bidder knows the bid of any other participant. The highest bidder pays the price that was submitted. In this tutorial you will learn how to create a cross-chain sealed bid auction dApp with encrypted bids using SecretPath.
See a live demo here!
Contract Deployment: Participants initiate the process by deploying a Sealed Bid Contract to the Secret Network. This contract contains their auction items and encrypted bids, safeguarding the bid details from public exposure.
Contract Execution via Public Gateway:
The execution sequence begins when the Sealed Bid Contract is interacted with via the Ethereum Virtual Machine (EVM).
The SecretPath Public Gateway Smart Contract serves as the intermediary, facilitating communication between the EVM and Secret Network.
Secure Message Transmission:
Messages and transactions pass through the Public Gateway to the Private Gateway Smart Contract, utilizing ECDH to ensure that the data exchanged remains confidential and tamper-proof, maintaining the integrity of the sealed bid throughout the process.
Finalization:
Once the bidding period concludes, the Sealed Bid Contract processes the bids to determine the winner securely.
The outcome is then communicated back through the gateway contracts to the relevant parties on the EVM.
Confidential voting on Secret Network enables developers to create and manage voting systems where proposals and votes remain encrypted and secure. This ensures confidentiality and integrity in voting processes across EVM-compatible chains. There are 2 cross-chain voting solutions on Secret Network, the first uses SecretPath, and the other ECDH cryptography.
Overview: Introduction to using SecretPath as a Confidential Computation Layer for EVM chains, allowing encrypted data transfer and storage on Secret Network. Description of how SecretPath functions as a bridge for encrypted data, facilitating the creation and voting on proposals within a Secret smart contract.
Setup and Deployment: Step-by-step guide on setting up the development environment, compiling and uploading the Secret contract, and configuring the frontend to interact with the SecretPath-enabled voting system.
Passing Encrypted Data: Detailed explanation of how to pass encrypted proposals and votes from the EVM to the Secret Network using SecretPath.
Introduction: Guide to encrypting and decrypting votes using Secret Network smart contracts, aimed at building confidential voting on any EVM chain.
Setup and Configuration: Instructions for setting up the developer environment, configuring environment variables, and generating cryptographic keys for encryption. Steps to upload and instantiate the Secret Network and Polygon smart contracts, enabling creation and voting on proposals.
Executing Contracts: Processes for creating proposals, voting, and decrypting votes using the deployed smart contracts on the Polygon testnet and Secret Network.
A first-price sealed-bid auction, also known as a "blind auction", is a type of auction in which all bidders simultaneously submit sealed bids so that no bidder knows the bid of any other participant. The highest bidder pays the price that was submitted. In this tutorial you will learn how to create a cross-chain sealed bid auction dApp with encrypted bids using SecretPath.
You will start by configuring your developer environment and then learn how to use SecretPath to enable cross-chain encryption and decryption, using Secret Network as a Confidential Computing Layer (CCL) for the EVM.
To get started, clone the SecretPath tutorials repository:
Fund your Sepolia wallet.
cd
into sealed-bid-auctions/sealed-bid-contract
Update the env
file with your Secret Network wallet mnemonic, and rename it ".env" instead of ".env.example"
Compile the contract
cd
into secret-contract/node:
Install the node dependencies
Set SecretPath parameters:
Open upload.js and configure the SecretPath gatewayAddress
, gatewayHash
, and gatewayPublicKey
:
gatewayAddress, gatewayHash, and gatewayPublicKey are needed for instantiating contracts that utilize SecretPath and can be found in the docs here. You will always use these same 3 parameters for instantiating a SecretPath-compatible contract on testnet.
Upload and instantiate the contract:
Upon successful upload and instantiation, add the contract codehash and address to your env.
Now that you've instantiated a sealed bid contract on Secret Network, it's time to create your first auction item with SecretPath!
cd
into sealed-bid-auctions/evm-contract
:
Install the dependencies
Configure env
Configure the env
with your sealed bid auction contract address and codehash, and rename it ".env" instead of ".env.example".
Configure SecretPath
Open scripts/create_auction.js and navigate to line 44, the publicClientAddress
. This is the SecretPath gateway address for Sepolia testnet.
If you wanted to send messages on another chain, such as Base or Polygon, you would simply update this publicClientAddress with the corresponding address found here.
Similarly, there is a SecretPath gateway encryption key, which is on line 63. This is used for ChaCha20-Poly1305 Payload encryption and can be found in the docs here.
If you wanted to do this for mainnet, you would simply use the mainnet encryption key.
Next, configure the auction name
, description,
and end_time
to your liking (end_time
is the amount of minutes that the auction will be live for), and note the handle
variable, which is the function that is actually being called in the Secret contract that you deployed. You are executing the create_auction_item
handle, which executes the create_auction-item
function in your sealed bid contract.
Now that you have all of your SecretPath code configured, execute the SecretPath Sepolia public gateway contract to send your auction item to the Secret contract:
Each auction item you create will have an associated ID; the first auction item has ID 1, the second has ID 2, and so on.
Upon successful execution, info about your SecretPath payload will be returned:
Now it's time to place an encrypted bid on your listed auction item. Open bid.js and adjust the amount that you want to bid as well as the index of the auction item.
Note that the sealed bid contract is designed so that each auction item has an ascending index number starting with 1. So the first auction item you list is index 1, the second is index 2, and so on.
Once you have set your bid, execute the bid function:
Upon successful execution, info about your SecretPath payload will be returned. Now let's query your auction item and bids with secret.js.
cd
into sealed-bid-auctions/sealed-bid-contract/node
:
Make sure you have added your Sealed bid contract address and codehash to your env file, and then query the auction item with node query_auction
:
Note that you are querying with key 1, because the first auction item is stored at index 1, the second auction item is stored at index 2, and so on.
If your auction item was submitted successfully, it should be returned like so:
NOTE: end_time
is converted from minutes to Secret Network block height in the sealed bid auction contract 😎
Now, query the encrypted bids by running node query_bid
:
If the bidding is still open, it will return the message:
If the bidding is closed, it will return the highest bid:
This is programmed in the retrieve_bids_query function of the Sealed Bid contract and can be adjusted to your liking 😊
NOTE: Be sure to update the index of the query for subsequent auction item queries
Congrats! You deployed your very own sealed bid auction contract on Secret Network and used SecretPath to send cross-chain encrypted bids on Sepolia testnet. See the fullstack demo here. You now have all of the tools you need to start building your own cross-chain SecretPath contracts on the EVM 🎉
Note that the end user of the application is not exposed to Secret Network and is only working directly in the EVM environment. However, the data is fully protected and cannot be viewed by anyone.
If you have any questions or run into any issues, post them on the Secret Developer Discord and somebody will assist you shortly.
One of SecretPath's key features is the ability to use encrypted payloads to send over confidential messages to a Secret Smart contract.
SecretPath can seamlessly handle encrypted payloads, as the master gateway contract on Secret automatically decrypts the payload and hands the decrypted payload over to the target contract.
The encryption of the payload is done using the ChaCha20-Poly1305, an authenticated encryption with additional data (AEAD) algorithm.
The key for this symmetric encryption is created by using the Elliptic-curve Diffie-Hellman (ECDH) scheme, comprising of two components:
An extra encryption public key provided from the Secret Gateway Contract
A randomly created (ephemeral) encryption private key on the user side (independent of the user wallet's private key)
Combining both of these keys together via the ECDH Scheme yields our encryption key, which we use to encrypt the payload with ChaCha20-Poly1305.
As a first example for this, we have used SecretPath to encrypt a string
and subsequently store it in a Secret contract.
SecretVRF stands out in the competitive landscape of verifiable random functions (VRFs) by offering a significant cost and speed advantage over its principal competitors. Notably, it provides approximately a 4 times cost benefit, which is a massive saving for projects that rely on random number generation at scale. This economic efficiency is largely due to its optimized gas usage, which minimizes the on-chain transaction cost.
In addition to its cost benefits, SecretVRF is also twice as fast as its closest competitor. This speed improvement is critical for applications that require almost real-time randomness, such as gaming, lotteries, and various DeFi protocols.
To demonstrate, we have this small video here outlining all of the advantages of SecretVRF vs. its biggest competitor:
An example contract call using SecretVRF on Ethereum Sepolia which requests 20 random words is compared for its gas usage. Here, we use the example contracts provided in the documentation of Chainlink. In both cases, response time for Secret VRF is at around 1-2 blocks, so around 10s.
In total, we also do not need to pay in special LINK tokens and instead can just pay in the native gas token of the chain (here: Sepolia ETH), which saves you additional costs.
To summarize, SecretVRF's combination of cost efficiency, speed, and EVM chain compatibility makes it a compelling choice for developers and projects seeking reliable and economical verifiable random functions. Its technical innovations position it as a leader in the space, offering tangible benefits that can significantly enhance the performance and cost-effectiveness of a wide range of blockchain applications.
Learn how to use SecretPath on EVM to encrypt payloads.
SecretPath seamlessly handles encrypted payloads on the EVM, which means EVM developers can use SecretPath to encrypt and decrypt messages cross-chain with little-to-no Rust experience required.
Check out the Key Value store demo to see what you will build
This tutorial explains how to:
Upload your own Key-value store contract on Secret Network
Encrypt data on the EVM and transmit encrypted data cross-chain to Secret Network
Connect your key value store contract to a React frontend.
After this tutorial, you will have the tools you need to use SecretPath to encrypt messages on any .
To get started, clone the EVM key value store repository:
cd
into secret-contract/node
Install the dependencies:
gatewayAddress
is the SecretPath gateway contract address for testnet
gatewayHash
is the SecretPath gateway contract hash for testnet
gatewayKey
is public key used for SecretPath encryption on Secret testnet
To upload and instantiate the contract, run node upload
:
Upon successful upload, a contractHash
and address
will be returned:
If you want to make any changes to the Secret smart contract before uploading it to Secret Network, you can do that too! Simply update the contract and then compile it by running make build-mainnet:
The compiled contract, called contract.wasm.gz
, will be outputted in the secret-contract folder.
Now that you have your key value store smart contract uploaded to Secret Network, let's use it to store encrypted messages passed from the EVM. Most of the ECDH cryptography has been abstracted away so there are only a few values you need to change.
cd
into evm-kv-store-demo/kv-store-frontend:
Install the dependencies:
That's it! You dApp is now connected to your Secret smart contract and ready to encrypt key value pairs. To start the application, run:
Now that you have successfully uploaded a key-value contract to Secret Network and connected it to a React frontend, let's examine the code to understand how SecretPath passes encrypted data from the EVM to Secret Network.
When you create your cross-chain dApp, you simply need to format your data so that it can be transmitted successfully from the public SecretPath contract to the private SecretPath contract.
handle
is the name of the function that we are executing in our private Secret smart contract, and data
is the data that we pass to the function that we are executing in the Secret contract, which in the case of the key value contract is key,
value,
and viewing_key.
Let's now look at the Secret Network contract that we uploaded to better understand the store_value
function and how it uses the parameters key,
value,
and viewing_key.
Since we pass the handle store_value
from your dApp to your Secret contract, it knows to execute the store_value
function!
Inside of the store_value
function, we use the key,
value,
and viewing_key
parameters that we pass from the EVM in order to create a key map with our key-value pairs:
This data is encrypted and stored inside of your Secret smart contract. The data can now only be revealed with a query that uses the proper viewing_key:
In this tutorial, you've learned how to deploy a key-value store smart contract on Secret Network, encrypt and transmit messages from an EVM-compatible chain, and integrate the contract with a React frontend. Using SecretPath, you can now seamlessly handle encrypted payloads cross-chain with minimal Rust experience. By following the steps outlined, you're equipped to build decentralized applications that leverage SecretPath for secure, cross-chain communication and data storage.
94k Gas with Secretpath:
300k+ Gas for Chainlink VRF with their example project:
55k gas with Secretpath:
200k+ gas for Chainlink VRF with their example project:
In the node
folder, open the upload.js file and review the instantiate message at :
These three parameters remain constant and must be passed for every Secret Network contract that implements SecretPath. They can be found for testnet.
Open and change the routing_contract
and routing_code_hash
to the address and code hash for your contract:
Congrats! You now have now deployed a fullstack cross-chain decentralized application that passes encrypted key-value pairs from the EVM and stores them on Secret Network
From a high-level, all that you need to know is there is a public SecretPath contract deployed on every EVM chain listed , which communicates with a private SecretPath contract deployed on Secret Network, and it is these public/private contract pairs that encrypt your data and pass messages from the EVM to Secret Network.
All of the data formatting for the public EVM contract happens in . This is almost entirely boilerplate code except for the variables and :
At, we have a match
statement, which includes the handle "store_value":
You can view the frontend component for querying your Secret contract !
If you have any questions or run into any issues, post them on the and somebody will assist you shortly.