Skip to content

Commit

Permalink
Merge pull request #1773 from oasisprotocol/kostko/feature/rofl
Browse files Browse the repository at this point in the history
Add support for ROFL
  • Loading branch information
kostko authored Jul 3, 2024
2 parents dfa1d9b + 9f744c3 commit de6715a
Show file tree
Hide file tree
Showing 106 changed files with 5,351 additions and 589 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ jobs:
# NOTE: This name appears in GitHub's Checks API.
name: e2e-ts-web-rt
runs-on: ubuntu-latest
env:
# Run all E2E tests in mock SGX.
OASIS_UNSAFE_SKIP_AVR_VERIFY: 1
OASIS_UNSAFE_ALLOW_DEBUG_ENCLAVES: 1
OASIS_UNSAFE_MOCK_SGX: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
26 changes: 24 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ members = [
"tests/runtimes/simple-consensus",
"tests/runtimes/simple-evm",
"tests/runtimes/simple-contracts",
"tests/runtimes/components-ronl",
"tests/runtimes/components-rofl",
]
exclude = [
# Test contracts.
Expand Down
3 changes: 3 additions & 0 deletions client-sdk/go/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/core"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/evm"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rewards"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
)

// RuntimeClient is a client.RuntimeClient augmented with commonly used modules.
Expand All @@ -34,6 +35,7 @@ type RuntimeClient struct {
ConsensusAccounts consensusaccounts.V1
Contracts contracts.V1
Evm evm.V1
ROFL rofl.V1
}

// Connection is the general node connection interface.
Expand Down Expand Up @@ -74,6 +76,7 @@ func (c *connection) Runtime(pt *config.ParaTime) RuntimeClient {
ConsensusAccounts: consensusaccounts.NewV1(cli),
Contracts: contracts.NewV1(cli),
Evm: evm.NewV1(cli),
ROFL: rofl.NewV1(cli),
}
}

