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

Add Security documentation to ensure finality #231

Merged
Merged
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
32 changes: 32 additions & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ function transferFrom(address who, address to, uint amount)
}
```

## Speed Bump

If we would like to prevent off-chain calls from being chained together, we can
ensure that the block has been finalized.

```solidity
contract Secret {
uint256 private _height;
bytes private _secret;
address private _buyer;
kostko marked this conversation as resolved.
Show resolved Hide resolved

constructor(bytes memory _text) {
_secret = _text;
kostko marked this conversation as resolved.
Show resolved Hide resolved
}

function recordPayment() external payable {
require(msg.value == 1 ether);
// set and lock buyer
_height = block.number;
_buyer = msg.sender;
}

/// @notice Reveals the secret.
function revealSecret() view external returns (bytes memory) {
require(block.number > _height, "not settled");
require(_buyer != address(0), "no recorded buyer");
kostko marked this conversation as resolved.
Show resolved Hide resolved
// TODO: optionally authenticate call from buyer
return _secret;
}
}
```

## Gas Padding

To prevent leaking information about a particular transaction, Sapphire
Expand Down
Loading