Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f560791
num%chore: drop since base-sdk#27 unused `Hash512`
kwvg Sep 14, 2026
af02f8a
num%refac: strip compile-time constness guarantees from API
kwvg Sep 14, 2026
df76b5f
num%refac: shave dead `ArithInt` and `HashBlob` traits
kwvg Sep 14, 2026
1d87604
num%refac: shave duplicate definitions, inline in trait impls or drop
kwvg Sep 14, 2026
15f45af
num%refac(compact): seal the inner type and tidy the target API
kwvg Sep 14, 2026
db4bf4a
num%refac(hash): replace manual conversion routines with `type_cvrt!`
kwvg Sep 14, 2026
f5643c0
num%refac(hash): replace manual parsing with `hex-conservative`
kwvg Sep 14, 2026
a2e26fa
types%refac: `uint` -> `numeric`,`codec::NumCodec` -> `numeric::Numeric`
kwvg Sep 13, 2026
3b88753
types%refac(numeric): decouple `Numeric` trait with `codec` feature
kwvg Sep 13, 2026
e066bc7
types%refac: restore `enum_map!` usage of `Numeric` for open enums
kwvg Sep 14, 2026
2573eb9
types%feat: extend `Numeric` trait to define base, byte image and `ZERO`
kwvg Sep 14, 2026
8fe4444
num%refac(hash): replace `define_hash!` with a const-generic blob
kwvg Sep 14, 2026
e776b29
num%fix(hash): align whitespace handling with reference impl
kwvg Sep 14, 2026
769cd26
num%refac: reap dead `prelude` module, consolidate `{impl,make}_hash`
kwvg Sep 14, 2026
14cfd7a
num%refac(hash): unify arithmetic and blob types behind `Numeric` trait
kwvg Sep 14, 2026
640c60a
sdk%fix(num): extend `make_hash!` and use it to reflect `Hash160` order
kwvg Sep 14, 2026
b0c151b
types%fix(adapters): render `ScriptHash` like a `Hash160` using `rev`
kwvg Sep 14, 2026
c9eefdf
pkc%fix(bls): use `make_hash!` to treat `BlsShareId` as `Hash256`
kwvg Sep 14, 2026
6a00fa1
sdk%lint(semgrep): discourage `make_bytes!` `rev` directive
kwvg Sep 14, 2026
f85f1de
types%chore: re-export `zeroize` due to usage in public API
kwvg Sep 14, 2026
3cd13ca
num%fix(arith): correct `block_proof` at one and zero
kwvg Sep 14, 2026
66eb099
num%fix(hash): tighten `ParseHexError`'s contract and scope
kwvg Sep 14, 2026
6d21bbf
num%feat: expand hex formatting surface for `HashBlob` and friends
kwvg Sep 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/samples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/samples/solver/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bitcoin_primitives::script::{ScriptPubKeyBuf, ScriptSigBuf};
use bitcoin_units::Amount;
use dash_num::{Arith256, CompactTarget, Hash256};
use dash_primitives::{BlockHash, BlockHeader, MerkleRoot, OutPoint, Transaction, TxHash, TxIn, TxOut, TxType};
use dash_types::codec::Hashable;
use dash_types::{Hashable, Numeric};
use hex_conservative::FromHex;
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn merkle_root(script_sig_hex: &str, script_pubkey_hex: &str, amount_duffs:
let sig_bytes = Vec::<u8>::from_hex(script_sig_hex).map_err(|e| format!("invalid scriptSig hex: {e}"))?;
let pk_bytes = Vec::<u8>::from_hex(script_pubkey_hex).map_err(|e| format!("invalid scriptPubKey hex: {e}"))?;
let coinbase = build_coinbase(sig_bytes, pk_bytes, amount_duffs)?;
let root = MerkleRoot::from_bytes(*coinbase.hash().as_bytes());
let root = MerkleRoot::from_lendian(*coinbase.hash().as_bytes());
Ok(format!("{root}"))
}

