-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into pedro/rollup_producti…
…on_based_on_size
- Loading branch information
Showing
12 changed files
with
258 additions
and
45 deletions.
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
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
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,10 @@ | ||
--- | ||
--- | ||
# Testnet Security | ||
|
||
The first Obscuro Testnet is focused on functionality and the User and Developer experience. | ||
|
||
Privacy features require special attention from the core and security audit team and will be finalised in a | ||
future version of Testnet. | ||
|
||
As a user of the "Obscuro Testnet", do not expect the data you are loading to be 100% private. |
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,29 @@ | ||
--- | ||
--- | ||
# Developer quick start | ||
|
||
The only difference between an Obscuro and an Ethereum (or Arbitrum) dApp is that on Obscuro you can hide the internal | ||
state of the contract. | ||
|
||
The most obvious example is that an ERC20 token deployed on Obscuro will not respond to balance requests unless you are | ||
the account owner. | ||
|
||
In Obscuro, the internal node database is encrypted, and the contract execution is also encrypted inside the TEE. | ||
The calls to [getStorageAt](https://docs.alchemy.com/reference/eth-getstorageat) are disabled, so all data access | ||
requests will be performed through view functions which are under the control of the smart contract developer. | ||
|
||
Nobody (which includes node operators and the sequencer) can access the internal state of a contract. | ||
|
||
**The only thing you have to do when porting a dApp to Obscuro is to add a check in your view functions comparing | ||
the `tx.origing` and `msg.sender` against the accounts allowed to access that data.** | ||
|
||
The snippet below illustrates this for an [ERC20 token](https://github.com/obscuronet/sample-applications/blob/main/number-guessing-game/contracts/ERC20.sol#L25). | ||
|
||
```solidity | ||
function balanceOf(address tokenOwner) public view override returns (uint256) { | ||
require(tx.origin == tokenOwner || msg.sender == tokenOwner, "Only the token owner can see the balance."); | ||
return balances[tokenOwner]; | ||
} | ||
``` | ||
|
||
_Note that this works because in Obscuro all calls to view functions are authenticated._ |
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
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
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
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
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
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,129 @@ | ||
package manualtests | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/obscuronet/go-obscuro/tools/walletextension/common" | ||
"github.com/stretchr/testify/require" | ||
"github.com/valyala/fasthttp" | ||
|
||
gethcommon "github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func TestSubscribeToOG(t *testing.T) { | ||
t.Skip("skip manual tests") | ||
|
||
// Using http | ||
ogHTTPAddress := "https://dev-testnet.obscu.ro:443" | ||
ogWSAddress := "wss://dev-testnet.obscu.ro:81" | ||
// ogWSAddress := "ws://51.132.131.47:81" | ||
|
||
// join the network | ||
statusCode, userID, err := fasthttp.Get(nil, fmt.Sprintf("%s/v1/join/", ogHTTPAddress)) | ||
require.NoError(t, err) // dialing to the given TCP address timed out | ||
fmt.Println(statusCode) | ||
fmt.Println(userID) | ||
|
||
// sign the message | ||
messagePayload := signMessage(string(userID)) | ||
|
||
// register an account | ||
var regAccountResp []byte | ||
regAccountResp, err = registerAccount(ogHTTPAddress, string(userID), messagePayload) | ||
require.NoError(t, err) | ||
fmt.Println(string(regAccountResp)) | ||
fmt.Println(hex.EncodeToString(regAccountResp)) | ||
|
||
// Using WS -> | ||
|
||
// Connect to WebSocket server using the standard geth client | ||
client, err := ethclient.Dial(ogWSAddress) | ||
require.NoError(t, err) | ||
|
||
// Create a simple request | ||
at, err := client.BalanceAt(context.Background(), l2Wallet.Address(), nil) | ||
require.NoError(t, err) | ||
|
||
fmt.Println("Balance for account ", l2Wallet.Address().Hex(), " - ", at.String()) | ||
|
||
// Create a subscription | ||
query := ethereum.FilterQuery{ | ||
Addresses: []gethcommon.Address{l2Wallet.Address()}, | ||
} | ||
|
||
logs := make(chan types.Log) | ||
sub, err := client.SubscribeFilterLogs(context.Background(), query, logs) | ||
if err != nil { | ||
log.Fatalf("Failed to subscribe: %v", err) | ||
} | ||
defer sub.Unsubscribe() | ||
|
||
// Listen for events from the contract | ||
for { | ||
select { | ||
case err := <-sub.Err(): | ||
log.Fatalf("Subscription error: %v", err) | ||
case vLog := <-logs: | ||
// Process the contract event | ||
// This is just a simple example printing the block number; you'll want to decode and handle the logs according to your contract's ABI | ||
log.Printf("Received log in block number: %v", vLog.BlockNumber) | ||
} | ||
} | ||
} | ||
|
||
func registerAccount(baseAddress, userID, payload string) ([]byte, error) { | ||
req, err := http.NewRequestWithContext( | ||
context.Background(), | ||
http.MethodPost, | ||
baseAddress+"/v1/authenticate/?u="+userID, | ||
strings.NewReader(payload), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
|
||
client := &http.Client{} | ||
response, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer response.Body.Close() | ||
return io.ReadAll(response.Body) | ||
} | ||
|
||
// { | ||
// "signature": "0xc784adea83ed3ec60528f4747418c85abe553b35a47fd2c95425de654bb9d0d40ede24aec182e6a2ec65c0c7c6aedab7823f21a9b9f7ff5db3a77a9f90dc97b41c", | ||
// "message": "Register e097c4a10d4285d13b377985834b4c57e069b5856cc6c2cd4a038f62da4bc459 for 0x06ed49a32fcc5094abee51a4ffd46dd23b62a191" | ||
// } | ||
func signMessage(userID string) string { | ||
pk := l2Wallet.PrivateKey() | ||
address := l2Wallet.Address() | ||
hexAddress := address.Hex() | ||
|
||
message := fmt.Sprintf("Register %s for %s", userID, strings.ToLower(hexAddress)) | ||
prefixedMessage := fmt.Sprintf(common.PersonalSignMessagePrefix, len(message), message) | ||
|
||
messageHash := crypto.Keccak256([]byte(prefixedMessage)) | ||
sig, err := crypto.Sign(messageHash, pk) | ||
if err != nil { | ||
log.Fatalf("Failed to sign message: %v", err) | ||
} | ||
sig[64] += 27 | ||
signature := "0x" + hex.EncodeToString(sig) | ||
payload := fmt.Sprintf("{\"signature\": \"%s\", \"message\": \"%s\"}", signature, message) | ||
fmt.Println(payload) | ||
return payload | ||
} |
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
Oops, something went wrong.