Skip to content

Instantly share code, notes, and snippets.

@ineffectualproperty
Last active September 23, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ineffectualproperty/9811fbe573eae600420c93336d379038 to your computer and use it in GitHub Desktop.
Save ineffectualproperty/9811fbe573eae600420c93336d379038 to your computer and use it in GitHub Desktop.

To support EIP-2565 the following are some changes required to Geth:

In contracts.go, the pricing formula for ModExp should be replaced with the following logic:

// Calculate the gas cost of the operation
gas := new(big.Int).Set(math.BigMax(modLen, baseLen))
gas = gas.Add(gas, 7).Div(8) // this is an integer divide with ceiling
gas = gas.Mul(gas, gas) // this will square the value
gas.Mul(gas, math.BigMax(adjExpLen, big1))
gas.Div(gas, new(big.Int).SetUint64(params.ModExpQuadCoeffDiv))
gas=math.BigMax(gas, new(big.Int).Set(200)) // this sets a minimum gas of 200

if gas.BitLen() > 64 {
	return math.MaxUint64
}
return gas.Uint64()

Also, in protocol_params.go line 123 ModExpQuadCoeffDiv should be changed from 20 to 3.

Below is a table with the updated test vectors

Test Case EIP-198 Pricing New Pricing
modexp_nagydani_1_square 204 200
modexp_nagydani_1_qube 204 200
modexp_nagydani_1_pow0x10001 3276 341
modexp_nagydani_2_square 665 200
modexp_nagydani_2_qube 665 200
modexp_nagydani_2_pow0x10001 10649 1365
modexp_nagydani_3_square 1894 341
modexp_nagydani_3_qube 1894 341
modexp_nagydani_3_pow0x10001 30310 5461
modexp_nagydani_4_square 5580 1365
modexp_nagydani_4_qube 5580 1365
modexp_nagydani_4_pow0x10001 89292 21845
modexp_nagydani_5_square 17868 5461
modexp_nagydani_5_qube 17868 5461
modexp_nagydani_5_pow0x10001 285900 87381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment