Skip to content

Commit 443f88c

Browse files
committed
add randomness consumer deployment script and deploy
1 parent 2c3a30d commit 443f88c

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "lib/blocklock-solidity"]
88
path = lib/blocklock-solidity
99
url = https://github.com/randa-mu/blocklock-solidity
10+
[submodule "lib/randomness-solidity"]
11+
path = lib/randomness-solidity
12+
url = https://github.com/randa-mu/randomness-solidity

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ source .env
5959
forge script script/SealedBidAuction.s.sol --rpc-url $CALIBRATION_TESTNET_RPC_URL --private-key $CALIBRATION_TESTNET_PRIVATE_KEY --broadcast
6060
```
6161

62+
For common deployment issues with the Filecoin calibration testnet, please refer to the [FEVM (Ethereum Virtual Machine on Filecoin) Foundry toolkit](https://github.com/filecoin-project/fevm-foundry-kit).
63+
6264

6365
## How It Works
6466
1. Encrypting Your Bid (Off-Chain): Bidders encrypt their bid amounts off-chain, generating ciphertexts for submission.
@@ -75,6 +77,5 @@ forge script script/SealedBidAuction.s.sol --rpc-url $CALIBRATION_TESTNET_RPC_UR
7577
Check out the detailed tutorial on [our blog](https://drand.love/blog/2025/03/04/onchain-sealed-bid-auction/).
7678

7779

78-
7980
## Licensing
8081
This source code is licensed under the MIT License which can be accessed [here](LICENSE).

lib/randomness-solidity

Submodule randomness-solidity added at d9d1057

remappings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ config/=config/
77

88
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
99
@blocklock-solidity/src/=lib/blocklock-solidity/src/
10+
@randomness-solidity/src/=lib/randomness-solidity/src/

script/RandomnessConsumer.s.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
7+
import {RandomnessConsumer} from "src/RandomnessConsumer.sol";
8+
9+
contract RandomnessConsumerScript is Script {
10+
function run() external {
11+
vm.broadcast();
12+
RandomnessConsumer randomnessConsumer = new RandomnessConsumer();
13+
14+
console.log("RandomnessConsumer deployed at: ", address(randomnessConsumer));
15+
}
16+
}

src/RandomnessConsumer.sol

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import {RandomnessReceiverBase} from "@randomness-solidity/src/RandomnessReceiverBase.sol";
5+
6+
/// @title Randomness Consumer contract
7+
/// @author Randamu developers
8+
/// @notice A mock RandomnessConsumer contract that makes use of the Randamu randomness-solidity
9+
/// library to request verifiable randomness
10+
/// The library is available at: https://github.com/randa-mu/randomness-solidity/tree/main
11+
/// The library also contains logic for array shuffling using Feistel shuffle
12+
/// and selecting n items randomly from an array
13+
/// Deployed at: 0x410354CCce2c9d99bfD1968F91d37767beE97315
14+
contract RandomnessConsumer is RandomnessReceiverBase {
15+
address public constant RANDOMNESS_SENDER = 0x9c789bc7F2B5c6619Be1572A39F2C3d6f33001dC;
16+
17+
bytes32 public randomness;
18+
uint256 public requestId;
19+
20+
constructor() RandomnessReceiverBase(RANDOMNESS_SENDER) {}
21+
22+
/**
23+
* @dev Requests randomness.
24+
*
25+
* This function calls the `requestRandomness` method to request a random value.
26+
* The `requestId` is updated with the ID returned from the randomness request.
27+
*/
28+
function rollDice() external {
29+
requestId = requestRandomness();
30+
}
31+
32+
/**
33+
* @dev Callback function that is called when randomness is received.
34+
* @param requestID The ID of the randomness request that was made.
35+
* @param _randomness The random value received.
36+
*
37+
* This function verifies that the received `requestID` matches the one that
38+
* was previously stored. If they match, it updates the `randomness` state variable
39+
* with the newly received random value.
40+
*
41+
* Reverts if the `requestID` does not match the stored `requestId`, ensuring that
42+
* the randomness is received in response to a valid request.
43+
*/
44+
function onRandomnessReceived(uint256 requestID, bytes32 _randomness) internal override {
45+
require(requestId == requestID, "Request ID mismatch");
46+
randomness = _randomness;
47+
}
48+
}

src/SealedBidAuction.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ import {AbstractBlocklockReceiver} from "@blocklock-solidity/src/AbstractBlocklo
88
// Import ReentrancyGuard which is an Openzeppelin solidity library that helps prevent reentrant calls to a function.
99
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
1010

11+
/// @title Sealed Bid Auction interface
12+
/// @author Randamu developers
13+
/// @notice An interface for a sealed bid auction smart contract
14+
/// allowing encrypted bids which are decrypted at a future block number.
1115
interface ISealedBidAuction {
1216
function placeSealedBid(TypesLib.Ciphertext calldata sealedBid) external payable returns (uint256);
1317
function withdrawRefund() external;
1418
function fulfillHighestBid() external payable;
1519
function finalizeAuction() external;
1620
}
1721

22+
/// @title Sealed Bid Auction contract
23+
/// @author Randamu developers
24+
/// @notice A bid smart contract which allows sealed bids to be made in an auction.
25+
/// The bids are automatically decrypted at a future block number (block number that closes the bidding window).
1826
contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, ReentrancyGuard {
1927
struct Bid {
2028
uint256 bidID; // Unique identifier for the bid

0 commit comments

Comments
 (0)