Order/LendTx

OrderTx

In order to hide the amount in the trader's account, the program separates the pedersen commitment for the initial margin from the original value in the account. Yes, the whole account is locked. Though the knowledge of original value in the account remains with the trader.

The program below performs a range check on the resulting expression from V - IM to prove expr ≥ 0 .

p.push(Commitment::blinded(v))
.var() 

.expr() 

.push(Commitment::blinded(IM))

.var()
.expr()
.neg() 

.add()

.range()
.drop()

The blinding factor used for the Initial Margin would then be revealed to the relayer in order to track the solvency of the positions and create settlement transactions.

The relayer would use the execution price of the trade to generate a delegate locking signature on this Tx and relay it forward to the base layer.

LendTx

The program for LendTx is similar to OrderTx, and instead of IM, we use the commitment on the Deposit to be locked in the Twilight pool.

p.push(Commitment::blinded(v))
.var() 

.expr() 
.push(Committment::blinded(Deposit)

.r#const() 

.neg()
.add()

.range()

.drop()

The relayer further executes locking constraints on the transaction where:

  • 0 and 1 subscripts are referring to before and after state of the values

  • TLV and TPS are abbreviations for total locked value and total pool share.

  • AND is a conjunction constraint

  • Error is from the rounding error

p.push(Commitment::blinded(TLV0)
.var()
.dup()

.expr()

.push(Commitment::blinded(poolShare))

.var()
.dup()

.expr()
.roll:2()

.mul()

.push(Commitment::blinded(TPS0))

.var()

.dup()

.expr()
.push(Commitment::blinded(Deposit))
.var()
.dup()

.expr()
.roll:2()
.mul()
.push(Commitment::blinded(Error))

.var()

.expr()

.add()
.roll:3()
.eq()

.push(commitment::blinded(TPS1)

.var()
.expr()
.roll:3()
.expr()

.neg()
.add()

.roll:3()

.expr()

.eq()
.and()
.push(Commitment::blinded(TLV1))

.var()

.expr()

.roll:3()
.expr()
.neg()
.add()

.roll:2()
.expr()

.eq()

.and()

.verify()

The above program holds true for a positive error. For a negative error, expr for the error is negated.

The relayer would use the deposit amount of the transaction to generate a delegate locking signature and relay it to the base layer.

Last updated