这是indexloc提供的服务,不要输入任何密码
Skip to content

big.int_mod() returns incorrect result for some numbers #5931

@in3rsha

Description

@in3rsha

Odin Version: dev-2025-10-nightly
OS: Ubuntu 22.04.5

The big.int_mod() proc seems to return the incorrect remainder for some big integer values.

Here's an example in Python:

a = 3351951982485649274893506249551461531869841455148098344430890360930192345844485855956241793418914802713278852793799976230545127411560969441984014513833901
b = 115792089237316195423570985008687907853269984665640564039457584007908834671663
result = a % b
print(result)
# 28948022309329048855892746252171976963317496166410141009864396001977208667952

This is the result in Odin:

package main

import "core:fmt"
import "core:math/big"

main :: proc() {

  // declare variables
  a := &big.Int{}
  b := &big.Int{}
  result := &big.Int{}

  // initialize big integers
  big.string_to_int(a, "3351951982485649274893506249551461531869841455148098344430890360930192345844485855956241793418914802713278852793799976230545127411560969441984014513833901")
  big.string_to_int(b, "115792089237316195423570985008687907853269984665640564039457584007908834671663")

  // calculate remainder (incorrect result)
  big.int_mod(result, a, b)
  fmt.println(big.int_itoa_string(result))
  // 102293456496754433260461317602130322570708599506021384729404192755153405213617964403429313603415344574109447143323238980677293152034467596747900421084

  // calculate remainder again (correct result the second time around)
  big.int_mod(result, result, b)
  fmt.println(big.int_itoa_string(result))
  // 28948022309329048855892746252171976963317496166410141009864396001977208667952

}

The result of the first big.int_mod() is greater than the size of the modulus, which should not be possible. However, if you modulo this result again by the same modulus, you do get the correct result the second time around.

The function seems to work for other numbers of a similar size, but this is an example of one that I found that produces the bug.

Metadata

Metadata

Assignees

Labels

bugreplicatedWe were able to replicate the bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions