37 if (!
get()->m_execs.count(_name))
38 BOOST_THROW_EXCEPTION(ExecutorNotFound());
39 return get()->m_execs[_name];
44 if (!
get()->m_pricers.count(_name))
45 BOOST_THROW_EXCEPTION(PricerNotFound());
46 return get()->m_pricers[_name];
62 memcpy(&in, _in.data(), min(_in.size(),
sizeof(in)));
66 if (v >= 27 && v <= 28)
76 memset(ret.data(), 0, 12);
77 return {
true, ret.asBytes()};
98 return {
true, _in.toBytes()};
105 if (_begin > _in.
count())
107 assert(_count <= numeric_limits<size_t>::max() / 8);
109 size_t const begin{_begin};
110 size_t const count{_count};
115 bigint ret = fromBigEndian<bigint>(cropped);
117 assert(count - cropped.
count() <= numeric_limits<size_t>::max() / 8);
118 ret <<= 8 * (count - cropped.
count());
125 bigint const baseLength(parseBigEndianRightPadded(_in, 0, 32));
126 bigint const expLength(parseBigEndianRightPadded(_in, 32, 32));
127 bigint const modLength(parseBigEndianRightPadded(_in, 64, 32));
128 assert(modLength <= numeric_limits<size_t>::max() / 8);
129 assert(baseLength <= numeric_limits<size_t>::max() / 8);
130 if (modLength == 0 && baseLength == 0)
131 return {
true,
bytes{}};
132 assert(expLength <= numeric_limits<size_t>::max() / 8);
134 bigint const base(parseBigEndianRightPadded(_in, 96, baseLength));
135 bigint const exp(parseBigEndianRightPadded(_in, 96 + baseLength, expLength));
136 bigint const mod(parseBigEndianRightPadded(_in, 96 + baseLength + expLength, modLength));
138 bigint const result = mod != 0 ? boost::multiprecision::powm(base, exp, mod) :
bigint{0};
140 size_t const retLength(modLength);
141 bytes ret(retLength);
151 if (_expLength <= 32)
153 bigint const exp(parseBigEndianRightPadded(_in, _expOffset, _expLength));
154 return exp ? msb(exp) : 0;
158 bigint const expFirstWord(parseBigEndianRightPadded(_in, _expOffset, 32));
159 size_t const highestBit(expFirstWord ? msb(expFirstWord) : 0);
160 return 8 * (_expLength - 32) + highestBit;
169 return (_x * _x) / 4 + 96 * _x - 3072;
171 return (_x * _x) / 16 + 480 * _x - 199680;
177 bigint const baseLength(parseBigEndianRightPadded(_in, 0, 32));
178 bigint const expLength(parseBigEndianRightPadded(_in, 32, 32));
179 bigint const modLength(parseBigEndianRightPadded(_in, 64, 32));
181 bigint const maxLength(max(modLength, baseLength));
182 bigint const adjustedExpLength(expLengthAdjust(baseLength + 96, expLength, _in));
184 return multComplexity(maxLength) * max<bigint>(adjustedExpLength, 1) / 20;
204 return 100000 + (_in.
size() / 192) * 80000;
std::pair< bool, bytes > alt_bn128_G1_mul(bytesConstRef _in)
vector_ref< _T > cropped(size_t _begin, size_t _count) const
void toBigEndian(T _val, Out &o_out)
h256 sha256(bytesConstRef _input) noexcept
bool sha3(bytesConstRef _input, bytesRef o_output) noexcept
std::pair< bool, bytes > alt_bn128_G1_add(bytesConstRef _in)
std::function< std::pair< bool, bytes >(bytesConstRef _in)> PrecompiledExecutor
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
std::pair< bool, bytes > alt_bn128_pairing_product(bytesConstRef _in)
std::function< bigint(bytesConstRef _in)> PrecompiledPricer
Public recover(Signature const &_sig, h256 const &_hash)
Recovers Public key from signed message hash.
std::vector< byte > bytes
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
h160 ripemd160(bytesConstRef _input)
#define ETH_REGISTER_PRECOMPILED(Name)
#define ETH_REGISTER_PRECOMPILED_PRICER(Name)