Skip to content

Commit

Permalink
Merge pull request #231 from oasisprotocol/CU-86934gu0x_Add-security-…
Browse files Browse the repository at this point in the history
…notice-for-block-checking_Xi-Zhang

Add Security documentation to ensure finality
  • Loading branch information
aefhm authored Jan 30, 2024
2 parents d20b73d + 1418969 commit 07c6aa6
Showing 1 changed file with 32 additions and 0 deletions.
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;
constructor(bytes memory _text) {
_secret = _text;
}
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");
// TODO: optionally authenticate call from buyer
return _secret;
}
}
```

## Gas Padding

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

0 comments on commit 07c6aa6

Please sign in to comment.