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

fix: Add docs for Smart Contracts #96

Merged
merged 50 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
dca0f1e
fix: added contracts in docs
nakul1010 Nov 22, 2023
b9ba1aa
fix: remove readme file
nakul1010 Nov 22, 2023
d92d70e
fix: add doc command in ci
nakul1010 Nov 22, 2023
c75366c
fix: change solidity comment
nakul1010 Nov 22, 2023
2eb9cd3
fix: revert changes done to ci
nakul1010 Nov 22, 2023
b1d2e34
fix: change label remove summary
nakul1010 Nov 22, 2023
cebdda1
fix: update contract docs
nakul1010 Nov 23, 2023
889506f
fix: py script added to modify docs
nakul1010 Nov 25, 2023
0582502
ci: fix formatting
nakul1010 Nov 25, 2023
033d654
fix: add comment
nakul1010 Nov 25, 2023
8bd56c9
fix: modify comment
nakul1010 Nov 25, 2023
27d6d5c
fix: modify comment
nakul1010 Nov 25, 2023
70baf25
Merge branch 'master' of https://github.com/bob-collective/bob into n…
nakul1010 Nov 29, 2023
5f4b0e7
fix: remove contracts dir
nakul1010 Nov 29, 2023
a76145d
Merge branch 'master' of https://github.com/bob-collective/bob into n…
nakul1010 Nov 29, 2023
535b6c3
Merge branch 'master' into nakul/feat_contract_docs
nakul1010 Dec 1, 2023
faeb1d8
Merge branch 'master' into nakul/feat_contract_docs
nakul1010 Dec 4, 2023
3c2d30e
fix: remove contracts docs
nakul1010 Dec 5, 2023
e8e240e
chore: format forge-rs docs as part of the build process
ns212 Dec 5, 2023
0973c17
chore: format forge-rs docs as part of the build process
ns212 Dec 5, 2023
6d0380c
fix: update sidebar script
nakul1010 Dec 5, 2023
e2d3831
fix: add comment
nakul1010 Dec 5, 2023
e1315ac
Merge branch 'nakul/feat_contract_docs' of https://github.com/bob-col…
nakul1010 Dec 5, 2023
6abff35
Merge pull request #104 from bob-collective/ci_forge
gregdhill Dec 6, 2023
e9e07df
chore: format forge-rs docs as part of the build process
ns212 Dec 6, 2023
f0e8381
chore: format forge-rs docs as part of the build process
ns212 Dec 6, 2023
47de700
Merge branch 'nakul/feat_contract_docs' into ci_forge
ns212 Dec 6, 2023
8300e03
fix: remove contracts dir from gitignore.
nakul1010 Dec 6, 2023
353b24c
Generate Foundry docs
nakul1010 Dec 6, 2023
20be054
Merge pull request #106 from bob-collective/ci_forge
nakul1010 Dec 6, 2023
a1d94f0
Merge branch 'master' into nakul/feat_contract_docs
nakul1010 Dec 6, 2023
93a7ef5
Generate Foundry docs
nakul1010 Dec 6, 2023
1ac20ae
fix: update commit message.
nakul1010 Dec 6, 2023
51411a1
chore: Generate Foundry docs
nakul1010 Dec 6, 2023
4b30b16
fix: move script to docs folder.
nakul1010 Dec 13, 2023
456fe37
chore: Generate Foundry docs
nakul1010 Dec 13, 2023
3e99672
Merge branch 'master' into nakul/feat_contract_docs
nakul1010 Dec 13, 2023
80772f7
chore: Generate Foundry docs
nakul1010 Dec 13, 2023
1f61394
fix: update ci
nakul1010 Dec 13, 2023
2956bf2
chore: Generate Foundry docs
nakul1010 Dec 13, 2023
d9c9196
fix: remove python script command from ci
nakul1010 Dec 13, 2023
2ea7c12
chore: Generate Foundry docs
nakul1010 Dec 13, 2023
eeecf07
fix: remove python command from package.json
nakul1010 Dec 13, 2023
9c01c7c
Merge remote-tracking branch 'origin/nakul/feat_contract_docs' into n…
nakul1010 Dec 13, 2023
413a802
fix: remove python command from package.json
nakul1010 Dec 13, 2023
f4a21be
chore: Generate Foundry docs
nakul1010 Dec 13, 2023
299e080
Merge branch 'master' into nakul/feat_contract_docs
nakul1010 Dec 15, 2023
6d14140
chore: Generate Foundry docs
nakul1010 Dec 15, 2023
8566870
Merge branch 'master' into nakul/feat_contract_docs
nud3l Dec 21, 2023
1817d76
chore: Generate Foundry docs
nud3l Dec 21, 2023
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
18 changes: 15 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ env:

