VegaSec / Solidity scan report

bad-randomness-blackjack.sol

VSS-20261003-U2NB6NB6 · generated Oct 3, 2026, 7:53 PM

Clear surface · automated21 findings2 highPasted sourcesemgrep 1.163.0

Verdict is derived from severity counts via the same deterministic formula every VegaSec report uses. bad-randomness-blackjack.sol was scanned from pasted source. This is static-analysis triage, not a certification or formal audit attestation.

Signature

signed

This report is signed. Anyone can verify that these exact bytes came from us, with no account, no wallet and no API key. The signature proves integrity and authorship. It does not prove the audited contract is safe: read the coverage status and the limitations above.

sha256
7a4de5176b077375...d6acd6de
Signed by
Ed25519 key vsig-2026-09
Canonical version
vss-canonical-1
Bytes served
stored canonical text, byte for byte

PDF artifact

Queued artifact pipeline · not blocking on the scan

Not requested

No PDF artifact has been requested for this report yet. The HTML report and the Markdown export already carry the full disclaimer and limitations inline. PDF synthesis is a queued artifact, not part of the scan path.

Status endpoint

GET /report/solidity/VSS-20261003-U2NB6NB6/export.pdf

Solidity evidence report

21 audit findings

critical: 0high: 2medium: 0low: 0informational: 19

Severity distribution

