-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: improved tokenomics #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SIDDHANTCOOKIE
wants to merge
5
commits into
feat/timestamp-pow-validation
Choose a base branch
from
feat/improved-tokenomics
base: feat/timestamp-pow-validation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
328d2ce
feat: decouple fee into gas_limit and max_fee_per_gas, configurable g…
SIDDHANTCOOKIE a15d228
fix: address PR review feedback on genesis validation, send CLI, and …
SIDDHANTCOOKIE a521a23
fix: resolve critical mempool, state, and sandbox vulnerabilities
SIDDHANTCOOKIE 505b281
Fix contract timeout on Windows and mempool RBF test fee
SIDDHANTCOOKIE 9854fce
Merge pull request #120 from StabilityNexus/fix/defensive-security
Zahnentferner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,13 +68,20 @@ def _create_genesis_block(self, genesis_path): | |
|
|
||
| # Apply genesis allocations | ||
| alloc = config.get("alloc", {}) | ||
| total_alloc = 0 | ||
| for address, data in alloc.items(): | ||
| balance = data.get("balance", 0) | ||
| if not isinstance(balance, int) or balance < 0: | ||
| logger.error("Invalid genesis balance for %s: %s. Must be a non-negative integer.", address, balance) | ||
| sys.exit(1) | ||
| account = self.state.get_account(address) | ||
| account['balance'] = balance | ||
| total_alloc += balance | ||
|
|
||
| initial_supply = config.get("initial_supply") | ||
| if initial_supply is not None and initial_supply != total_alloc: | ||
| logger.error("Genesis allocation mismatch: initial_supply is %s but alloc sum is %s", initial_supply, total_alloc) | ||
| sys.exit(1) | ||
|
|
||
| self.chain_id = config.get("chain_id", "minichain-default") | ||
| self.state.chain_id = self.chain_id | ||
|
|
@@ -168,7 +175,7 @@ def _apply_block(self, prev_block, block, state, difficulty, avg_block_time): | |
| return status, difficulty, avg_block_time | ||
| receipts.append(receipt) | ||
|
|
||
| total_fees = sum(getattr(r, 'gas_used', 0) for r in receipts) | ||
| total_fees = sum(getattr(r, 'gas_used', 0) * getattr(tx, 'max_fee_per_gas', 0) for r, tx in zip(receipts, block.transactions)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is "max_fee_per_gas" call "max"? It seems that it is just a "fee_per_gas". Isn't it? Isn't the user being charged exactly |
||
| if block.miner: | ||
| state.credit_mining_reward(block.miner, reward=state.DEFAULT_MINING_REWARD + total_fees) | ||
|
|
||
|
|
@@ -214,7 +221,7 @@ def add_block(self, block): | |
|
|
||
| def resolve_conflicts(self, new_chain_list) -> tuple[bool, list]: | ||
| """ | ||
| Evaluates a competing chain. If it has strictly greater cumulative work, | ||
| Evaluates a competing partial or full chain. If it has strictly greater cumulative work, | ||
| attempts a reorg. Rebuilds state from genesis to guarantee validity. | ||
| Returns: (success_bool, list_of_orphaned_transactions) | ||
| """ | ||
|
|
@@ -224,46 +231,54 @@ def resolve_conflicts(self, new_chain_list) -> tuple[bool, list]: | |
| return False, [] | ||
|
|
||
| with self._lock: | ||
| first_block = new_chain_list[0] | ||
| fork_idx = first_block.index | ||
|
|
||
| if fork_idx == 0: | ||
| if first_block.hash != self.chain[0].hash: | ||
| logger.warning("Reorg failed: Genesis hash mismatch.") | ||
| return False, [] | ||
| else: | ||
| if fork_idx > len(self.chain): | ||
| logger.warning("Reorg failed: Partial chain does not connect to our history.") | ||
| return False, [] | ||
| if first_block.previous_hash != self.chain[fork_idx - 1].hash: | ||
| logger.warning("Reorg failed: Partial chain hash mismatch at fork point.") | ||
| return False, [] | ||
|
|
||
| proposed_chain = self.chain[:fork_idx] + new_chain_list | ||
|
|
||
| current_work = self.get_total_work() | ||
| new_work = self.get_total_work(new_chain_list) | ||
| new_work = self.get_total_work(proposed_chain) | ||
|
|
||
| if new_work <= current_work: | ||
| logger.debug("Incoming chain (work: %s) is not heavier than local chain (work: %s). Rejecting.", new_work, current_work) | ||
| return False, [] | ||
|
|
||
| # 1. Verify genesis block matches | ||
| if new_chain_list[0].hash != self.chain[0].hash: | ||
| logger.warning("Reorg failed: Genesis hash mismatch.") | ||
| return False, [] | ||
|
|
||
| logger.info("Incoming chain is heavier (%s > %s). Attempting reorg...", new_work, current_work) | ||
|
|
||
| # 2. Snapshot current chain in case reorg fails validation | ||
| original_chain = list(self.chain) | ||
|
|
||
| # 3. Rebuild state entirely from genesis using the new chain | ||
| temp_state = State() | ||
| temp_state.chain_id = self.chain_id | ||
| temp_state.restore(self._genesis_state_snapshot) | ||
|
|
||
| temp_difficulty = new_chain_list[0].difficulty | ||
| temp_difficulty = proposed_chain[0].difficulty | ||
| temp_avg_block_time = self.target_block_time | ||
|
|
||
| # Verify and apply blocks 1 to N through the shared pipeline | ||
| for i in range(1, len(new_chain_list)): | ||
| for i in range(1, len(proposed_chain)): | ||
| status, temp_difficulty, temp_avg_block_time = self._apply_block( | ||
| new_chain_list[i - 1], new_chain_list[i], temp_state, temp_difficulty, temp_avg_block_time | ||
| proposed_chain[i - 1], proposed_chain[i], temp_state, temp_difficulty, temp_avg_block_time | ||
| ) | ||
| if status != ValidationStatus.VALID: | ||
| logger.warning("Reorg failed at block %s", new_chain_list[i].index) | ||
| logger.warning("Reorg failed at block %s", proposed_chain[i].index) | ||
| return False, [] | ||
|
|
||
| # 4. Success! Compute orphaned transactions. | ||
| old_txs = {tx.tx_id: tx for b in original_chain[1:] for tx in b.transactions} | ||
| new_tx_ids = {tx.tx_id for b in new_chain_list[1:] for tx in b.transactions} | ||
| new_tx_ids = {tx.tx_id for b in proposed_chain[1:] for tx in b.transactions} | ||
| orphans = [tx for tx_id, tx in old_txs.items() if tx_id not in new_tx_ids] | ||
|
|
||
| self.chain = new_chain_list | ||
| self.chain = proposed_chain | ||
| self.state = temp_state | ||
| self.current_difficulty = temp_difficulty | ||
| self.avg_block_time = temp_avg_block_time | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Wire
initial_supplyinto genesis loading or remove it.minichain/chain.pystill initializes balances fromalloconly, so this new top-level field has no runtime effect and can mislead operators about the actual genesis issuance.🤖 Prompt for AI Agents