Skip to content

fix chain fundamentals#129

Open
SIDDHANTCOOKIE wants to merge 1 commit into
feat/cross-contract-callsfrom
fix/architecture-audit-findings
Open

fix chain fundamentals#129
SIDDHANTCOOKIE wants to merge 1 commit into
feat/cross-contract-callsfrom
fix/architecture-audit-findings

Conversation

@SIDDHANTCOOKIE

Copy link
Copy Markdown
Member

Addressed Issues:

Refactor core blockchain consensus, persistence, and smart contract execution

  • Refactor PoW difficulty to use 256-bit integer targets with proportional retargeting arithmetic, improving block time stability.
  • Fix SQLite state persistence to deterministically recalculate current_target and avg_block_time via chain replay on startup.
  • Migrate smart contract execution to an in-process sandbox using sys.settrace gas-metering, removing problematic multiprocessing IPC overhead and resolving deadlocks on Windows.
  • Unban ast.Mult in the smart contract validation whitelist.
  • Backwards compatible parsing for difficulty serialization to prevent legacy block hash mismatches.
  • Update the entire Pytest suite and manually defined targets to correctly reflect 256-bit arithmetic (All 76 tests passing).

Screenshots/Recordings:

TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • main
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: afef6b3d-00b2-4cd4-94e2-88a7a2a897ac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/architecture-audit-findings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Zahnentferner Zahnentferner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR made the difficulty logic significantly more obscure.

Considering MiniChain's educational goal, this obscurity is not desirable.

Also, the difficulty and target are being manipulated in strange ways, with some strange bounds and, apparently, strange handling of some corner cases. It is unclear why. Why can't this be simpler?

Comment thread minichain/chain.py
with self._lock:
chain_list = self.chain
return sum(2 ** (block.difficulty or 1) for block in chain_list)
return sum((1 << 256) // (block.target + 1) for block in chain_list)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 << 256 is a constant number. There is no need to be recalculating it here all the time.

Comment thread minichain/block.py
@@ -72,6 +72,14 @@ def __init__(
if self.receipt_root is None and self.receipts:
self.receipt_root = calculate_receipt_root(self.receipts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be many magic constants in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants