-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
[WIP] Adding Inflight tx exits #132
base: master
Are you sure you want to change the base?
Conversation
test/exitHandler.js
Outdated
// transaction hash + constant signed by alice | ||
const signature = (transferTx + c).sign(alicePriv); | ||
|
||
const inTxData = Tx.parseToParams(transferTx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't calculate transferProof because period is not getting submitted(transferTx is inflight) so i am parsing it to data and then passing it to function and in our contract we can parse this data to obtain the transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible, even simpler would be transferTx.hex()
.
test/exitHandler.js
Outdated
const inTxData = Tx.parseToParams(transferTx); | ||
|
||
// Bob will start the exit for Alice | ||
await exitHandler.startLimboExit(inTxData, signature, outputIndex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who will start the limbo exit for tx A->B? A or B?
(Current) B starts a limbo exit by submitting all data A would submit if A were exiting from the coin, as well as the signature received and the in-flight transaction.. All data A would submit will be the depositTx and depositProof.
test/exitHandler.js
Outdated
(b, tx) => b.addTx(tx), | ||
new Block(33) | ||
); | ||
prevRoot = period.merkleRoot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need spendProof (Proof that bob sent the money to charlie) so that i can pass it to challengeLimbo
and validate it there. Can i create a block simply and not publish it to Bridge
so that i can get period.
test/exitHandler.js
Outdated
const depositProof = period.proof(depositTx); | ||
const outputIndex = 1; | ||
const exitStake = exitHandler.exitStake(); | ||
const signature = (transferTx + c).sign(alicePriv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A sends B a signature on the hash of the in-flight transaction plus some special constant.
Need to fix it
contracts/ExitHandler.sol
Outdated
bytes32 depositTxHash; | ||
(txPos, depositTxHash,) = TxLib.validateProof(96, depositProof); | ||
require( | ||
depositTxHash == transferTx.ins[*].outpoint.hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was supposed to pass _inputIndex in the function and put it here but i was looking for some other way to verify this.
contracts/ExitHandler.sol
Outdated
@@ -181,6 +181,64 @@ contract ExitHandler is DepositHandler { | |||
exitDuration = _exitDuration; | |||
} | |||
|
|||
function startLimboExit( | |||
bytes memory limboTxData, bytes32 signature, uint8 _outputIndex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanspro i think you have been looking at the wrong specification. there should not be any signatures for more viable plasma. can you make sure that you tried to implement this: https://ethresear.ch/t/more-viable-plasma/2160
0ffcbbf
to
d495814
Compare
@johannbarbie i've updated the PR(still need to update test cases though), could you check it out once and give me a feedback upon it. |
👀 |
contracts/ExitHandler.sol
Outdated
|
||
bytes32 inTxHash = keccak256(inTxData); | ||
|
||
// for now assume outputIndex 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what should this be later? youngest input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a tx has multiple inputs and multiple outputs then there will be multiple utxo's so right now i am handling one but a tx might have more so i how should i handle that scenario?
One possible soln: if a tx has multiple utxo's then i can write a combine function which will get me combined priority for the tx (i can use getERC20ExitPriority
to get individual utxo priority)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can i use youngest input in any way for this?
contracts/ExitHandler.sol
Outdated
output: outputs, | ||
input: inputs, | ||
finalized: false, | ||
exitor: msg.sender, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does there need to be any special relation between msg.sender and the transaction? signer of inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no there's actually no need for storing it with tx, i thought we might need it to check if same address is initiating large amount of exits but i think keeping exitStake
handles this problem
Will remove it
contracts/ExitHandler.sol
Outdated
function challengeLimboExitByOutputSpend( | ||
bytes32 exitId, | ||
bytes inTxData, uint8 inOutputNo, | ||
bytes competingTxData, bytes proof, uint8 competingInputNo, uint32 blockNumber) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think here you should borrow from our existing proof structure (bytes32[]), which will allow you to read the blockHeight from the bridge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah i am comparing blockHeight of inTx and spendTx to see who comes first.
contracts/ExitHandler.sol
Outdated
TxLib.Tx memory transferTx = Tx.parseTx(inTxData); | ||
|
||
// [TODO]check if this tx is included or not | ||
// TxLib.Tx memory includedTx = checkForValidityAndInclusion(blockNumber, includedTxData, includedProof); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't you need to pass an inclusion proof here? i think you can copy from the other exit functions: https://github.com/leapdao/leap-contracts/blob/master/test/exitHandler.js#L134-L136
contracts/ExitHandler.sol
Outdated
|
||
function respondInputSpendChallenge( | ||
bytes32 exitId, bytes inTxData, uint8 inInputNo, | ||
bytes includedTxData, bytes includedProof, uint8 includedOutputNo, uint32 blockNumber |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here also use bytes32[]
for inclusion proof and make use of leap-core and txLib.sol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanspro you are on the right way. i think figuring out the inclusion proofs is the biggest gap left. awesome work 👍
f5f89cb
to
ec05c37
Compare
contracts/ExitHandler.sol
Outdated
uint32 timestamp; | ||
|
||
// priority based on youngestInput | ||
if (_youngestInputProof.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary check? We always need youngestInputProof, no? Otherwise, I guess it will fail on line 171 (validateProof)
contracts/ExitHandler.sol
Outdated
|
||
function challengeLimboExitByInclusionProof( | ||
bytes32 exitId, bytes memory inTxData, | ||
uint8 InputNo, bytes32[] memory _youngestInputProof, bytes32[] memory _inclusionProof) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_youngestInputProof
is not used in any of these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't done a complete review. This looks like a nice effort, however couple of my findings make me think that the whole implementation is not working correct yet. Having a working set of unit tests will definitely help here.
I will continue review once the tests are done, so I can make sure I do my best work here.
contracts/ExitHandler.sol
Outdated
for(uint8 i=0; i < currentExit.output.length; i++){ | ||
LimboOut memory out = currentExit.output[i]; | ||
if (out.exitable){ | ||
amount = piggybackStake + out.amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
piggybackStake
is in wei and out.amount
is in tokens. Separate transfers needed here
contracts/ExitHandler.sol
Outdated
for(uint8 i=0; i < currentExit.input.length; i++){ | ||
LimboIn memory input = currentExit.input[i]; | ||
if (input.exitable){ | ||
amount = piggybackStake + input.amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
piggybackStake
is in wei and input.amount
is in tokens. Separate transfers needed here
contracts/ExitHandler.sol
Outdated
uint32 prevHeight = bridge.periods[_prevProof[0]].height; | ||
|
||
require(blockHeight < prevHeight); | ||
tokens[transferTx.outs[0].color].addr.transferFrom(address(this), msg.sender, challengeStake); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
challengeStake
is in ether, so it should transfer ether here. Also the destination is not correct: we are returning stake of the previous challenger, so it should transfer to prevChallenge.owner
contracts/ExitHandler.sol
Outdated
|
||
require(inTxHash == txHash, "Invalid inclusion proof"); | ||
|
||
limboExit.isValid = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not we check that provided tx has any connection to challenged exit?
@nanspro how are things here? :) |
Implementing Limbo(Inflight tx) Exits
Fixes #86