Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug report: wrong input params in newton_y() test case #10

Open
0x-stan opened this issue Apr 14, 2022 · 0 comments
Open

bug report: wrong input params in newton_y() test case #10

0x-stan opened this issue Apr 14, 2022 · 0 comments

Comments

@0x-stan
Copy link

0x-stan commented Apr 14, 2022

Wrong input params of test_newton_y()

The parameters here need to be modified, from A * 3**3 * 10000 to A

https://github.com/curvefi/curve-crypto-contract/blob/master/tests/tricrypto/test_math.py#L114

A_MUL = 10000 * 3**3
MIN_A = int(0.01 * A_MUL)
MAX_A = 1000 * A_MUL

...

# MIN_A and MAX_A have multiplied N**N * A_MUL.
@given(
       A=strategy('uint256', min_value=MIN_A, max_value=MAX_A),
       ...
)
@settings(max_examples=MAX_SAMPLES)
def test_newton_y(crypto_math, A, D, xD, yD, zD, gamma, j):
    ...
    try:
       # A is already ANN now, shouldn't multiply N**N * A_MUL any more.
        result_contract = crypto_math.newton_y(A * 3**3 * 10000, gamma, X, D, j) 
    except Exception:
        ...

Params given by strategy are always inappropriate to newton's method

For example, run test of newton_D(), strategy will give 50 sets of input data, may only a few of them fit. Most of them could not match the condition, causes the test cannot be performed effectively.

The main reason for improper test data is that yx or zx is too small, causes the xp in newton_D are very imbalanced. So the result of python simulation always fails to match the conditions.

@given(
       A=strategy('uint256', min_value=MIN_A, max_value=MAX_A),
       x=strategy('uint256', min_value=10**9, max_value=10**14 * 10**18),  # 1e-9 USD to 100T USD
       yx=strategy('uint256', min_value=int(1.1e11), max_value=10**18),  # <- ratio 1e18 * y/x, typically 1e18 * 1
       zx=strategy('uint256', min_value=int(1.1e11), max_value=10**18),  # <- ratio 1e18 * z/x, typically 1e18 * 1
       perm=strategy('uint8', max_value=5),  # Permutation
       gamma=strategy('uint256', min_value=MIN_GAMMA, max_value=MAX_GAMMA)
)
@settings(max_examples=MAX_SAMPLES)
def test_newton_D(crypto_math, A, x, yx, zx, perm, gamma):
    ...
    # Most of test data would not match the condition below.
    # Because the xps of the pool are very imbalanced.
    if all(f >= 1.1e16 and f <= 0.9e20 for f in [_x * 10**18 / result_sim for _x in X]):
        # Very few test data could reach here
        result_contract = crypto_math.newton_D(A, gamma, X)
        

newton_y() test case has the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant