Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Change the gas cost of modexp according to ethereum/EIPs@4d4d8fb
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Jul 24, 2017
1 parent b352d83 commit fc9c695
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libethcore/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ namespace
return 8 * (_expLength - 32) + highestBit;
}
}

bigint mult_complexity(bigint const& _x)
{
if (_x <= 64)
return _x * _x;
if (_x <= 1024)
return (_x * _x) / 4 + 96 * _x - 3072;
else
return (_x * _x) / 16 + 480 * _x - 199680;
}
}

ETH_REGISTER_PRECOMPILED_PRICER(modexp)(bytesConstRef _in)
Expand All @@ -171,7 +181,7 @@ ETH_REGISTER_PRECOMPILED_PRICER(modexp)(bytesConstRef _in)
bigint const maxLength(max(modLength, baseLength));
bigint const adjustedExpLength(expLengthAdjust(baseLength + 96, expLength, _in));

return maxLength * maxLength * max<bigint>(adjustedExpLength, 1) / 100;
return mult_complexity(maxLength) * max<bigint>(adjustedExpLength, 1) / 100;
}

ETH_REGISTER_PRECOMPILED(alt_bn128_G1_add)(bytesConstRef _in)
Expand Down

0 comments on commit fc9c695

Please sign in to comment.