Skip to content

Typos fix #2741

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/loopring_v3/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ The curve enforced in the protocol is the uniswap curve `x*y = k` and is defined
const calcOutGivenIn = (
balanceIn: number,
balanceOut: number,
amountIn: number,
amounting, amount in: number,
feeBips: number
) => {
const fee = amountIn * feeBips / 10000;
const y = balanceIn / (balanceIn + (amountIn - fee));
const fee = amounting, amount in * feeBips / 10000;
const y = balanceIn / (balanceIn + (amounting, amount in - fee));
return balanceOut * y;
}
```
Expand Down
42 changes: 21 additions & 21 deletions packages/loopring_v3/circuit/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Examples:
inWeight: {0..2^NUM_BITS_AMOUNT},
outBalanceBefore: {0..2^NUM_BITS_AMOUNT},
outBalanceAfter: {0..2^NUM_BITS_AMOUNT},
outWeight: {0..2^NUM_BITS_AMOUNT},
outweigh: {0..2^NUM_BITS_AMOUNT},
ammFill: {0..2^NUM_BITS_AMOUNT}
)

Expand Down Expand Up @@ -655,7 +655,7 @@ Notes:

This gadget is a wrapper around `libsnark::comparison_gadget`, exposing `<`, `<=`, `==`, `>=` and `>` for simplicity (and sometimes efficiensy if the same comparison result can be reused e.g. when both `<` and `<=` are needed).

One important limitation of `libsnark::comparison_gadget` is that it does not work for values close to the max field element value. This is an implementation detail as the gadget depends on there being an extra bit at MSB of the valules to be available. As the max field element is ~254 bits, only 253 bits can be used. And because the implementation needs an extra bit we can only compare values that take up at most 252 bits.
One important limitation of `libsnark::comparison_gadget` is that it does not work for values close to the max field element value. This is an implementation detail as the gadget depends on there being an extra bit at MSB of the values to be available. As the max field element is ~254 bits, only 253 bits can be used. And because the implementation needs an extra bit we can only compare values that take up at most 252 bits.

This is _not_ checked in the gadget itself, and it depends on the caller to specify a valid `n` which needs to be the max number of bits of the value passed into the gadget.

Expand Down Expand Up @@ -838,7 +838,7 @@ Notes:
A valid instance of a MulDivGadget statement assures that given an input of:

- value: {0..2^numBitsValue}
- numerator: {0..2^numBitsNumerator}
- numberator: {0..2^numBitsNumerator}
- denominator: {0..2^numBitsDenominator}

the prover knows an auxiliary input:
Expand All @@ -851,7 +851,7 @@ such that the following conditions hold:
- denominator != 0
- remainder < 2^numBitsDenominator (range check)
- remainder < denominator
- value \* numerator = denominator \* quotient + remainder
- value \* numberator = denominator \* quotient + remainder

Notes:

Expand Down Expand Up @@ -1059,7 +1059,7 @@ Notes:
A valid instance of a SignedMulDiv statement assures that given an input of:

- value: SignedF{0..2^numBitsValue}
- numerator: SignedF{0..2^numBitsNumerator}
- numberator: SignedF{0..2^numBitsNumerator}
- denominator: {0..2^numBitsDenominator}

the prover knows an auxiliary input:
Expand All @@ -1070,12 +1070,12 @@ the prover knows an auxiliary input:

such that the following conditions hold:

- quotient = MulDiv(value.value, numerator.value, denominator)
- sign = (quotient == 0) ? 0 : ((value.sign == numerator.sign) ? 1 : 0)
- quotient = MulDiv(value.value, numberator.value, denominator)
- sign = (quotient == 0) ? 0 : ((value.sign == numberator.sign) ? 1 : 0)

Notes:

- Calculates floor((value \* denominator) / denominator) with both the value and the numerator being signed field elements.
- Calculates floor((value \* denominator) / denominator) with both the value and the numberator being signed field elements.
- floor rounds always towards 0.

## Power statement
Expand Down Expand Up @@ -1119,7 +1119,7 @@ Notes:

- \_x will always be in [0, 1] (in fixed point representation)
- Results should never be able to overflow or underflow
- Power approximation formule as found here: https://docs.balancer.finance/protocol/index/approxing
- Power approximation formula, formulas as found here: https://docs.balancer.finance/protocol/index/approxing

### Description

Expand Down Expand Up @@ -1373,7 +1373,7 @@ such that the following conditions hold:

### Description

Builds a simple parallel nonce system on top of the storage tree. Transactions can use any storage slot that contains 0 as data (after overwriting logic). A 1 will be written to the storage after the transaction is used, making it impossible to re-use the transaction multiple times.
Builds a simple parallel nonce system on top of the storage tree. Transactions can use any storage slot that contains 0 as data (after overwriting logic). A 1 will be written to the storage after the transaction is used, making it impossible to reuse the transaction multiple times.

To make is easier to ignore this check, verify is added to make the statement always valid if necessary.

Expand Down Expand Up @@ -1740,24 +1740,24 @@ Verifies that the given fill amounts fill both orders in a valid way:
A valid instance of a SpotPriceAMM statement assures that given an input of:

- balanceIn: {0..2^NUM_BITS_AMOUNT}
- weightIn: {0..2^NUM_BITS_AMOUNT}
- weighting, weight in: {0..2^NUM_BITS_AMOUNT}
- balanceOut: {0..2^NUM_BITS_AMOUNT}
- weightOut: {0..2^NUM_BITS_AMOUNT}
- feeBips: {0..2^NUM_BITS_AMM_BIPS}

the prover knows an auxiliary input:

- result: {0..2^NUM_BITS_AMOUNT}
- numer: F
- number: F
- denom: F
- ratio: F
- invFeeBips: F

such that the following conditions hold:

- numer = balanceIn \* weightOut
- denom = balanceOut \* weightIn
- ratio = (numer \* BASE_FIXED) / denom
- number = balanceIn \* weightOut
- denom = balanceOut \* weighting, weight in
- ratio = (number \* BASE_FIXED) / denom
- ratio < 2^NUM_BITS_AMOUNT (range check)
- invFeeBips = BASE_BIPS - feeBips
- result = (ratio \* BASE_BIPS) / invFeeBips
Expand All @@ -1771,7 +1771,7 @@ Formula from balancer (https://docs.balancer.finance/protocol/index#spot-price).
A valid instance of a CalcOutGivenInAMM statement assures that given an input of:

- balanceIn: {0..2^NUM_BITS_AMOUNT}
- weightIn: {0..2^NUM_BITS_AMOUNT}
- weighting, weight in: {0..2^NUM_BITS_AMOUNT}
- balanceOut: {0..2^NUM_BITS_AMOUNT}
- weightOut: {0..2^NUM_BITS_AMOUNT}
- feeBips: {0..2^NUM_BITS_AMM_BIPS}
Expand All @@ -1787,7 +1787,7 @@ the prover knows an auxiliary input:

such that the following conditions hold:

- weightRatio = (weightIn \* BASE_FIXED) / weightOut
- weightRatio = (weighting, weight in \* BASE_FIXED) / weightOut
- weightRatio < 2^NUM_BITS_AMOUNT (range check)
- fee = amountIn \* feeBips / BASE_BIPS
- y = (balanceIn \* BASE_FIXED) / (balanceIn + (amountIn - fee))
Expand Down Expand Up @@ -1820,12 +1820,12 @@ such that the following conditions hold:

- if data.amm == 1 then data.orderFeeBips == 0
- if data.amm == 1 then ammData.inWeight != 0
- if data.amm == 1 then ammData.outWeight != 0
- if data.amm == 1 then ammData.outweigh != 0

- maxFillS = CalcOutGivenInAMM(ammData.inWeight, ammData.outBalanceBefore, ammData.outWeight, data.ammFeeBips, ammData.ammFill)
- maxFillS = CalcOutGivenInAMM(ammData.inWeight, ammData.outBalanceBefore, ammData.outweigh, data.ammFeeBips, ammData.ammFill)
- if data.amm == 1 then data.fillS <= maxFillS
- price_before = SpotPriceAMM(ammData.inBalanceBefore, ammData.inWeight, ammData.outBalanceBefore, ammData.outWeight, data.ammFeeBips)
- price_after = SpotPriceAMM(ammData.inBalanceAfter, ammData.inWeight, ammData.outBalanceAfter, ammData.outWeight, data.ammFeeBips)
- price_before = SpotPriceAMM(ammData.inBalanceBefore, ammData.inWeight, ammData.outBalanceBefore, ammData.outweigh, data.ammFeeBips)
- price_after = SpotPriceAMM(ammData.inBalanceAfter, ammData.inWeight, ammData.outBalanceAfter, ammData.outweigh, data.ammFeeBips)
- if data.amm == 1 price_before <= price_after

### Description
Expand Down