Executive summary

  • 21 findings surfaced (0 critical, 2 high, 0 medium, 0 low, 19 informational).
  • HIGH · Deck.deal(address,uint8) (bad-randomness-blackjack.sol#15-22) uses a weak PRNG: "uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52 (deal) — exploitability medium.
  • HIGH · BlackJack (bad-randomness-blackjack.sol#45-308) contract sets array length with a user-controlled value: (BlackJack) — exploitability medium.
  • Automated static analysis only. A human operator review has not been attached to this report.
semgrep 1.163.0
  • highOracle manipulationConfidence: mediumExploitability: mediumDetector: slither

    Deck.deal(address,uint8) (bad-randomness-blackjack.sol#15-22) uses a weak PRNG: "uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52

    Affected location
    bad-randomness-blackjack.sol:15-22 · deal
    Detector / source
    slither · slither:weak-prng

    Evidence

    Deck.deal(address,uint8) (bad-randomness-blackjack.sol#15-22) uses a weak PRNG: "uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52) (bad-randomness-blackjack.sol#21)"

    Exploitability notes

    Medium-confidence detection; manual review required before relying on the finding either way.

    Remediation

    Use multi-source price feeds (e.g. Chainlink + TWAPs) and validate freshness/deviation before consuming oracle data on-chain.

    Limitations

    • Medium analyzer confidence; manual review should confirm the code path and preconditions.
    • Exploitability depends on deployment context, permissions, balances, and reachable preconditions.
    • Analyzer output did not include a source excerpt for this finding.
  • highGas / DoSConfidence: mediumExploitability: mediumDetector: slither

    BlackJack (bad-randomness-blackjack.sol#45-308) contract sets array length with a user-controlled value:

    Affected location
    bad-randomness-blackjack.sol:45-308 · BlackJack
    Detector / source
    slither · slither:controlled-array-length

    Evidence

    BlackJack (bad-randomness-blackjack.sol#45-308) contract sets array length with a user-controlled value: - games[msg.sender].houseCards.push(newCard) (bad-randomness-blackjack.sol#149)

    Exploitability notes

    Medium-confidence detection; manual review required before relying on the finding either way.

    Remediation

    Cap loop bounds, paginate iteration, and ensure no user can grow a state structure the contract must traverse to make progress.

    Limitations

    • Medium analyzer confidence; manual review should confirm the code path and preconditions.
    • Exploitability depends on deployment context, permissions, balances, and reachable preconditions.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Version constraint ^0.4.9 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)

    Affected location
    bad-randomness-blackjack.sol:8 · ^0.4.9
    Detector / source
    slither · slither:solc-version

    Evidence

    Version constraint ^0.4.9 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html) - DirtyBytesArrayToStorage - KeccakCaching - EmptyByteArrayCopy - DynamicArrayCleanup - ImplicitConstructorCallvalueCheck - TupleAssignmentMultiStackSlotComponents - MemoryArrayCreationOverflow - privateCanBeOverridden - SignedArrayStorageCopy - UninitializedFunctionPointerInConstructor_0.4.x - IncorrectEventSignatureInLibraries_0.4.x - ExpExponentCleanup - NestedArrayFunctionCallDecoder - ZeroFunctionSelector - DelegateCallReturnValue - ECRecoverMalformedInput - SkipEmptyStringLiteral - ConstantOptimizerSubtraction. It is used by: - ^0.4.9 (bad-randomness-blackjack.sol#8)

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52) (bad-randomness-blackjack.sol#21):

    Affected location
    bad-randomness-blackjack.sol:21 · uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52)
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected uint8(uint256(keccak256()(block.blockhash(b),player,cardNumber,timestamp)) % 52) (bad-randomness-blackjack.sol#21): - Usage of "block.blockhash()" should be replaced with "blockhash()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    BlackJack.minBet (bad-randomness-blackjack.sol#48) should be constant

    Affected location
    bad-randomness-blackjack.sol:48 · minBet
    Detector / source
    slither · slither:constable-states

    Evidence

    BlackJack.minBet (bad-randomness-blackjack.sol#48) should be constant

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    BlackJack.maxBet (bad-randomness-blackjack.sol#49) should be constant

    Affected location
    bad-randomness-blackjack.sol:49 · maxBet
    Detector / source
    slither · slither:constable-states

    Evidence

    BlackJack.maxBet (bad-randomness-blackjack.sol#49) should be constant

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    BlackJack.BLACKJACK (bad-randomness-blackjack.sol#51) should be constant

    Affected location
    bad-randomness-blackjack.sol:51 · BLACKJACK
    Detector / source
    slither · slither:constable-states

    Evidence

    BlackJack.BLACKJACK (bad-randomness-blackjack.sol#51) should be constant

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Variable BlackJack.BLACKJACK (bad-randomness-blackjack.sol#51) is not in mixedCase

    Affected location
    bad-randomness-blackjack.sol:51 · BLACKJACK
    Detector / source
    slither · slither:naming-convention

    Evidence

    Variable BlackJack.BLACKJACK (bad-randomness-blackjack.sol#51) is not in mixedCase

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#70):

    Affected location
    bad-randomness-blackjack.sol:70
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#70): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#102):

    Affected location
    bad-randomness-blackjack.sol:102
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#102): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#106):

    Affected location
    bad-randomness-blackjack.sol:106
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#106): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalReentrancyConfidence: mediumExploitability: lowDetector: slither

    Reentrancy in BlackJack.checkGameResult(BlackJack.Game,bool) (bad-randomness-blackjack.sol#159-247):

    Affected location
    bad-randomness-blackjack.sol:159-247 · checkGameResult
    Detector / source
    slither · slither:reentrancy-unlimited-gas

    Evidence

    Reentrancy in BlackJack.checkGameResult(BlackJack.Game,bool) (bad-randomness-blackjack.sol#159-247): External calls: - ! msg.sender.send(game.bet * 2) (bad-randomness-blackjack.sol#240) State variables written after the call(s): - games[msg.sender].state = GameState.Player (bad-randomness-blackjack.sol#241)

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Apply the checks-effects-interactions pattern. State writes must happen before external calls, and consider OpenZeppelin's ReentrancyGuard for high-risk entry points.

    Limitations

    • Medium analyzer confidence; manual review should confirm the code path and preconditions.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#170):

    Affected location
    bad-randomness-blackjack.sol:170
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#170): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#183):

    Affected location
    bad-randomness-blackjack.sol:183
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#183): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#186):

    Affected location
    bad-randomness-blackjack.sol:186
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#186): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#223):

    Affected location
    bad-randomness-blackjack.sol:223
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#223): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#236):

    Affected location
    bad-randomness-blackjack.sol:236
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#236): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#240):

    Affected location
    bad-randomness-blackjack.sol:240
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#240): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#268):

    Affected location
    bad-randomness-blackjack.sol:268
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#268): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#275):

    Affected location
    bad-randomness-blackjack.sol:275
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#275): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.
  • informationalLogicConfidence: highExploitability: lowDetector: slither

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#290):

    Affected location
    bad-randomness-blackjack.sol:290
    Detector / source
    slither · slither:deprecated-standards

    Evidence

    Deprecated standard detected THROW (bad-randomness-blackjack.sol#290): - Usage of "throw" should be replaced with "revert()"

    Exploitability notes

    Informational signal; not directly exploitable without additional context.

    Remediation

    Re-derive the business rule by hand, write a property-based test that fails on the current path, and only then fix the implementation.

    Limitations

    • High analyzer confidence, still requires source-level review before promotion.
    • Direct exploitability is not established; keep the signal as a remediation/checklist item.
    • Analyzer output did not include a source excerpt for this finding.

Limitations

  • VegaSec runs static analysis only. Findings can include false positives, miss patterns the configured detectors do not cover, and never replace manual auditor judgement.
  • Scan ran slither and semgrep against a single sandboxed copy of the source. Multi-file dependency analysis beyond what slither resolves automatically is out of scope.
  • This report is not a certification, audit attestation, or financial advice.

Exploit reasoning

Reference-grade reasoning tied to evidence

  • 77561c06740e0877399a1f58d78ab8d9754526920887642439da28c13a474936 · oracle-manipulationhigh
    Confidence: low

    Conditions point at the exploit but at least one precondition needs operator confirmation.

    Preconditions

    • Price or rate read from an on-chain source that can be moved in the same block by the caller
    • Decisions (mint amount, collateral check) derived from the manipulable price

    Action

    Attacker uses a flash loan or large swap to move the oracle price in the same block, triggers the price-dependent action, then reverts the price.

    Impact

    Mint of more shares than collateral warrants, undercollateralized borrow, or theft of liquidity by exploiting the manipulated rate.

    False-positive caveats

    • The oracle may be a time-weighted aggregator that resists single-block movement.
    • The function may compare against a snapshot taken on a separate block.

    Remediation checklist

    • Use a TWAP (time-weighted average price) over multiple blocks.
    • Cross-check at least two independent oracle sources before acting.
    • Reject prices that diverge from a recent average by more than a documented threshold.
  • 28fd5ca69c8dc9f8ea41a5c9a7472ea30a59df5829272801b3d5e0cc58ab3837 · gas-doshigh
    Confidence: low

    Conditions point at the exploit but at least one precondition needs operator confirmation.

    Preconditions

    • Loop over an unbounded data structure controlled by external input
    • Single attacker-controlled entry that grows the data structure

    Action

    Attacker grows the data structure until the loop consumes more gas than the block can hold, blocking the function for everyone.

    Impact

    Permanent denial of service on critical functions (withdrawals, claim, settle).

    False-positive caveats

    • The loop may be bounded by other invariants the analyzer cannot prove.
    • Pagination or pull-based design may mitigate the issue at a higher layer.

    Remediation checklist

    • Replace the unbounded loop with a pull-based or paginated pattern.
    • Cap the data structure growth at the entry point with a documented limit.
    • Add a stress test asserting the loop terminates under adversarial input.

Audit pipeline

Audit cockpit

Honest stage-by-stage view of what VegaSec ran against this contract. Automated stages do not replace a human operator review.

Passed: 5Partial: 3Blocked: 1
  1. Audit intake

    Passed320ms replay7:53 PM

    Normalize the submitted contract target and confirm it can enter the Solidity audit lane.

    Next: Acquire verified source or scan the pasted Solidity source.

  2. Source acquisition

    Passed1.4s replay7:53 PM

    Resolve pasted source or verified explorer source without treating malformed input as demo data.

    Next: Validate the analyzer toolchain against the acquired source.

  3. Toolchain validation

    Passed2.3s replay7:53 PM

    Confirm the configured static analyzers can run and produce parseable output.

    Next: Run static analysis and capture raw detector evidence.

  4. Static analysis

    Passed21 findings8.8s replay7:53 PM

    Run static analyzers against the sandboxed source and collect raw detector evidence.

    Next: Normalize detector output into one deduped finding set.

  5. Finding normalization

    Passed21 findings1.1s replay7:53 PM

    Dedupe detectors, classify vulnerability classes and compute severity-weighted risk.

    Next: Review exploitability conservatively against confidence and limitations.

  6. Exploitability review

    Partial21 findings1.9s replay7:53 PM

    Frame automated findings with conservative exploitability and limitation notes.

    Next: Draft remediation notes from the normalized evidence.

    • Automated exploitability review is conservative and does not replace a manual exploitability assessment.
  7. Remediation draft

    Partial21 findings1.5s replay7:53 PM

    Prepare remediation-oriented evidence for the shareable report artifact.

    Next: Attach an operator review artifact before claiming human review.

    • Remediation notes are generated from detector evidence and require project-specific engineering review.
  8. Operator review

    Blocked0ms replay7:53 PM

    Record whether a human operator artifact exists before buyer escalation.

    Next: Attach a real operator review artifact before claiming human review.

    • No operator review artifact is attached to this automated scan.
    • Human operator review has not been attached to this automated scan yet.
  9. Finalization

    Partial21 findings620ms replay7:53 PM

    Publish the automated report artifact or explain why the scan failed closed.

    Next: Share the report with explicit limitations and review state.

    Artifact: Automated Solidity report · solidity-2f746d702f766567

    • Final report is an automated static-analysis artifact; no operator review artifact is attached.

Report badges

Verified source

Badges describe the evidence carried by this report artifact, not financial value or future pricing. Operator-reviewed is never granted automatically.

How to read this report

Score, confidence, ranking: four moving parts, no hand-tuning.

Generated Oct 3, 2026, 7:53 PM · Solidity · bad-randomness-blackjack.sol

Score bands

  • 0-19

    AVOID-style triage

    Multiple high or critical findings, low source confidence, or unverified context. Public action should pause until a Private Review or a re-scan with better evidence.

  • 20-49

    High caution

    Notable findings or thin evidence. Worth a Private Review before relying on the artifact.

  • 50-69

    Watch

    Mixed signals: some evidence, some gaps. Re-scan after material changes to the target.

  • 70-89

    Clear surface (automated) · this report

    No critical or high findings via static analysis. Not a safety claim: human review is still recommended for diligence work.

  • 90-100

    Strong surface (automated)

    No critical or high findings, verified source, and high source confidence. Not a safety claim: human review is still recommended for diligence work.

Score
Deterministic 0-100 derived from severity counts. Same formula across every report. Lower means more risk.
Confidence
Separate axis. Measures how much VegaSec trusts the input data. Low confidence pushes the verdict toward UNKNOWN; the two are never collapsed into one number.
Ranking / percentile
Only meaningful within the eligible Trust Index set. Shown on /trust-index when the eligible pool is large enough. Today the public index is a controlled preview.

Private Review is separate

A paid Private Review does not raise the public score on this report. Public score reflects public-source evidence only. Private Review adds operator attestation and a confidential memo, never a score bump.

Export and share

  • · Shareable public URL: copy from the report actions panel.
  • · Markdown export: every export carries the report id, target, verdict, generated timestamp, and the public-data disclaimer.
  • · PDF export: not in this MVP. Tracked as a follow-up. The Markdown export contains the same content and prints cleanly to PDF from a browser today.

Source provenance

This report scanned a Solidity source provided directly by the submitter (paste). No on-chain address is associated.

Scanned source (8,537 chars)

/*
 * @article: https://blog.positive.com/predicting-random-numbers-in-ethereum-smart-contracts-e5358c6b8620
 * @source: https://etherscan.io/address/0xa65d59708838581520511d98fb8b5d1f76a96cad#code
 * @vulnerable_at_lines: 17,19,21
 * @author: -
 */

 pragma solidity ^0.4.9;

library Deck {
	// returns random number from 0 to 51
	// let's say 'value' % 4 means suit (0 - Hearts, 1 - Spades, 2 - Diamonds, 3 - Clubs)
	//			 'value' / 4 means: 0 - King, 1 - Ace, 2 - 10 - pip values, 11 - Jacket, 12 - Queen

	function deal(address player, uint8 cardNumber) internal returns (uint8) {
		// <yes> <report> BAD_RANDOMNESS
		uint b = block.number;
		// <yes> <report> BAD_RANDOMNESS
		uint timestamp = block.timestamp;
		// <yes> <report> BAD_RANDOMNESS
		return uint8(uint256(keccak256(block.blockhash(b), player, cardNumber, timestamp)) % 52);
	}

	function valueOf(uint8 card, bool isBigAce) internal constant returns (uint8) {
		uint8 value = card / 4;
		if (value == 0 || value == 11 || value == 12) { // Face cards
			return 10;
		}
		if (value == 1 && isBigAce) { // Ace is worth 11
			return 11;
		}
		return value;
	}

	function isAce(uint8 card) internal constant returns (bool) {
		return card / 4 == 1;
	}

	function isTen(uint8 card) internal constant returns (bool) {
		return card / 4 == 10;
	}
}


contract BlackJack {
	using Deck for *;

	uint public minBet = 50 finney; // 0.05 eth
	uint public maxBet = 5 ether;

	uint8 BLACKJACK = 21;

  enum GameState { Ongoing, Player, Tie, House }

	struct Game {
		address player; // address игрока
		uint bet; // стывка

		uint8[] houseCards; // карты диллера
		uint8[] playerCards; // карты игрока

		GameState state; // состояние
		uint8 cardsDealt;
	}

	mapping (address => Game) public games;

	modifier gameIsGoingOn() {
		if (games[msg.sender].player == 0 || games[msg.sender].state != GameState.Ongoing) {
			throw; // game doesn't exist or already finished
		}
		_;
	}

	event Deal(
        bool isUser,
        uint8 _card
    );

    event GameStatus(
    	uint8 houseScore,
    	uint8 houseScoreBig,
    	uint8 playerScore,
    	uint8 playerScoreBig
    );

    event Log(
    	uint8 value
    );

	function BlackJack() {

	}

	function () payable {

	}

	// starts a new game
	function deal() public payable {
		if (games[msg.sender].player != 0 && games[msg.sender].state == GameState.Ongoing) {
			throw; // game is already going on
		}

		if (msg.value < minBet || msg.value > maxBet) {
			throw; // incorrect bet
		}

		uint8[] memory houseCards = new uint8[](1);
		uint8[] memory playerCards = new uint8[](2);

		// deal the cards
		playerCards[0] = Deck.deal(msg.sender, 0);
		Deal(true, playerCards[0]);
		houseCards[0] = Deck.deal(msg.sender, 1);
		Deal(false, houseCards[0]);
		playerCards[1] = Deck.deal(msg.sender, 2);
		Deal(true, playerCards[1]);

		games[msg.sender] = Game({
			player: msg.sender,
			bet: msg.value,
			houseCards: houseCards,
			playerCards: playerCards,
			state: GameState.Ongoing,
			cardsDealt: 3
		});

		checkGameResult(games[msg.sender], false);
	}

	// deals one more card to the player
	function hit() public gameIsGoingOn {
		uint8 nextCard = games[msg.sender].cardsDealt;
		games[msg.sender].playerCards.push(Deck.deal(msg.sender, nextCard));
		games[msg.sender].cardsDealt = nextCard + 1;
		Deal(true, games[msg.sender].playerCards[games[msg.sender].playerCards.length - 1]);
		checkGameResult(games[msg.sender], false);
	}

	// finishes the game
	function stand() public gameIsGoingOn {

		var (houseScore, houseScoreBig) = calculateScore(games[msg.sender].houseCards);

		while (houseScoreBig < 17) {
			uint8 nextCard = games[msg.sender].cardsDealt;
			uint8 newCard = Deck.deal(msg.sender, nextCard);
			games[msg.sender].houseCards.push(newCard);
			games[msg.sender].cardsDealt = nextCard + 1;
			houseScoreBig += Deck.valueOf(newCard, true);
			Deal(false, newCard);
		}

		checkGameResult(games[msg.sender], true);
	}

	// @param finishGame - whether to finish the game or not (in case of Blackjack the game finishes anyway)
	function checkGameResult(Game game, bool finishGame) private {
		// calculate house score
		var (houseScore, houseScoreBig) = calculateScore(game.houseCards);
		// calculate player score
		var (playerScore, playerScoreBig) = calculateScore(game.playerCards);

		GameStatus(houseScore, houseScoreBig, playerScore, playerScoreBig);

		if (houseScoreBig == BLACKJACK || houseScore == BLACKJACK) {
			if (playerScore == BLACKJACK || playerScoreBig == BLACKJACK) {
				// TIE
				if (!msg.sender.send(game.bet)) throw; // return bet to the player
				games[msg.sender].state = GameState.Tie; // finish the game
				return;
			} else {
				// HOUSE WON
				games[msg.sender].state = GameState.House; // simply finish the game
				return;
			}
		} else {
			if (playerScore == BLACKJACK || playerScoreBig == BLACKJACK) {
				// PLAYER WON
				if (game.playerCards.length == 2 && (Deck.isTen(game.playerCards[0]) || Deck.isTen(game.playerCards[1]))) {
					// Natural blackjack => return x2.5
					if (!msg.sender.send((game.bet * 5) / 2)) throw; // send prize to the player
				} else {
					// Usual blackjack => return x2
					if (!msg.sender.send(game.bet * 2)) throw; // send prize to the player
				}
				games[msg.sender].state = GameState.Player; // finish the game
				return;
			} else {

				if (playerScore > BLACKJACK) {
					// BUST, HOUSE WON
					Log(1);
					games[msg.sender].state = GameState.House; // finish the game
					return;
				}

				if (!finishGame) {
					return; // continue the game
				}

                // недобор
				uint8 playerShortage = 0;
				uint8 houseShortage = 0;

				// player decided to finish the game
				if (playerScoreBig > BLACKJACK) {
					if (playerScore > BLACKJACK) {
						// HOUSE WON
						games[msg.sender].state = GameState.House; // simply finish the game
						return;
					} else {
						playerShortage = BLACKJACK - playerScore;
					}
				} else {
					playerShortage = BLACKJACK - playerScoreBig;
				}

				if (houseScoreBig > BLACKJACK) {
					if (houseScore > BLACKJACK) {
						// PLAYER WON
						if (!msg.sender.send(game.bet * 2)) throw; // send prize to the player
						games[msg.sender].state = GameState.Player;
						return;
					} else {
						houseShortage = BLACKJACK - houseScore;
					}
				} else {
					houseShortage = BLACKJACK - houseScoreBig;
				}

                // ?????????????????????? почему игра заканчивается?
				if (houseShortage == playerShortage) {
					// TIE
					if (!msg.sender.send(game.bet)) throw; // return bet to the player
					games[msg.sender].state = GameState.Tie;
				} else if (houseShortage > playerShortage) {
					// PLAYER WON
					if (!msg.sender.send(game.bet * 2)) throw; // send prize to the player
					games[msg.sender].state = GameState.Player;
				} else {
					games[msg.sender].state = GameState.House;
				}
			}
		}
	}

	function calculateScore(uint8[] cards) private constant returns (uint8, uint8) {
		uint8 score = 0;
		uint8 scoreBig = 0; // in case of Ace there could be 2 different scores
		bool bigAceUsed = false;
		for (uint i = 0; i < cards.length; ++i) {
			uint8 card = cards[i];
			if (Deck.isAce(card) && !bigAceUsed) { // doesn't make sense to use the second Ace as 11, because it leads to the losing
				scoreBig += Deck.valueOf(card, true);
				bigAceUsed = true;
			} else {
				scoreBig += Deck.valueOf(card, false);
			}
			score += Deck.valueOf(card, false);
		}
		return (score, scoreBig);
	}

	function getPlayerCard(uint8 id) public gameIsGoingOn constant returns(uint8) {
		if (id < 0 || id > games[msg.sender].playerCards.length) {
			throw;
		}
		return games[msg.sender].playerCards[id];
	}

	function getHouseCard(uint8 id) public gameIsGoingOn constant returns(uint8) {
		if (id < 0 || id > games[msg.sender].houseCards.length) {
			throw;
		}
		return games[msg.sender].houseCards[id];
	}

	function getPlayerCardsNumber() public gameIsGoingOn constant returns(uint) {
		return games[msg.sender].playerCards.length;
	}

	function getHouseCardsNumber() public gameIsGoingOn constant returns(uint) {
		return games[msg.sender].houseCards.length;
	}

	function getGameState() public constant returns (uint8) {
		if (games[msg.sender].player == 0) {
			throw; // game doesn't exist
		}

		Game game = games[msg.sender];

		if (game.state == GameState.Player) {
			return 1;
		}
		if (game.state == GameState.House) {
			return 2;
		}
		if (game.state == GameState.Tie) {
			return 3;
		}

		return 0; // the game is still going on
	}

}

Public-data disclaimer

Solidity scans are triage based on slither + semgrep static analysis. Output is not a certification, audit attestation or financial advice. Findings can include false positives and may miss patterns the configured detectors do not cover.