Skip to content

Commit 04d1a6a

Browse files
committed
update code documentation
1 parent 57c7da7 commit 04d1a6a

23 files changed

Lines changed: 370 additions & 414 deletions

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dotEnvConfig();
1010

1111
const config: HardhatUserConfig = {
1212
solidity: {
13-
version: "0.8.24",
13+
version: "0.8.28",
1414
settings: {
1515
optimizer: {
1616
enabled: true,

script/single-deployment/DeployRandomnessReceiver.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {Factory} from "src/factory/Factory.sol";
1414
/// @title DeploySignatureSchemeAddressProvider
1515
/// @dev Script for deploying MockRandomnessReceiver contract.
1616
contract DeployRandomnessReceiver is JsonUtils {
17-
1817
function run() public virtual {
1918
address randomnessSenderAddr =
2019
_readAddressFromJsonInput(Constants.DEPLOYMENT_INPUT_JSON_PATH, "randomnessSenderProxyAddress");

script/single-deployment/DeployRandomnessSender.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {Factory} from "src/factory/Factory.sol";
1717
/// @dev Script for deploying or upgrading the RandomnessSender contract.
1818
/// Reads an environment variable to determine if it's an upgrade (new implementation only) or a full deployment.
1919
contract DeployRandomnessSender is JsonUtils, EnvReader {
20-
2120
/// @notice Runs the deployment script, checking the environment variable to determine whether to upgrade or deploy.
2221
function run() public virtual {
2322
bool isUpgrade = vm.envBool("IS_UPGRADE");

script/single-deployment/DeploySignatureSchemeAddressProvider.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {Factory} from "src/factory/Factory.sol";
1515
/// @title DeploySignatureSchemeAddressProvider
1616
/// @dev Script for deploying SignatureSchemeAddressProvider contract.
1717
contract DeploySignatureSchemeAddressProvider is JsonUtils, EnvReader {
18-
1918
function run() public virtual {
2019
deploySignatureSchemeAddressProvider();
2120
}

script/single-deployment/DeploySignatureSender.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {Factory} from "src/factory/Factory.sol";
1818
/// @dev Script for deploying or upgrading the SignatureSender contract.
1919
/// Reads an environment variable to determine if it's an upgrade (new implementation only) or a full deployment.
2020
contract DeploySignatureSender is JsonUtils, SignatureUtils, EnvReader {
21-
2221
function run() public virtual {
2322
bool isUpgrade = vm.envBool("IS_UPGRADE");
2423
address signatureSchemeAddressProvider =

src/RandomnessReceiverBase.sol

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
1-
// SPDX-License-Identifier: MIT
1+
/// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8;
33

44
import {IRandomnessReceiver} from "./interfaces/IRandomnessReceiver.sol";
55
import {IRandomnessSender} from "./interfaces/IRandomnessSender.sol";
66

7+
/// @title RandomnessReceiverBase contract
8+
/// @author Randamu
9+
/// @notice Abstract contract to facilitate receiving randomness from an external source.
10+
/// @dev This contract ensures that only a designated randomness sender can provide randomness values.
711
abstract contract RandomnessReceiverBase is IRandomnessReceiver {
12+
/// @notice The contract responsible for providing randomness.
13+
/// @dev This is an immutable reference set at deployment.
814
IRandomnessSender public immutable randomnessSender;
915

16+
/// @notice Ensures that only the designated randomness sender can call the function.
1017
modifier onlyRandomnessSender() {
1118
require(msg.sender == address(randomnessSender), "Only randomnessSender can call");
1219
_;
1320
}
1421

22+
/// @notice Initializes the contract with a specified randomness sender.
23+
/// @dev Ensures that the provided sender address is non-zero.
24+
/// @param _randomnessSender The address of the randomness sender contract.
1525
constructor(address _randomnessSender) {
1626
require(_randomnessSender != address(0), "Cannot set zero address as randomness sender");
1727
randomnessSender = IRandomnessSender(_randomnessSender);
1828
}
1929

20-
/**
21-
* @dev See {IRandomnessSender-requestRandomness}.
22-
*/
30+
/// @notice Requests randomness from the designated randomness sender.
31+
/// @dev Calls the `requestRandomness` function on the randomness sender contract.
32+
/// @return requestID The unique identifier of the randomness request.
2333
function requestRandomness() internal returns (uint256 requestID) {
2434
requestID = randomnessSender.requestRandomness();
2535
}
2636

27-
/**
28-
* @dev See {IRandomnessReceiver-receiveRandomness}.
29-
*/
37+
/// @notice Receives randomness for a specific request ID from the designated sender.
38+
/// @dev This function is restricted to calls from the designated randomness sender.
39+
/// @param requestID The unique identifier of the randomness request.
40+
/// @param randomness The generated random value as a `bytes32` type.
3041
function receiveRandomness(uint256 requestID, bytes32 randomness) external onlyRandomnessSender {
3142
onRandomnessReceived(requestID, randomness);
3243
}
3344

34-
/**
35-
* @notice Handles the reception of a generated random value for a specific request.
36-
* @dev This internal function is called when randomness is received for the given `requestID`.
37-
* It is intended to be overridden by derived contracts to implement custom behavior.
38-
* @param requestID The unique identifier of the randomness request.
39-
* @param randomness The generated random value, provided as a `bytes32` type.
40-
*/
45+
/// @notice Handles the reception of a generated random value for a specific request.
46+
/// @dev This internal function is intended to be overridden by derived contracts to implement custom behavior.
47+
/// @param requestID The unique identifier of the randomness request.
48+
/// @param randomness The generated random value, provided as a `bytes32` type.
4149
function onRandomnessReceived(uint256 requestID, bytes32 randomness) internal virtual;
4250
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8;
33

4+
/// @title IRandomnessReceiver interface
5+
/// @author Randamu
6+
/// @notice Interface for randomness consumer contracts that receive randomness via callbacks.
47
interface IRandomnessReceiver {
5-
/**
6-
* @notice Receives a random value associated with a specific request.
7-
* @dev This function is called to provide the randomness generated for a given request ID.
8-
* It is intended to be called by a trusted source that provides randomness.
9-
* @param requestID The unique identifier of the randomness request.
10-
* @param randomness The generated random value, provided as a `bytes32` type.
11-
*/
8+
/// @notice Receives a random value associated with a specific request.
9+
/// @dev This function is called to provide the randomness generated for a given request ID.
10+
/// It is intended to be called by a trusted source that provides randomness.
11+
/// @param requestID The unique identifier of the randomness request.
12+
/// @param randomness The generated random value, provided as a `bytes32` type.
1213
function receiveRandomness(uint256 requestID, bytes32 randomness) external;
1314
}

src/interfaces/IRandomnessSender.sol

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,35 @@ pragma solidity ^0.8;
33

44
import "../libraries/TypesLib.sol";
55

6-
// todo subscription and payments
7-
// todo we could embed the following for subscription and payments - subscriptionID, numberOfRequestTxConfirmations, callbackGasLimit, numRandomValues
8-
// todo check for potential gaps in using uint256 as id compared to bytes32
6+
/// @title IRandomnessSender interface
7+
/// @author Randamu
8+
/// @notice Interface for randomness sender contract which sends randomness via callbacks to randomness consumer contracts.
99
interface IRandomnessSender {
10-
/**
11-
* @notice Requests the generation of a random value for a specified blockchain height.
12-
* @dev Initiates a randomness request.
13-
* The generated randomness will be associated with the returned `requestID`.
14-
* @return requestID The unique identifier assigned to this randomness request.
15-
*/
10+
/// @notice Requests the generation of a random value for a specified blockchain height.
11+
/// @dev Initiates a randomness request.
12+
/// The generated randomness will be associated with the returned `requestID`.
13+
/// @return requestID The unique identifier assigned to this randomness request.
1614
function requestRandomness() external returns (uint256 requestID);
17-
/**
18-
* @notice Retrieves a specific request by its ID.
19-
* @dev This function returns the Request struct associated with the given requestId.
20-
* @param requestId The ID of the request to retrieve.
21-
* @return The Request struct corresponding to the given requestId.
22-
*/
15+
16+
/// @notice Retrieves a specific request by its ID.
17+
/// @dev This function returns the Request struct associated with the given requestId.
18+
/// @param requestId The ID of the request to retrieve.
19+
/// @return The Request struct corresponding to the given requestId.
2320
function getRequest(uint256 requestId) external view returns (TypesLib.RandomnessRequest memory);
2421

25-
/**
26-
* @notice Sets signatureSender contract address.
27-
* @param newSignatureSender The new address to set.
28-
*/
22+
/// @notice Sets signatureSender contract address.
23+
/// @param newSignatureSender The new address to set.
2924
function setSignatureSender(address newSignatureSender) external;
3025

31-
/**
32-
* @notice Retrieves all requests.
33-
* @dev This function returns an array of all Request structs stored in the contract.
34-
* @return An array containing all the Request structs.
35-
*/
26+
/// @notice Retrieves all requests.
27+
/// @dev This function returns an array of all Request structs stored in the contract.
28+
/// @return An array containing all the Request structs.
3629
function getAllRequests() external view returns (TypesLib.RandomnessRequest[] memory);
37-
/**
38-
* @notice Generates a message from the given request.
39-
* @dev Creates a hash-based message using the `DST` and `nonce` fields of the `Request` struct.
40-
* The resulting message is the hash of the encoded values, packed into a byte array.
41-
* @param r The `Request` struct containing the data for generating the message.
42-
* @return A byte array representing the hashed and encoded message.
43-
*/
30+
31+
/// @notice Generates a message from the given request.
32+
/// @dev Creates a hash-based message using the `DST` and `nonce` fields of the `Request` struct.
33+
/// The resulting message is the hash of the encoded values, packed into a byte array.
34+
/// @param r The `Request` struct containing the data for generating the message.
35+
/// @return A byte array representing the hashed and encoded message.
4436
function messageFrom(TypesLib.RandomnessRequest memory r) external pure returns (bytes memory);
4537
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8;
33

4+
/// @title ISignatureReceiver interface
5+
/// @author Randamu
6+
/// @notice Interface for contracts receiving signatures via callbacks.
47
interface ISignatureReceiver {
5-
/// Setters
6-
7-
/**
8-
* @notice Receives a signature for a specified request.
9-
* @dev This function is intended to be called to provide a signature for the given `requestID`.
10-
* @param requestID The unique identifier of the request associated with the signature.
11-
* @param signature The cryptographic signature of the message, provided as a byte array.
12-
*/
8+
/// @notice Receives a signature for a specified request.
9+
/// @dev This function is intended to be called to provide a signature for the given `requestID`.
10+
/// @param requestID The unique identifier of the request associated with the signature.
11+
/// @param signature The cryptographic signature of the message, provided as a byte array.
1312
function receiveSignature(uint256 requestID, bytes calldata signature) external;
1413
}
Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8;
33

4+
/// @title ISignatureScheme interface
5+
/// @author Randamu
6+
/// @notice Interface for signature schemes, e.g., BN254, BLS, etc.
47
interface ISignatureScheme {
5-
/// Getters
6-
7-
/**
8-
* @notice Returns the scheme identifier as a string, e.g., "BN254", "BLS12-381", "TESS"
9-
*/
8+
/// @notice Returns the scheme identifier as a string, e.g., "BN254", "BLS12-381", "TESS"
109
function SCHEME_ID() external returns (string memory);
1110

12-
/**
13-
* @notice Verifies a signature using the given signature scheme.
14-
* @param message The message that was signed. Message is a G1 point represented as bytes.
15-
* @param signature The signature to verify. Signature is a G1 point represented as bytes.
16-
* @param publicKey The public key of the signer. Public key is a G2 point represented as bytes.
17-
* @return isValid boolean which evaluates to true if the signature is valid, false otherwise.
18-
*/
11+
/// @notice Verifies a signature using the given signature scheme.
12+
/// @param message The message that was signed. Message is a G1 point represented as bytes.
13+
/// @param signature The signature to verify. Signature is a G1 point represented as bytes.
14+
/// @param publicKey The public key of the signer. Public key is a G2 point represented as bytes.
15+
/// @return isValid boolean which evaluates to true if the signature is valid, false otherwise.
1916
function verifySignature(bytes calldata message, bytes calldata signature, bytes calldata publicKey)
2017
external
2118
view
2219
returns (bool isValid);
2320

24-
/**
25-
* @notice Hashes a message to a G1 point on the elliptic curve.
26-
* @param message The message to be hashed.
27-
* @return (uint256, uint256) A point on the elliptic curve in G1, represented as x and y coordinates.
28-
*/
21+
/// @notice Hashes a message to a G1 point on the elliptic curve.
22+
/// @param message The message to be hashed.
23+
/// @return (uint256, uint256) A point on the elliptic curve in G1, represented as x and y coordinates.
2924
function hashToPoint(bytes memory message) external view returns (uint256, uint256);
30-
/**
31-
* @notice Hashes a message to a G1 point on the elliptic curve.
32-
* @param message The message to be hashed.
33-
* @return bytes A point on the elliptic curve in G1, represented as bytes.
34-
*/
25+
26+
/// @notice Hashes a message to a G1 point on the elliptic curve.
27+
/// @param message The message to be hashed.
28+
/// @return bytes A point on the elliptic curve in G1, represented as bytes.
3529
function hashToBytes(bytes calldata message) external view returns (bytes memory);
3630
}

0 commit comments

Comments
 (0)