Expand Down
3 changes: 0 additions & 3 deletions client-sdk/go/modules/consensusaccounts/consensus_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ func (a *v1) GetEvents(ctx context.Context, round uint64) ([]*Event, error) {
if err != nil {
return nil, err
}
if ev == nil {
continue
}
for _, e := range ev {
evs = append(evs, e.(*Event))
}
Expand Down
3 changes: 0 additions & 3 deletions client-sdk/go/modules/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ func (a *v1) GetEvents(ctx context.Context, round uint64) ([]*Event, error) {
if err != nil {
return nil, err
}
if ev == nil {
continue
}
for _, e := range ev {
evs = append(evs, e.(*Event))
}
Expand Down
4 changes: 2 additions & 2 deletions client-sdk/go/modules/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ type EstimateGasQuery struct {
PropagateFailures bool `json:"propagate_failures,omitempty"`
}

// GasCosts are the consensus accounts module gas costs.
// GasCosts are the core module gas costs.
type GasCosts struct {
TxByte uint64 `json:"tx_byte"`
AuthSignature uint64 `json:"auth_signature"`
AuthMultisigSigner uint64 `json:"auth_multisig_signer"`
CallformatX25519Deoxysii uint64 `json:"callformat_x25519_deoxysii"`
}

// Parameters are the parameters for the consensus accounts module.
// Parameters are the parameters for the core module.
type Parameters struct {
MaxBatchGas uint64 `json:"max_batch_gas"`
MaxTxSigners uint32 `json:"max_tx_signers"`
Expand Down
97 changes: 97 additions & 0 deletions client-sdk/go/modules/rofl/app_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package rofl

import (
"encoding"
"encoding/binary"

"github.com/oasisprotocol/oasis-core/go/common/crypto/address"
"github.com/oasisprotocol/oasis-core/go/common/encoding/bech32"

"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

var (
// AppIDV0CRIContext is the unique context for v0 creator/round/index application identifiers.
AppIDV0CRIContext = address.NewContext("oasis-sdk/rofl: cri app id", 0)
// AppIDV0GlobalNameContext is the unique context for v0 global name application identifiers.
AppIDV0GlobalNameContext = address.NewContext("oasis-sdk/rofl: global name app id", 0)
// AppIDBech32HRP is the unique human readable part of Bech32 encoded application identifiers.
AppIDBech32HRP = address.NewBech32HRP("rofl")

_ encoding.BinaryMarshaler = AppID{}
_ encoding.BinaryUnmarshaler = (*AppID)(nil)
_ encoding.TextMarshaler = AppID{}
_ encoding.TextUnmarshaler = (*AppID)(nil)
)

// AppID is the ROFL application identifier.
type AppID address.Address

// MarshalBinary encodes an application identifier into binary form.
func (a AppID) MarshalBinary() ([]byte, error) {
return (address.Address)(a).MarshalBinary()
}

// UnmarshalBinary decodes a binary marshaled application identifier.
func (a *AppID) UnmarshalBinary(data []byte) error {
return (*address.Address)(a).UnmarshalBinary(data)
}

// MarshalText encodes an application identifier into text form.
func (a AppID) MarshalText() ([]byte, error) {
return (address.Address)(a).MarshalBech32(AppIDBech32HRP)
}

// UnmarshalText decodes a text marshaled application identifier.
func (a *AppID) UnmarshalText(text []byte) error {
return (*address.Address)(a).UnmarshalBech32(AppIDBech32HRP, text)
}

// Equal compares vs another application identifier for equality.
func (a AppID) Equal(cmp AppID) bool {
return (address.Address)(a).Equal((address.Address)(cmp))
}

// String returns the string representation of an application identifier.
func (a AppID) String() string {
bech32Addr, err := bech32.Encode(AppIDBech32HRP.String(), a[:])
if err != nil {
return "[malformed]"
}
return bech32Addr
}

// NewAppIDCreatorRoundIndex creates a new application identifier from the given creator/round/index
// tuple.
func NewAppIDCreatorRoundIndex(creator types.Address, round uint64, index uint32) AppID {
data := make([]byte, address.Size+8+4)

rawCreator, _ := creator.MarshalBinary()
copy(data[:address.Size], rawCreator)

binary.BigEndian.PutUint64(data[address.Size:], round)
binary.BigEndian.PutUint32(data[address.Size+8:], index)

return NewAppIDRaw(AppIDV0CRIContext, data)
}

// NewAppIDGlobalName creates a new application identifier from the given global name.
func NewAppIDGlobalName(name string) AppID {
return NewAppIDRaw(AppIDV0GlobalNameContext, []byte(name))
}

// NewAppIDRaw creates a new application identifier from passed context and data.
func NewAppIDRaw(ctx address.Context, data []byte) AppID {
return (AppID)(address.NewAddress(ctx, data))
}

// NewAppIDFromBech32 creates a new application identifier from the given bech-32 encoded string.
//
// Panics in case of errors -- use UnmarshalText if you want to handle errors.
func NewAppIDFromBech32(data string) (a AppID) {
err := a.UnmarshalText([]byte(data))
if err != nil {
panic(err)
}
return
}
28 changes: 28 additions & 0 deletions client-sdk/go/modules/rofl/app_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rofl

import (
"testing"

"github.com/stretchr/testify/require"

sdkTesting "github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing"
)

func TestIdentifierV0(t *testing.T) {
require := require.New(t)

appID := NewAppIDCreatorRoundIndex(sdkTesting.Alice.Address, 42, 0)
require.Equal("rofl1qr98wz5t6q4x8ng6a5l5v7rqlx90j3kcnun5dwht", appID.String())

appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 42, 0)
require.Equal("rofl1qrd45eaj4tf6l7mjw5prcukz75wdmwg6kggt6pnp", appID.String())

appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 1, 0)
require.Equal("rofl1qzmuyfwygnmfralgtwrqx8kcm587kwex9y8hf9hf", appID.String())

appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 42, 1)
require.Equal("rofl1qzmh56f52yd0tcqh757fahzc7ec49s8kaguyylvu", appID.String())

appID = NewAppIDGlobalName("test global app")
require.Equal("rofl1qrev5wq76npkmcv5wxkdxxcu4dhmu704yyl30h43", appID.String())
}
46 changes: 46 additions & 0 deletions client-sdk/go/modules/rofl/policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package rofl

import (
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/sgx"
"github.com/oasisprotocol/oasis-core/go/common/sgx/quote"
)

// AppAuthPolicy is the per-application ROFL policy.
type AppAuthPolicy struct {
// Quotes is a quote policy.
Quotes quote.Policy `json:"quotes"`
// Enclaves is the set of allowed enclave identities.
Enclaves []sgx.EnclaveIdentity `json:"enclaves"`
// Endorsements is the set of allowed endorsements.
Endorsements []AllowedEndorsement `json:"endorsements"`
// Fees is the gas fee payment policy.
Fees FeePolicy `json:"fees"`
// MaxExpiration is the maximum number of future epochs for which one can register.
MaxExpiration beacon.EpochTime `json:"max_expiration"`
}

// AllowedEndorsement is an allowed endorsement policy.
type AllowedEndorsement struct {
// Any specifies that any node can endorse the enclave.
Any *struct{} `json:"any,omitempty"`
// ComputeRole specifies that a compute node can endorse the enclave.
ComputeRole *struct{} `json:"role_compute,omitempty"`
// ObserverRole specifies that an observer node can endorse the enclave.
ObserverRole *struct{} `json:"role_observer,omitempty"`
// Entity specifies that a registered node from a specific entity can endorse the enclave.
Entity *signature.PublicKey `json:"entity,omitempty"`
// Node specifies that a specific node can endorse the enclave.
Node *signature.PublicKey `json:"node,omitempty"`
}

// FeePolicy is a gas fee payment policy.
type FeePolicy uint8

const (
// FeePolicyAppPays is a fee policy where the application enclave pays the gas fees.
FeePolicyAppPays FeePolicy = 1
// FeePolicyEndorsingNodePays is a fee policy where the endorsing node pays the gas fees.
FeePolicyEndorsingNodePays FeePolicy = 2
)
Loading

0 comments on commit de6715a

Please sign in to comment.