-
Notifications
You must be signed in to change notification settings - Fork 109
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
parent and child insurance stubs #272
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import {AddressAliasHelper} from "../libraries/AddressAliasHelper.sol"; | ||
|
||
// assumes parent and child chain uses ETH for fees | ||
// EVERY FUNCTION MUST NEVER REVERT WHEN CALLED BY PARENT IN SEQUENCE, OTHERWISE QUEUE IS STUCK | ||
contract Child { | ||
address public immutable parentChainAddr; | ||
address public immutable sequencerAddr; | ||
uint256 public sequenceNumber; | ||
uint256 public amtSatisfied; | ||
|
||
constructor(address _parentChainAddr, address _sequencerAddr) { | ||
parentChainAddr = _parentChainAddr; | ||
sequencerAddr = _sequencerAddr; | ||
} | ||
|
||
modifier onlyInSequenceFromParent(uint256 seqNum) { | ||
require(seqNum == sequenceNumber, "invalid sequence number"); | ||
require(msg.sender == AddressAliasHelper.applyL1ToL2Alias(parentChainAddr), "only parent chain contract can call"); | ||
sequenceNumber++; | ||
_; | ||
} | ||
|
||
function deposit(uint256 seqNum) public payable onlyInSequenceFromParent(seqNum) { | ||
// no need to do anything here, just receiving ETH | ||
} | ||
|
||
function withdraw(uint256 seqNum, uint256 amount) public onlyInSequenceFromParent(seqNum) { | ||
amount = amount < address(this).balance ? amount : address(this).balance; | ||
(bool success,) = payable(sequencerAddr).call{value: amount}(""); | ||
require(success, "withdraw failed"); | ||
} | ||
|
||
// If (blocknum, blockhash) is in the history of Chain X, then add amount to S. Otherwise pay out amount to beneficiaryAddr. | ||
// will revert if arb block num < blockNum | ||
function commit(uint256 seqNum, address beneficiary, uint256 amount, uint256 blockNum, bytes32 blockHash) external payable onlyInSequenceFromParent(seqNum) { | ||
// revert if arb block num < blockNum | ||
// pay msg.value to sequencer | ||
// check if blockHash is part of history | ||
// if yes: increment amtSatisfied (S) | ||
// if no: pay out amount to beneficiary. do not revert on failure, because a contract could DoS | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
// assumes parent and child chain uses ETH for fees | ||
contract Parent { | ||
struct SequencerCommitment { | ||
uint256 blockNum; | ||
bytes32 blockHash; | ||
uint256 pricePerEthWad; | ||
} | ||
|
||
address public immutable sequencer; | ||
|
||
// D | ||
uint256 public depositedAmount; | ||
Check failure Code scanning / Slither Uninitialized state variables High
Parent.depositedAmount is never initialized. It is used in:
- Parent.buy(uint256,Parent.SequencerCommitment,bytes,Parent.RetryableParams) |
||
// I - insurance sold | ||
uint256 public insuranceSold; | ||
|
||
// sequence number sigma | ||
uint256 public sequenceNumber; | ||
|
||
constructor(address _sequencer) { | ||
sequencer = _sequencer; | ||
} | ||
|
||
modifier onlySequencer() { | ||
require(msg.sender == sequencer, "only sequencer can call"); | ||
_; | ||
} | ||
|
||
function deposit() public payable onlySequencer { | ||
// increment depositedAmount by value | ||
// create a retryable to hit the child contract deposit function | ||
// increment seqNum | ||
} | ||
|
||
function withdraw(uint256 amount) public onlySequencer { | ||
// decrement depositedAmount by amount | ||
// create a retryable to hit the child contract withdraw function | ||
// increment seqNum | ||
} | ||
|
||
function buy(uint256 amount, uint256 minSatisfied, address beneficiary, bytes memory signedCommitment) public payable { | ||
// verify the signed commitment | ||
// require depositAmount - insuranceSold + minSatisfied >= amount | ||
// require msg.value == price*amount | ||
// increment insuranceSold by amount | ||
// create a retryable to hit the child contract settle function, sending msg.value | ||
// increment seqNum | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is the assumption that the
signedCommitment
inbuy
also encodes the values being committed to alongside the commitment + signature?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, just pushed up a commit that includes those. the entire
struct SequencerCommitment
is signed over