Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9407adb
ci: bump actions/checkout to v5 (#338)
rejected-l Aug 19, 2025
94d596d
fix #348 (#349)
lynndell2010 Oct 9, 2025
c3b0e66
fix #350 (#351)
lynndell2010 Oct 9, 2025
cc57122
fix #363 Insufficient validation of generated hints (#364)
lynndell2010 Oct 9, 2025
d7f53c2
add validation of num of mocked segments (#374)
wz14 Oct 9, 2025
5de23a8
[Zellic Audit] Hash Bug (Mark 3 09.07) (#316)
wz14 Oct 9, 2025
a2195dc
Zellic Audit G1 fixes (#334)
sevkett12 Oct 9, 2025
0b398a4
[Zellic Audit] Tonelli Shanks and Compute_c_wi (#368)
sevkett12 Oct 9, 2025
e277e89
[Zellic Audit] fix fq6_hinted_mul_keep_elements (#339)
sevkett12 Oct 9, 2025
9f2a42a
[Zellic Audit] 3.19 MSM segments drop too many elements on invalid in…
sevkett12 Oct 9, 2025
2dea02f
[Zellic Audit] 3.26 Empty stack check for BLAKE3 (#370)
just-erray Oct 9, 2025
358d00f
extend scalar validity checks to each index (#372)
just-erray Oct 9, 2025
4fbead3
remove fp254impl::is_field (#378)
Hakkush-07 Oct 9, 2025
794c593
Fq::mul_by_constant now works more efficiently when constant is 1 or …
Hakkush-07 Oct 9, 2025
3d8e467
fix incorrect wrappers for tmul (#385)
Hakkush-07 Oct 9, 2025
1bf2bf5
[Zellic Audit] 3.38 Leftover values on altstack in utils_fq12_square …
Hakkush-07 Oct 9, 2025
1261ddc
change logic to expect hint rounded down in tmul (#384)
Hakkush-07 Oct 9, 2025
880bde5
change Self::N_LIMBS to T::LIMBS in tmul where it is used incorrectly…
Hakkush-07 Oct 9, 2025
dd271c2
[Zellic Audit] 3.27 Blake3 script is incorrect (#390)
Hakkush-07 Oct 9, 2025
60325db
change LC_BITS in tmul (#382)
Hakkush-07 Oct 9, 2025
5ee432c
assert window is not 1 in tmul init_table (#381)
Hakkush-07 Oct 9, 2025
b7a2229
add BigInt::double_prevent_overflow_keep_element and use it in tmul i…
Hakkush-07 Oct 9, 2025
fc89d9c
fix limb_add and limb_double issues (#327)
Hakkush-07 Oct 9, 2025
5691068
create BigInt::neg function for optimization purposes, use it in tmul…
Hakkush-07 Oct 9, 2025
19996d5
Fix altstack overflow in verify_digits for fixed-point edge case (#318)
KSlashh Oct 9, 2025
04df2bd
[Zellic Audit] Winternitz Fixes (#337)
just-erray Oct 9, 2025
525c08c
[Zellic Audit] 3.4 Computational hint types not validated (#387)
Hakkush-07 Oct 10, 2025
f9e11ba
[Zellic Audit] fix fp254impl issues (#328)
Hakkush-07 Oct 10, 2025
d2a4bb4
Clear Part1 Report (#300)
Hakkush-07 Oct 10, 2025
dda579f
[Zellic Audit] 3.2 3.3 (#393)
just-erray Oct 30, 2025
a977a21
[Zellic Audit] 3.12 Incomplete handling of G1 point addition (#379)
Hakkush-07 Nov 11, 2025
e728157
Merge remote-tracking branch 'bitvm/main' into v2
KSlashh Nov 21, 2025
7b31dfd
fix merge conficts
KSlashh Nov 21, 2025
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
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
timeout-minutes: 60
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Run rustfmt
run: cargo fmt --all -- --check

Expand All @@ -24,7 +24,7 @@ jobs:
timeout-minutes: 60
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Run clippy (no guests)
run: cargo clippy --workspace --exclude header-chain-circuit --exclude final-spv-circuit

Expand All @@ -34,7 +34,7 @@ jobs:
timeout-minutes: 60
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Build guests
run: |
REPR_GUEST_BUILD=1 BITCOIN_NETWORK=mainnet cargo build -p header-chain-circuit --release
Expand All @@ -46,7 +46,7 @@ jobs:
timeout-minutes: 60
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Cache Build Artifacts
uses: actions/cache@v4
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
hash::blake3::tests::test_blake3_randominputs
hash::blake3::tests::test_blake3_randominputs_multipleof64bytes
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Cache Build Artifacts
uses: actions/cache@v4
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
# needs: build
# runs-on: self-hosted
# steps:
# - uses: actions/checkout@v4
# - uses: actions/checkout@v5
#
# - name: Cache Build Artifacts
# uses: actions/cache@v4
Expand Down
78 changes: 72 additions & 6 deletions bitvm/src/bigint/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ impl<const N_BITS: u32, const LIMB_SIZE: u32> BigIntImpl<N_BITS, LIMB_SIZE> {
}
}

/// add one
pub fn add1() -> Script {
script! {
OP_1ADD // a0 ... an
{ 1 << LIMB_SIZE } // a0 ... an x
OP_SWAP // a0 ... x an
for _ in 0..Self::N_LIMBS-1 { // ... x a
OP_2DUP // ... x a x a
OP_EQUAL // ... x a 0/1
OP_TUCK // ... x 0/1 a 0/1
OP_IF OP_NOT OP_ENDIF // ... x 0/1 a/0
OP_TOALTSTACK // ... x 0/1
OP_ROT // .. x 0/1 a_{i-1}
OP_ADD // .. x a'
}
// x a0
OP_NIP // a0
{ Self::HEAD_OFFSET } // a0 y
OP_OVER // a0 y a0
OP_EQUAL // a0 0/1
OP_IF OP_NOT OP_ENDIF // a/0

for _ in 0..Self::N_LIMBS - 1 {
OP_FROMALTSTACK
}
}
}

/// Double the BigInt on top of the stack
///
/// # Note
Expand Down Expand Up @@ -98,15 +126,15 @@ impl<const N_BITS: u32, const LIMB_SIZE: u32> BigIntImpl<N_BITS, LIMB_SIZE> {
{ 1 << LIMB_SIZE }

// Double the limb, take the result to the alt stack, and add initial carry
{ n + 1 } OP_PICK limb_double_without_carry OP_TOALTSTACK
{ n * Self::N_LIMBS + 1 } OP_PICK limb_double_without_carry OP_TOALTSTACK

for i in 0..Self::N_LIMBS - 2 {
{ n + i + 3 } OP_PICK limb_double_with_carry OP_TOALTSTACK
{ n * Self::N_LIMBS + i + 3 } OP_PICK limb_double_with_carry OP_TOALTSTACK
}

// When we got {limb} {base} {carry} on the stack, we drop the base
OP_NIP // {limb} {carry}
{ n + 9 } OP_PICK { limb_double_with_carry_allow_overflow(Self::HEAD_OFFSET) }
{ n * Self::N_LIMBS + Self::N_LIMBS } OP_PICK { limb_double_with_carry_allow_overflow(Self::HEAD_OFFSET) }

// Take all limbs from the alt stack to the main stack
for _ in 0..Self::N_LIMBS - 1 {
Expand Down Expand Up @@ -144,6 +172,25 @@ impl<const N_BITS: u32, const LIMB_SIZE: u32> BigIntImpl<N_BITS, LIMB_SIZE> {
}
}

/// Double the referenced BigInt but keep the original element in its position
/// This function prevents overflow of the underlying integer types during
/// doubling operation.
pub fn double_prevent_overflow_keep_element(n: u32) -> Script {
script! {
{ 1 << LIMB_SIZE }
{ n * Self::N_LIMBS + 1 } OP_PICK limb_double_without_carry OP_TOALTSTACK
for i in 0..Self::N_LIMBS - 2 {
{ n * Self::N_LIMBS + i + 3 } OP_PICK limb_double_with_carry OP_TOALTSTACK
}
OP_NIP
{ n * Self::N_LIMBS + Self::N_LIMBS } OP_PICK OP_SWAP
{ limb_double_with_carry_prevent_overflow(Self::HEAD_OFFSET) }
for _ in 0..Self::N_LIMBS - 1 {
OP_FROMALTSTACK
}
}
}

/// Left shift the BigInt on top of the stack by `bits`
///
/// # Note
Expand Down Expand Up @@ -234,7 +281,7 @@ impl<const N_BITS: u32, const LIMB_SIZE: u32> BigIntImpl<N_BITS, LIMB_SIZE> {

OP_NIP
{ b_depth + 1 } OP_PICK
OP_ROT
OP_SWAP
{ limb_add_with_carry_prevent_overflow(Self::HEAD_OFFSET) }

for _ in 0..Self::N_LIMBS - 1 {
Expand Down Expand Up @@ -361,7 +408,7 @@ fn limb_add_with_carry_prevent_overflow(head_offset: u32) -> Script {
OP_2SWAP // {a+b+c_nlo} {x} {a} {sign_b} {a+b+c_nlo} {x}
OP_GREATERTHANOREQUAL // {a+b+c_nlo} {x} {a} {sign_b} {I:0/1}
OP_2SWAP // {a+b+c_nlo} {sign_b} {I:0/1} {x} {a}
OP_GREATERTHANOREQUAL // {a+b+c_nlo} {sign_b} {I:0/1} {sign_a}
OP_GREATERTHAN // {a+b+c_nlo} {sign_b} {I:0/1} {sign_a}
OP_ADD OP_ADD 1 3 OP_WITHIN OP_VERIFY // verify (sign_a, sign_b, I) is not (0, 0, 0) or (1, 1, 1) which would mean overflow
}
}
Expand Down Expand Up @@ -417,7 +464,7 @@ fn limb_double_with_carry_prevent_overflow(head_offset: u32) -> Script {
OP_TUCK OP_DUP OP_ADD // {a} {x} {2a+c} {2x}
OP_2DUP OP_GREATERTHANOREQUAL // {a} {x} {2a+c} {2x} {L:0/1}
OP_NOTIF OP_NOT OP_ENDIF OP_SUB // {a} {x} {2a+c_nlo}
OP_2DUP OP_LESSTHAN // {a} {x} {2a+c_nlo} {I:0/1}
OP_2DUP OP_LESSTHANOREQUAL // {a} {x} {2a+c_nlo} {I:0/1}
OP_2SWAP // {2a+c_nlo} {I:0/1} {a} {x}
OP_LESSTHAN // {2a+c_nlo} {I:0/1} {sign_a}

Expand Down Expand Up @@ -537,6 +584,25 @@ mod test {
}
}

#[test]
fn test_add1() {
println!("U254.add1: {} bytes", U254::add1().len());
let mut prng = ChaCha20Rng::seed_from_u64(0);
for _ in 0..100 {
let a: BigUint = prng.sample(RandomBits::new(254));
let c: BigUint = (a.clone() + BigUint::one()).rem(BigUint::one().shl(254));

let script = script! {
{ U254::push_u32_le(&a.to_u32_digits()) }
{ U254::add1() }
{ U254::push_u32_le(&c.to_u32_digits()) }
{ U254::equalverify(1, 0) }
OP_TRUE
};
run(script);
}
}

#[test]
fn test_double() {
println!("U254.double: {} bytes", U254::double(0).len());
Expand Down
Loading
Loading