Expand All @@ -89,7 +89,7 @@ pub fn scanhash(
let pk_bytes = Vec::<u8>::from_hex(script_pubkey_hex).map_err(|e| format!("invalid scriptPubKey hex: {e}"))?;

let coinbase = build_coinbase(sig_bytes, pk_bytes, amount_duffs)?;
let merkle_root = MerkleRoot::from_bytes(*coinbase.hash().as_bytes());
let merkle_root = MerkleRoot::from_lendian(*coinbase.hash().as_bytes());

let header = BlockHeader {
version,
Expand All @@ -101,7 +101,7 @@ pub fn scanhash(
};
let mut header_buf = encode_to_vec(&header);

let decoded = CompactTarget(bits).decode();
let decoded = CompactTarget::new(bits).expand();
if decoded.negative || decoded.overflow {
return Err("invalid compact target".to_string());
}
Expand Down
32 changes: 24 additions & 8 deletions maint/codeql/rust/lib/imports.qll
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,32 @@ predicate isMacroReexport(Use u) {

/** Holds if `u` is an allowlisted re-export from a foreign crate. */
private predicate isAllowlistedReexport(Use u) {
usePrefix(u) = "dash_types_marker" and
fileOf(u).getAbsolutePath().matches("%pkgs/types/%")
fileOf(u).getAbsolutePath().matches("%pkgs/num/%") and
(
// Crate emits types relying on traits defined by a dependency, part of public API
usePrefix(u) = "dash_types" and
u.getUseTree().getPath().getSegment().getIdentifier().getText() = "Numeric"
)
or
usePrefix(u) = "dash_pkc" and
u.getUseTree().getPath().getSegment().getIdentifier().getText() = "__PubKeyHash" and
fileOf(u).getAbsolutePath().matches("%pkgs/script/%")
fileOf(u).getAbsolutePath().matches("%pkgs/script/%") and
(
// Workaround for the orphan rule, not part of public API
usePrefix(u) = "dash_pkc" and
u.getUseTree().getPath().getSegment().getIdentifier().getText() = "__PubKeyHash"
or
// Workaround for the orphan rule, not part of public API
usePrefix(u) = "dash_types" and
u.getUseTree().getPath().getSegment().getIdentifier().getText() = "__ScriptHash"
)
or
usePrefix(u) = "dash_types" and
u.getUseTree().getPath().getSegment().getIdentifier().getText() = "__ScriptHash" and
fileOf(u).getAbsolutePath().matches("%pkgs/script/%")
fileOf(u).getAbsolutePath().matches("%pkgs/types/%") and
(
// Sub-crate isolation demands re-exports, part of public API
usePrefix(u) = "dash_types_marker"
or
// Crate emits types relying on types or traits defined by a dependency, part of public API
usePrefix(u) = "zeroize"
)
}

/**
Expand Down
8 changes: 4 additions & 4 deletions maint/codeql/rust/lib/policy.qll
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ predicate isUnencodableCrate(File f) {
/** Declaration slots that define the required source ordering. */
newtype TDeclSlot =
TDefinition() or
TNumCodecImpl() or
TNumericImpl() or
TBaseCodecImpl() or
TCheckableImpl() or
THashableImpl() or
Expand All @@ -308,7 +308,7 @@ class DeclSlot extends TDeclSlot {
int getOrder() {
this = TDefinition() and result = 0
or
this = TNumCodecImpl() and result = 1
this = TNumericImpl() and result = 1
or
this = TBaseCodecImpl() and result = 2
or
Expand All @@ -325,7 +325,7 @@ class DeclSlot extends TDeclSlot {
string toString() {
this = TDefinition() and result = "definition"
or
this = TNumCodecImpl() and result = "NumCodec impl"
this = TNumericImpl() and result = "Numeric impl"
or
this = TBaseCodecImpl() and
result = "BaseCodec/Encode/Decode impl"
Expand All @@ -342,7 +342,7 @@ class DeclSlot extends TDeclSlot {

/** Maps a trait name to its declaration slot. */
DeclSlot traitSlot(string traitName) {
traitName = "NumCodec" and result = TNumCodecImpl()
traitName = "Numeric" and result = TNumericImpl()
or
traitName = "BaseCodec" and result = TBaseCodecImpl()
or
Expand Down
2 changes: 1 addition & 1 deletion maint/semgrep/rust/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rules:
- /pkgs/types/src/entity.rs
- /pkgs/types/src/macros.rs
- /pkgs/types/src/secret.rs
- /pkgs/types/src/uint.rs
- /pkgs/types/src/numeric.rs
pattern-regex: '\b(?:make|impl)_(?:bytes|num|type)!\s*[({]'

- id: types-macro-generics-bracketed
Expand Down
16 changes: 16 additions & 0 deletions maint/semgrep/rust/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,19 @@ rules:
include: [/pkgs/**/*.rs, /docs/samples/**/*.rs]
exclude: ["**/lib.rs", "**/mod.rs"]
pattern-regex: '^\s*pub\s+use\s'

- id: bytes-rev-means-hash
message: "dash_types::make_bytes! is not suitable for hash types, use dash_num::make_hash! instead"
severity: ERROR
languages: [rust]
paths:
include: [/pkgs/**/*.rs, /docs/samples/**/*.rs]
exclude:
- /pkgs/types/src/entity.rs # declares the generator
- /pkgs/types/src/secret.rs # declares its secret sibling
pattern-regex: |-
(?x)
\b (?: make | derive ) _ s? bytes ! # a byte-bag generator invocation
\s* [({] # ... opening its arguments
(?: [^\n]* \n ){0,6}? # ... over its doc comment, if any
[^\n]* \b rev \b # ... to the order token's line
7 changes: 6 additions & 1 deletion pkgs/num/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ rust-version.workspace = true

[features]
default = []
std = ["bitcoin-consensus-encoding?/std", "dash-types/std"]
std = [
"bitcoin-consensus-encoding?/std",
"dash-types/std",
"hex-conservative/std",
]
full = ["std", "codec", "serde"]
codec = ["dep:bitcoin-consensus-encoding", "dash-types/codec"]
serde = ["dep:serde", "dash-types/serde"]

[dependencies]
bitcoin-consensus-encoding = { workspace = true, optional = true }
dash-types = { version = "0.0.0", path = "../types", default-features = false }
hex-conservative = { version = "0.3", default-features = false }
serde = { version = "1", default-features = false, features = [
"derive",
"alloc",
Expand Down
Loading