Skip to content

Dart 2's BigInt.modPow is bugged #32626

@ds84182

Description

@ds84182

Minimal test case:

void main() {
  const input = "14222378113547797484180443703718287710954963648021535057076143638672814000321219503871352719175100865184619168128345594681547640115731246638";
  const dp = "68805717049526308324575273108573116001662526577152473869179706227957595091947965115631041308417430436199124027318143092441125820376694663934988040410650411495368889020042904305193636218299757516719158446153874604179501966374024692112438317379995729651506791282977824993147390378095874103264534184571632120755";
  const p = "144173682842817587002196172066264549138375068078359231382946906898412792452632726597279520229873489736777248181678202636100459215718497240474064366927544074501134727745837254834206456400508719134610847814227274992298238973375146473350157304285346424982280927848339601514720098577525635486320547905945936448443";

  final dart2 = (<T>() => T == int)<int>();
  if (dart2) {
    print(BigInt.parse(input).modPow(BigInt.parse(dp), BigInt.parse(p)));
  } else {
    print(int.parse(input).modPow(int.parse(dp), int.parse(p)));
  }
}

Dart 1.24.2 prints:

41228476947144730491819644448449646627743926889389391986712371102685149844677539601093216100085332586762793443185970606905210276466134532567499467782091302786983591600568927680640814869848681411989432528418918299321385420296108046942018595594076729397423805685944237555128652606412065971965116137839721723231

Dart 2.0.0-dev.40.0 prints:

107195413767532249511858342477196263115037563715887024727527619427156370691743018647443671518445164651770783796458102512150439532505589800981751463014511276958633276079197156133641055629548339601513111412358616661314784403746179252284131012505017667908497957864265639477986489348115439873392893965780954625183

With smaller numbers, modPow seems to work OK.

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions