Sealed Bid Auctions
A fullstack tutorial for cross-chain confidential sealed bid auctions on IBC-connected chains.
Last updated
A fullstack tutorial for cross-chain confidential sealed bid auctions on IBC-connected chains.
Last updated
Overview
This tutorial explains how to upload a confidential sealed bid auction contract on Secret Network, which you can execute and query for private auctions on any IBC-connected chain. π
In this example, you will learn how to deploy a confidential auction contract on Secret Network which you will execute from Osmosis mainnet.
The SDK abstracts IBC interactions with the Secret Network for applications that use Cosmos wallets. It introduces a secure method for generating confidential messages and reliably authenticating users at the same time using the chacha20poly1305
algorithm.
View the typescript SDK here, which we will learn how to implement shortly π
In this tutorial you will learn:
How to run the fullstack cross-chain Next.js application in your browser.
How to use the core smart contract logic for confidential cross-chain auctions using IBC hooks.
How to deploy your very own auction contract on Secret Network.
See a fullstack demo here!
Clone the repo:
cd
into next-frontend
and install the dependencies:
Add environment variables in cosmos-ccl-encrypted-payloads-demo/next-frontend
:
Start the application:
The fullstack Next.js application should now be running in your browser! You can use it to create confidential auctions and bids. Now that you have the application running in your browser, let's dive into the smart contract logic!
To encrypt auction bids using the SDK, we use the enum
called InnerMethods
, which wraps the possible actions in the auction smart contract, namely, CreateAuctionItem
and Bid, with the SDK encryption logic:
InnerMethods
leverage the SDK by using the GatewayExecuteMsg
to structure encrypted execution messages for cross-chain auction management and bidding:
Understanding the Encryption SDK
The magic of Secret Network's encryption SDK happens here, with handle_encrypted_wrapper:
The Extension
variant inExecuteMsg
leverages the functionality of handle_encrypted_wrapper
because the wrapper decrypts and verifies the entire message payload before the Extension
message is processed. Hereβs how it works:
handle_encrypted_wrapper
Applies to the Entire Input:
When the execute
function is called, the msg
and info
parameters are initially encrypted.
handle_encrypted_wrapper
is invoked with these parameters:
This function decrypts and verifies the wrapper (encrypted payload) to produce:
A decrypted msg
(of type ExecuteMsg
).
A decrypted info
(with verified sender details).
Decrypted msg
Can Contain ExecuteMsg::Extension
:
After decryption, the msg
can match any variant of ExecuteMsg
, including ExecuteMsg::Extension
.
For example:
Here, Extension
contains an additional layer of messages (InnerMethods
) which define specific functionality.
How handle_encrypted_wrapper
Affects Extension
:
The msg
inside ExecuteMsg::Extension
(i.e., InnerMethods
) is also encrypted in the original input.
handle_encrypted_wrapper
ensures:
The outer msg
is decrypted (revealing Extension
).
The inner data (e.g., InnerMethods
) is now in cleartext and ready for logical execution.
Without this decryption, the contract could not access or process InnerMethods
within the Extension
.
Validation and Security:
By verifying and decrypting the entire payload at the wrapper level, the contract ensures:
The Extension
message is authentic and unaltered.
The sender (info
) is authenticated and valid.
Any operations within InnerMethods
(like bidding) are authorized based on the decrypted info
and secure data.
Now that you understand how the encryption SDK functions, let's look how it's connected to the frontend. The Next.js encryption logic can be found in Gateway.ts:
Both of these functions access a confidential auction contract
already deployed on Secret Network (at the end of this tutorial, you will learn how to deploy your own).
Then, we call the execute_gateway_contract
function, which is where all of the cross-chain SDK logic is implemented using IBC hooks:
You can further examine sendIBCToken
and gatewayChachaHookMemo
in the CCL-SDK ibc.ts
file here.
There are two types of queries using the CCL SDK:
Unauthenticated queries ie Extension
, which are queries that donβt require sensitive or protected data. Example: Retrieving a list of auctions, which is public.
Authenticated queries ie Inner Queries
(WithPermit
, WithAuthData
), which are queries that require auth_data
from the caller for permission validation. Example: MyBid { auction_id: u64 }
retrieves a user-specific bid.
Extended Queries
Inner Queries
Data Access Level
Public or general data
Private or user-specific data
Authorization
No extra authentication required
Requires auth_data
or permit
Processing Function
query::query_extended
query::query_with_auth_data
Use Cases
Public info like auctions
Personal data like a userβs bids
To query encrypted bids using the CCL SDK, use the enum
InnerQueries
, which wraps the possible queries in the auction smart contract, namely, MyBid
, with the CCL SDK encryption logic:
InnerMethods
leverages the SDK by using the GatewayQueryMsg
types to query encrypted cross-chain bids. You have the choice of using two different types of encrypted queries: query_with_auth_data
and query_with_permit.
In this tutorial, you we will learn how to implement query_with_permit
.
Now let's take a look at the frontend code to see how query_with_permit is implemented. π
The Next.js query decryption logic can be found in Gateway.ts:
Because bids are encrypted, we must decrypt them in order to query a wallet's bids. The frontend function query_contract_auth
securely queries the Secret smart contract using query permits, ensuring that only authorized users can access sensitive data. Query permits are cryptographic credentials that:
Prove the userβs ownership of a wallet.
Allow contracts to verify the userβs identity.
Avoid exposing the private key.
You now should have all the tools you need to use the IBC CCL toolkit! Lastly, let's learn how to deploy your own auction contract on Secret Network π
cd
into deploy-scripts
and install the dependencies:
Add your wallet mnemonic to .env
. Then compile the contract:
The compile script requires Docker to be open for successful compilation
Compile the typescript upload script so you can upload the compiled vauction contract:
Once you run the above command, the typescript upload file in ./src
will be compiled as javascript file in ./dist
.
Upload and instantiate the voting contract on Secret Network Mainnet:
In your terminal, a codeID
, codeHash
, and contractAddress
will be returned:
Finally, update config.ts with your contract's code_hash and address:
Congratulations on completing this on using Secret Network's IBC SDK to encrypt auction bids cross-chain using Secret Network smart contracts! π You've explored the intricacies of encrypted messaging, cross-chain IBC interactions, and secure smart contract execution using the Secret Network CCL SDK. By building and running the fullstack IBC application, youβve gained hands-on experience in contract deployment, frontend integration, and secure querying with Secret Network query permits. π