jobs:
check:
strategy:
fail-fast: true

name: Foundry
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
Expand All @@ -37,3 +38,14 @@ jobs:
run: |
forge test -vvv
id: test

- name: Run Forge docs
run: |
forge doc --out docs/docs/contracts
python3 docs_reformat_scripts/forge_doc_reformat.py
nud3l marked this conversation as resolved.
Show resolved Hide resolved

- name: Commit Forge docs
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Generate Foundry docs"
file_pattern: "./docs/"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ out/
node_modules/*

# generated docs
/docs/docs/api/*
/docs/docs/api/*
1 change: 1 addition & 0 deletions docs/docs/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book/
13 changes: 13 additions & 0 deletions docs/docs/contracts/book.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
table {
margin: 0 auto;
border-collapse: collapse;
width: 100%;
}

table td:first-child {
width: 15%;
}

table td:nth-child(2) {
width: 25%;
}
12 changes: 12 additions & 0 deletions docs/docs/contracts/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[book]
src = "src"
title = ""

[output.html]
no-section-label = true
additional-js = ["solidity.min.js"]
additional-css = ["book.css"]
git-repository-url = "https://github.com/bob-collective/bob"

[output.html.fold]
enable = true
7 changes: 7 additions & 0 deletions docs/docs/contracts/contract_references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Smart Contracts

The source code for the smart contracts can be found in the following repository:

- [Relay Smart Contracts](https://github.com/bob-collective/bob/tree/master/src/relay)
- [Bridge Smart Contracts](https://github.com/bob-collective/bob/tree/master/src/bridge)
- [Swap Smart Contracts](https://github.com/bob-collective/bob/tree/master/src/swap)
74 changes: 74 additions & 0 deletions docs/docs/contracts/solidity.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0
}catch(e){return!1}}
var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/
;e()&&(a=a.source.replace(/\\b/g,"(?<!\\$)\\b"));var s={className:"number",
begin:a,relevance:0},n={
keyword:"assembly let function if switch case default for leave break continue u256 jump jumpi stop return revert selfdestruct invalid",
built_in:"add sub mul div sdiv mod smod exp not lt gt slt sgt eq iszero and or xor byte shl shr sar addmod mulmod signextend keccak256 pc pop dup1 dup2 dup3 dup4 dup5 dup6 dup7 dup8 dup9 dup10 dup11 dup12 dup13 dup14 dup15 dup16 swap1 swap2 swap3 swap4 swap5 swap6 swap7 swap8 swap9 swap10 swap11 swap12 swap13 swap14 swap15 swap16 mload mstore mstore8 sload sstore msize gas address balance selfbalance caller callvalue calldataload calldatasize calldatacopy codesize codecopy extcodesize extcodecopy returndatasize returndatacopy extcodehash create create2 call callcode delegatecall staticcall log0 log1 log2 log3 log4 chainid origin gasprice basefee blockhash coinbase timestamp number difficulty gaslimit",
literal:"true false"},i={className:"string",
begin:/\bhex'(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?'/},t={className:"string",
begin:/\bhex"(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?"/};function r(e){
return e.inherit(e.APOS_STRING_MODE,{begin:/(\bunicode)?'/})}function l(e){
return e.inherit(e.QUOTE_STRING_MODE,{begin:/(\bunicode)?"/})}var o={
SOL_ASSEMBLY_KEYWORDS:n,baseAssembly:e=>{
var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{
begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params",
begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={
className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c,
contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{
className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0,
contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}},
solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i,
HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e}
;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o
;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1
;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i
;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={
keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly",
literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",
built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4"
},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/
},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/,
excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={
begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{
built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max"
},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,
lexemes:C,keywords:p}),w={className:"built_in",
begin:(E()?"(?<!\\$)\\b":"\\b")+"(gas|value|salt)(?=:)"};function x(e,a){return{
begin:(E()?"(?<!\\$)\\b":"\\b")+e+"\\.\\s*",end:/[^A-Za-z0-9$_\.]/,
excludeBegin:!1,excludeEnd:!0,lexemes:C,keywords:{built_in:e+" "+a},
contains:[f],relevance:10}}var h=c(e),v=e.inherit(h,{
contains:h.contains.concat([{begin:/\./,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,
excludeEnd:!0,keywords:{built_in:"slot offset length address selector"},
relevance:2},{begin:/_/,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,
keywords:{built_in:"slot offset"},relevance:2}])});return{aliases:["sol"],
keywords:p,lexemes:C,
contains:[a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,b,w,O,{
className:"function",lexemes:C,
beginKeywords:"function modifier event constructor fallback receive error",
end:/[{;]/,excludeEnd:!0,
contains:[y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:/%/
},x("msg","gas value data sender sig"),x("block","blockhash coinbase difficulty gaslimit basefee number timestamp chainid"),x("tx","gasprice origin"),x("abi","decode encode encodePacked encodeWithSelector encodeWithSignature encodeCall"),x("bytes","concat"),f,{
className:"class",lexemes:C,beginKeywords:"contract interface library",end:"{",
excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"is",lexemes:C
},y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{lexemes:C,
beginKeywords:"struct enum",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{
beginKeywords:"import",end:";",lexemes:C,keywords:"import from as",
contains:[y,a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{
beginKeywords:"using",end:";",lexemes:C,keywords:"using for",
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{className:"meta",
beginKeywords:"pragma",end:";",lexemes:C,keywords:{
keyword:"pragma solidity experimental abicoder",
built_in:"ABIEncoderV2 SMTChecker v1 v2"},
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(a,{
className:"meta-string"}),e.inherit(s,{className:"meta-string"})]},{
beginKeywords:"assembly",end:/\b\B/,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(v,{begin:"{",
end:"}",endsParent:!0,contains:v.contains.concat([e.inherit(v,{begin:"{",
end:"}",contains:v.contains.concat(["self"])})])})]}],illegal:/#/}}})());

// Ugly hack to reload HLJS
hljs.initHighlightingOnLoad();
48 changes: 48 additions & 0 deletions docs/docs/contracts/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Build on Bitcoin

BOB is a Bitcoin-augmented rollup bringing experimentation and freedom of choice to builders to make a real-world impact. BOBs vision is to onboard the next billion users to Bitcoin.

## Learn more

- [Website](https://www.gobob.xyz/)
- [Docs](https://docs.gobob.xyz/)

## Contribution

BOB is an open-source project. We welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing code, and helping us improve our community.

## Getting Started

We use foundry extensively for maintaining and testing this contract suite:

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

## Local Testnet

To deploy the relay contract to a local environment for testing use our convenience script [here](https://github.com/bob-collective/bob/blob/master/sdk/scripts/init-bridge.ts):

```shell
# start local ethereum testnet node
docker-compose up anvil
# run script to deploy the relay contract
cd sdk
yarn run deploy-relay --init-height 2016 --private-key dev-0 --dev --network testnet
```

The initialization height should be a multiple of 2016 with at least one subsequent retarget (i.e. if using 2016 as the starting height, blocks 4031-4032 must exist).
19 changes: 19 additions & 0 deletions docs/docs/contracts/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Summary
- [Home](README.md)
# src
- [❱ bridge](src/bridge/README.md)
- [BitcoinTx](src/bridge/BitcoinTx.sol/library.BitcoinTx.md)
- [BridgeState](src/bridge/BridgeState.sol/library.BridgeState.md)
- [IRelay](src/bridge/IRelay.sol/interface.IRelay.md)
- [WitnessTx](src/bridge/WitnessTx.sol/library.WitnessTx.md)
- [❱ relay](src/relay/README.md)
- [Epoch](src/relay/LightRelay.sol/struct.Epoch.md)
- [ILightRelay](src/relay/LightRelay.sol/interface.ILightRelay.md)
- [RelayUtils](src/relay/LightRelay.sol/library.RelayUtils.md)
- [LightRelay](src/relay/LightRelay.sol/contract.LightRelay.md)
- [TestLightRelay](src/relay/TestLightRelay.sol/contract.TestLightRelay.md)
- [❱ swap](src/swap/README.md)
- [Bridge](src/swap/Bridge.sol/contract.Bridge.md)
- [BtcMarketPlace](src/swap/Btc_Marketplace.sol/contract.BtcMarketPlace.md)
- [MarketPlace](src/swap/Marketplace.sol/contract.MarketPlace.md)
- [BobWrappedBtc](src/swap/Wrapped.sol/contract.BobWrappedBtc.md)
6 changes: 6 additions & 0 deletions docs/docs/contracts/src/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


# Contents
- [bridge](/src/bridge)
- [relay](/src/relay)
- [swap](/src/swap)
138 changes: 138 additions & 0 deletions docs/docs/contracts/src/src/bridge/BitcoinTx.sol/library.BitcoinTx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# BitcoinTx
gregdhill marked this conversation as resolved.
Show resolved Hide resolved
[Git Source](https://github.com/bob-collective/bob/blob/a99b3699ad3d0a3694628b215f3ada9fa41517db/src/bridge/BitcoinTx.sol)

Allows to reference Bitcoin raw transaction in Solidity.

*See https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format*


## Functions
### validateProof

Validates the SPV proof of the Bitcoin transaction.
Reverts in case the validation or proof verification fail.


```solidity
function validateProof(BridgeState.Storage storage self, Info memory txInfo, Proof memory proof)
internal
view
returns (bytes32 txHash);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`self`|`BridgeState.Storage`||
|`txInfo`|`Info`|Bitcoin transaction data.|
|`proof`|`Proof`|Bitcoin proof data.|

**Returns**

|Name|Type|Description|
|----|----|-----------|
|`txHash`|`bytes32`|Proven 32-byte transaction hash.|


### evaluateProofDifficulty

Evaluates the given Bitcoin proof difficulty against the actual
Bitcoin chain difficulty provided by the relay oracle.
Reverts in case the evaluation fails.


```solidity
function evaluateProofDifficulty(BridgeState.Storage storage self, bytes memory bitcoinHeaders) internal view;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`self`|`BridgeState.Storage`||
|`bitcoinHeaders`|`bytes`|Bitcoin headers chain being part of the SPV proof. Used to extract the observed proof difficulty.|


### getTxOutputValue

Processes the Bitcoin transaction output vector.


```solidity
function getTxOutputValue(bytes32 scriptPubKeyHash, bytes memory txOutputVector) internal returns (uint64 value);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`scriptPubKeyHash`|`bytes32`|Expected Bitcoin scriptPubKey keccak256 hash.|
|`txOutputVector`|`bytes`|Bitcoin transaction output vector. This function assumes vector's structure is valid so it must be validated using e.g. `BTCUtils.validateVout` function before it is passed here.|

**Returns**

|Name|Type|Description|
|----|----|-----------|
|`value`|`uint64`|Outcomes of the processing.|


### getTxOutputValue

Processes all outputs from the transaction.


```solidity
function getTxOutputValue(
bytes32 scriptPubKeyHash,
bytes memory txOutputVector,
TxOutputsProcessingInfo memory processInfo
) internal returns (uint64 value);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`scriptPubKeyHash`|`bytes32`|Expected Bitcoin scriptPubKey keccak256 hash.|
|`txOutputVector`|`bytes`|Bitcoin transaction output vector. This function assumes vector's structure is valid so it must be validated using e.g. `BTCUtils.validateVout` function before it is passed here.|
|`processInfo`|`TxOutputsProcessingInfo`|TxOutputsProcessingInfo identifying output starting index and the number of outputs.|


## Structs
### Info
Represents Bitcoin transaction data.


```solidity
struct Info {
bytes4 version;
bytes inputVector;
bytes outputVector;
bytes4 locktime;
}
```

### Proof
Represents data needed to perform a Bitcoin SPV proof.


```solidity
struct Proof {
bytes merkleProof;
uint256 txIndexInBlock;
bytes bitcoinHeaders;
}
```

### TxOutputsProcessingInfo
Represents temporary information needed during the processing of
the Bitcoin transaction outputs. This structure is an internal one
and should not be exported outside of the transaction processing code.

*Allows to mitigate "stack too deep" errors on EVM.*


```solidity
struct TxOutputsProcessingInfo {
uint256 outputStartingIndex;
uint256 outputsCount;
}
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BridgeState
[Git Source](https://github.com/bob-collective/bob/blob/a99b3699ad3d0a3694628b215f3ada9fa41517db/src/bridge/BridgeState.sol)


## Structs
### Storage

```solidity
struct Storage {
IRelay relay;
uint96 txProofDifficultyFactor;
}
```

Loading