add some comment

This commit is contained in:
andri lim 2019-04-25 22:33:26 +07:00
parent 376957bea4
commit cee0a38278
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 29 additions and 0 deletions

View File

@ -197,6 +197,11 @@ op sha3, inline = true, startPos, length:
## 0x20, Compute Keccak-256 hash. ## 0x20, Compute Keccak-256 hash.
let (pos, len) = (startPos.toInt, length.toInt) let (pos, len) = (startPos.toInt, length.toInt)
# TODO:
# "randomStatetest14.json", # SHA3 offset
# "sha3_deja.json", # SHA3 startPos
# both test require Uint256 to calculate startpos/offset
if pos < 0 or len < 0 or pos > 2147483648: if pos < 0 or len < 0 or pos > 2147483648:
raise newException(OutOfBoundsRead, "Out of bounds memory access") raise newException(OutOfBoundsRead, "Out of bounds memory access")

View File

@ -56,6 +56,24 @@ proc getPoint[T: G1|G2](t: typedesc[T], data: openarray[byte]): Point[T] =
raise newException(ValidationError, "Could not get point value") raise newException(ValidationError, "Could not get point value")
if not py.fromBytes2(data.toOpenArray(nextOffset, nextOffset * 2 - 1)): if not py.fromBytes2(data.toOpenArray(nextOffset, nextOffset * 2 - 1)):
raise newException(ValidationError, "Could not get point value") raise newException(ValidationError, "Could not get point value")
# "ecpairing_perturb_g2_by_field_modulus_again.json",
# "ecpairing_perturb_zeropoint_by_field_modulus.json",
# "ecpairing_perturb_g2_by_field_modulus.json",
# modulus comparion in FQ2.fromBytes produce different result
const
modulus = Uint256.fromHex("30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47")
let a = Uint256.fromBytesBE(data.toOpenArray(0, 31), false)
let b = Uint256.fromBytesBE(data.toOpenArray(32, 63), false)
when T is G2:
let c = Uint256.fromBytesBE(data.toOpenArray(64, 95), false)
let d = Uint256.fromBytesBE(data.toOpenArray(96, 127), false)
if a >= modulus or b >= modulus or c >= modulus or d >= modulus:
raise newException(ValidationError, "value greater than field modulus")
else:
if a >= modulus or b >= modulus:
raise newException(ValidationError, "value greater than field modulus")
if px.isZero() and py.isZero(): if px.isZero() and py.isZero():
result = T.zero() result = T.zero()
else: else:
@ -138,6 +156,7 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
else: log2(exp) # highest-bit in exponent else: log2(exp) # highest-bit in exponent
else: else:
let first32 = rawMsg.rangeToPadded[:Uint256](96 + base_len, 95 + base_len + exp_len) let first32 = rawMsg.rangeToPadded[:Uint256](96 + base_len, 95 + base_len + exp_len)
# TODO: `modexpRandomInput.json` require Uint256 arithmetic for this code below
if not first32.isZero: if not first32.isZero:
8 * (exp_len - 32) + first32.log2 8 * (exp_len - 32) + first32.log2
else: else:
@ -176,6 +195,8 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
else: else:
powmod(base, exp, modulo).toByteArrayBE powmod(base, exp, modulo).toByteArrayBE
# maximum output len is the same as mod_len
# if it less than mod_len, it will be zero padded at left
if output.len >= mod_len: if output.len >= mod_len:
computation.rawOutput = @(output[^mod_len..^1]) computation.rawOutput = @(output[^mod_len..^1])
else: else:

View File

@ -25,10 +25,13 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool =
"RevertInCreateInInit.json", "RevertInCreateInInit.json",
"modexp.json", "modexp.json",
# see precompiles getPoint[G2]
"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",
"ecpairing_perturb_g2_by_field_modulus.json", "ecpairing_perturb_g2_by_field_modulus.json",
# all these tests below actually pass
# but they are very slow
# byzantium slow # byzantium slow
"LoopCallsDepthThenRevert3.json", "LoopCallsDepthThenRevert3.json",
"LoopCallsDepthThenRevert2.json", "LoopCallsDepthThenRevert2.json",