Skip to content

Commit

Permalink
rework bls_msm_cost
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 17, 2024
1 parent 49dfcd0 commit 1c57a19
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ int64_t bls_msm_cost(size_t k, int64_t multiplication_cost) noexcept
{
assert(k > 0);

constexpr auto MAX_DISCOUNT = 174;
constexpr int64_t MULTIPLIER = 1000;
constexpr int16_t discount[128] = {1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394,
379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277,
273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245,
244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220,
219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207,
206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193,
193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180,
179, 179, 178, 177, 176, 176, 175, 174};

const auto d = k <= 128 ? discount[k - 1] : MAX_DISCOUNT;
static constexpr int64_t MULTIPLIER = 1000;
static constexpr int16_t DISCOUNT[128] = {1200, 888, 764, 641, 594, 547, 500, 453, 438, 423,
408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285,
281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248,
247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222,
221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208,
208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195,
194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182,
181, 180, 179, 179, 178, 177, 176, 176, 175, 174};

const auto d = DISCOUNT[std::min(k, std::size(DISCOUNT)) - 1];
return (static_cast<int64_t>(k) * multiplication_cost * d) / MULTIPLIER;
}

Expand Down

0 comments on commit 1c57a19

Please sign in to comment.