@pulsartronic/entropy 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ /**
5
+ * @notice Represents a cryptographic hash record containing an identifier and its associated hash
6
+ * @dev Used for tracking hash commitments across rounds
7
+ */
8
+ struct HashRecord {
9
+ bytes32 id;
10
+ bytes32 hash;
11
+ }
12
+
13
+ /**
14
+ * @notice Contains data captured when a random number is requested
15
+ * @dev Stores entropy A and the block number at the time of the request
16
+ */
17
+ struct EntropyRequest {
18
+ bytes32 entropy_a;
19
+ uint256 block_number;
20
+ }
21
+
22
+ /**
23
+ * @notice Encapsulates the oracle's response payload for entropy generation
24
+ * @dev Contains entropy B, entropy C, and the next hash commitment for future rounds
25
+ */
26
+ struct EntropyResponse {
27
+ bytes32 entropy_b;
28
+ bytes32 entropy_c;
29
+ bytes32 next_hash_b;
30
+ }
31
+
32
+ /**
33
+ * @notice Result structure containing the outcome of cryptographic verification
34
+ * @dev Includes validation flags, the final derived random number, and the next hash record
35
+ */
36
+ struct Verified {
37
+ bool b; // entropy_b verification
38
+ bool c; // entropy_c verification
39
+ bytes32 random_number;
40
+ HashRecord next_hash_record;
41
+ }
42
+
43
+ /**
44
+ * @title ABC Entropy Core Interface
45
+ * @notice Interface defining the core functions of the ABC entropy and commit-reveal system
46
+ */
47
+ interface IABCEntropy {
48
+ /**
49
+ * @notice Calculates the total fee required for a random number request
50
+ * @param callback_gas_limit The gas limit allocated for the callback execution
51
+ * @return The total fee amount denominated in wei
52
+ */
53
+ function get_fee(uint256 callback_gas_limit) external view returns (uint256);
54
+
55
+ /**
56
+ * @notice Submits a request for a random number
57
+ * @param callback_id The unique identifier for the callback
58
+ * @param callback_gas_limit The gas limit allocated for the callback execution
59
+ * @param hash_record_id The identifier for the associated hash record
60
+ * @param entropy_a Seed A provided by the requester
61
+ * @return An EntropyRequest struct containing the recorded request details
62
+ */
63
+ function get(bytes32 callback_id, uint256 callback_gas_limit, bytes32 hash_record_id, bytes32 entropy_a) external payable returns (EntropyRequest memory);
64
+
65
+ /**
66
+ * @notice Verifies an oracle entropy response and returns the verification results
67
+ * @param hash The expected hash commitment
68
+ * @param request_data The original request data structure
69
+ * @param entropy_response The response payload containing entropy B and C
70
+ * @return A Verified struct containing the validation outcome and final random number
71
+ */
72
+ function verify(bytes32 hash, EntropyRequest memory request_data, EntropyResponse calldata entropy_response) external returns (Verified memory);
73
+ }
74
+
75
+ /**
76
+ * @title Entropy Consumer Interface
77
+ * @notice Interface that must be implemented by client dApps wanting to receive random number callbacks
78
+ */
79
+ interface IEntropyConsumer {
80
+ /**
81
+ * @notice Callback function invoked by the oracle to deliver the generated entropy response
82
+ * @param callback_id The unique identifier for the callback matching the original request
83
+ * @param entropy_response The response payload containing the entropy values
84
+ */
85
+ function entropy_callback(bytes32 callback_id, EntropyResponse calldata entropy_response) external payable;
86
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pulsartronic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
1
+ # ABC Entropy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Verifiable, tamper-proof randomness for your smart contracts.**
4
+
5
+ ABC Entropy is a lightweight commit-reveal randomness oracle designed to deliver verifiable, on-chain random numbers to your dApp with minimal friction.
6
+
7
+ ---
8
+
9
+ ## Table of contents
10
+
11
+ - [How ABC entropy works](#how-abc-entropy-works)
12
+ - [Getting started](#getting-started-consuming-entropy-from-a-contract)
13
+ - [Features](#features)
14
+ - [Supported networks](#supported-networks)
15
+ - [Security model](#security-model)
16
+
17
+ ## How ABC entropy works
18
+
19
+ This is a commit-reveal scheme built on three components, each contributing part of the final random number:
20
+
21
+ | | Component | Role |
22
+ |---|---|---|
23
+ | **A** | Your dapp users | Your frontend provides the user's entropy contribution. |
24
+ | **B** | Generator (us) | We lock our entropy contribution behind a hash beforehand, allowing post-reveal verification. |
25
+ | **C** | Sequencer (the network) | It introduces additional entropy so that no party, including us, can manipulate the outcome. |
26
+
27
+ As long as we aren't running the sequencer, the system remains tamper-proof, even against us. Read [Security model](#security-model).
28
+
29
+
30
+ ## Getting started: consuming entropy from a contract
31
+ Below is an example consumer contract implementing `IEntropyConsumer` (see [`ABCEntropyExample.sol`](./ABCEntropyExample.sol) for the full source code and detailed inline comments):
32
+ ```solidity
33
+ // SPDX-License-Identifier: MIT
34
+ pragma solidity ^0.8.20;
35
+
36
+ import "@pulsartronic/entropy/Definitions.sol";
37
+
38
+ struct UserState {
39
+ EntropyRequest entropy_request;
40
+ HashRecord hash_record;
41
+ }
42
+
43
+ contract ABCEntropyExample is IEntropyConsumer {
44
+ IABCEntropy public abc_entropy;
45
+ mapping(address => UserState) public user_state_map;
46
+ event RandomEvent(address user, bytes32 random_number);
47
+
48
+ constructor() {
49
+ // Arbitrum Sepolia example address.
50
+ abc_entropy = IABCEntropy(0xBfBfcbc03E3A3c40656b23fcfdb96A48232B8C3f);
51
+ }
52
+
53
+ function get_entropy(bytes32 user_entropy) external payable {
54
+ bytes memory a_seed = abi.encodePacked(user_entropy, msg.sender);
55
+ bytes32 entropy_a = keccak256(a_seed);
56
+ UserState storage user_state = user_state_map[msg.sender];
57
+ bytes32 callback_id = bytes32(uint256(uint160(msg.sender)));
58
+ uint256 callback_gas_limit = 50000;
59
+ uint256 fee = abc_entropy.get_fee(callback_gas_limit);
60
+
61
+ // Request a randoom number.
62
+ user_state.entropy_request = abc_entropy.get{value: fee}(
63
+ callback_id,
64
+ callback_gas_limit,
65
+ user_state.hash_record.id,
66
+ entropy_a
67
+ );
68
+ }
69
+
70
+ function entropy_callback(bytes32 callback_id, EntropyResponse calldata entropy_response) external payable {
71
+ require(msg.sender == address(abc_entropy), "INVALID_PROVIDER");
72
+ address user = address(uint160(uint256(callback_id)));
73
+ UserState storage user_state = user_state_map[user];
74
+
75
+ // Get the requested random number.
76
+ Verified memory verified = abc_entropy.verify(
77
+ user_state.hash_record.hash,
78
+ user_state.entropy_request,
79
+ entropy_response
80
+ );
81
+
82
+ // Emit an event with the generated random number.
83
+ if (verified.b || bytes32(0) == user_state.hash_record.hash) {
84
+ user_state.hash_record = verified.next_hash_record;
85
+ emit RandomEvent(user, verified.random_number);
86
+ }
87
+ }
88
+ }
89
+ ```
90
+ ## Quick Test Guide in Remix
91
+
92
+ 1. **Open the Contract:** Click [Open in Remix](https://app.remix.live/pulsartronic/entropy/blob/main/ABCEntropyExample.sol).
93
+ 2. **Compile:** Go to the **Solidity Compiler** tab on the left, select version `0.8.20` (or higher), and click **Compile ABCEntropyExample.sol**.
94
+ 3. **Deploy & Test on Arbitrum Sepolia:**
95
+ - Switch your Web3 wallet (MetaMask) to **Arbitrum Sepolia**.
96
+ - Go to the **Deploy & Run Transactions** tab.
97
+ - Set *Environment* to **Injected Provider - MetaMask**.
98
+ - The contract is pre-configured with the testnet oracle address (`0xBfBfcbc03E3A3c40656b23fcfdb96A48232B8C3f`).
99
+ - Call `get_entropy` passing some test bytes32 data (e.g., `0x1234...`) and attach the required ETH fee (check `get_fee` first if needed)!
100
+
101
+ ## Features
102
+
103
+ - **Verifiable:** every number ships with a proof that anyone can check on-chain.
104
+ - **Fast:** results arrive in your callback within [X] seconds on supported chains.
105
+ - **Predictable cost:** the fee for a request is readable from the contract with `get_fee(callback_gas_limit)`.
106
+ - **Simple to integrate:** one request function, one callback. No off-chain infrastructure to run.
107
+
108
+ ## Supported networks
109
+
110
+ ### Mainnets
111
+ | Network | Contract |
112
+ |---|---|
113
+ | Ethereum | `0x0000000000000000000000000000000000000000` |
114
+ | Arbitrum | `0x0000000000000000000000000000000000000000` |
115
+
116
+ ### Testnets
117
+ | Network | Contract |
118
+ |---|---|
119
+ | Ethereum | `0x492170C151777b7839d9c4cDD58448f0Deca9bcB` |
120
+ | Arbitrum | `0xBfBfcbc03E3A3c40656b23fcfdb96A48232B8C3f` |
121
+
122
+
123
+ ## Security model
124
+
125
+ ABC Entropy relies on a cryptographically secure commit-reveal architecture designed to prevent any single party—including us, the service provider—from predicting, altering, or rigging the final outcome.
126
+
127
+ ### How the Trust Guarantee Works
128
+
129
+ The final random number is derived by combining three independent entropy sources:
130
+
131
+ ```random_number = keccak256(A, B, C)```
132
+
133
+ 1. **Entropy A (The User/dApp):** Your frontend or user supplies their own entropy contribution during the request.
134
+ 2. **Entropy B (The Provider Commitment):** We lock our entropy contribution behind a cryptographic hash before you make a request. Once committed, it is permanently locked and cannot be modified.
135
+ 3. **Entropy C (The Sequencer):** An independent third-party network layer introduces block-level entropy at the moment your dApp makes a request.
136
+
137
+ ### Defending Against Provider Manipulation
138
+
139
+ The core challenge in building a verifiable random number oracle is preventing us from acting as a privileged user within your dApp.
140
+
141
+ ABC Entropy neutralizes this threat through **Entropy C**:
142
+ - Because Entropy C is generated **after** our commitment (but before revealing it) and **after** your dApp request, neither you nor us nor the sequencer can know all A, B and C values in advance.
143
+ - Even though we could know Entropies A and B in advance (by acting as a user), the unpredictable nature of C prevents any pre-calculation or manipulation of the final result.
144
+
145
+ ### Trust Assumptions
146
+
147
+ This security model remains fully tamper-proof as long as the service provider (us) does not control the entity generating Entropy C.
148
+ We mitigate this risk by letting you choose your preferred sequencer from an open list —making it highly unlikely that a single provider controls all available options.
149
+
150
+ ## License
151
+
152
+ MIT © 2026 pulsartronic
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@pulsartronic/entropy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Commit-reveal entropy definitions and interfaces for Solidity",
5
+ "files": [
6
+ "Definitions.sol"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/pulsartronic/entropy.git"
11
+ },
12
+ "keywords": [
13
+ "solidity",
14
+ "ethereum",
15
+ "arbitrum",
16
+ "entropy",
17
+ "randomness",
18
+ "random",
19
+ "rng",
20
+ "commit-reveal"
21
+ ],
22
+ "author": "pulsartronic",
23
+ "license": "MIT"
24
+ }