fix modexp output, GST +53

This commit is contained in:
andri lim 2019-04-24 22:37:34 +07:00
parent 89402af114
commit fd7c447f18
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 2293 additions and 2311 deletions

File diff suppressed because it is too large Load Diff

View File

@ -165,16 +165,22 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
result[0] = 1 result[0] = 1
# Start with EVM special cases # Start with EVM special cases
if modulo <= 1: let output = if modulo <= 1:
# If m == 0: EVM returns 0. # If m == 0: EVM returns 0.
# If m == 1: we can shortcut that to 0 as well # If m == 1: we can shortcut that to 0 as well
computation.rawOutput = @(zero()) zero()
elif exp.isZero(): elif exp.isZero():
# If 0^0: EVM returns 1 # If 0^0: EVM returns 1
# For all x != 0, x^0 == 1 as well # For all x != 0, x^0 == 1 as well
computation.rawOutput = @(one()) one()
else:
powmod(base, exp, modulo).toByteArrayBE
if output.len >= mod_len:
computation.rawOutput = @(output[^mod_len..^1])
else: else:
computation.rawOutput = @(powmod(base, exp, modulo).toByteArrayBE) computation.rawOutput = newSeq[byte](mod_len)
computation.rawOutput[^output.len..^1] = output[0..^1]
proc modExp*(computation: BaseComputation) = proc modExp*(computation: BaseComputation) =
## Modular exponentiation precompiled contract ## Modular exponentiation precompiled contract

View File

@ -20,38 +20,14 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool =
"CreateOOGafterInitCodeReturndataSize.json", "CreateOOGafterInitCodeReturndataSize.json",
"RevertInCreateInInit.json", "RevertInCreateInInit.json",
"modexpRandomInput.json",
"modexp_9_37111_37111_1000000.json",
"modexp_3_5_100_25000.json",
"modexp_3_09984_39936_155000.json",
"modexp_37120_37111_0_1000000.json",
"modexp.json", "modexp.json",
"modexp_55190_55190_42965_20500.json", "modexpRandomInput.json",
"modexp_39936_1_55201_20500.json",
"modexp_55190_55190_42965_22000.json",
"modexp_39936_1_55201_1000000.json",
"modexp_3_09984_39936_25000.json",
"modexp_3_5_100_22000.json",
"modexp_37120_37111_1_1000000.json",
"modexp_3_5_100_35000.json",
"modexp_3_5_100_1000000.json",
"modexp_3_09984_39936_1000000.json",
"modexp_3_28948_11579_20500.json",
"modexp_55190_55190_42965_25000.json",
"modexp_3_09984_39936_35000.json",
"modexp_3_09984_39936_22000.json",
"modexp_55190_55190_42965_155000.json",
"modexp_55190_55190_42965_1000000.json",
"modexp_55190_55190_42965_35000.json",
"modexp_3_5_100_20500.json",
"modexp_39936_1_55201_35000.json",
"modexp_39936_1_55201_25000.json",
"modexp_37120_37111_97_1000000.json",
"modexp_3_5_100_155000.json",
"modexp_39936_1_55201_22000.json",
"modexp_modsize0_returndatasize.json", "modexp_modsize0_returndatasize.json",
"modexp_9_37111_37111_1000000.json",
"modexp_37120_37111_0_1000000.json",
"modexp_37120_37111_1_1000000.json",
"modexp_37120_37111_97_1000000.json",
"modexp_37120_37111_37111_1000000.json", "modexp_37120_37111_37111_1000000.json",
"modexp_39936_1_55201_155000.json",
"ecpairing_perturb_g2_by_field_modulus_again.json", "ecpairing_perturb_g2_by_field_modulus_again.json",
"ecpairing_perturb_zeropoint_by_field_modulus.json", "ecpairing_perturb_zeropoint_by_field_modulus.json",