Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
cd863777
Unverified
Commit
cd863777
authored
Apr 24, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: Add separate keystore for local keys
parent
131ae0a1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
4 deletions
+178
-4
host.go
op-program/host/host.go
+4
-1
local.go
op-program/host/kvstore/local.go
+50
-0
local_test.go
op-program/host/kvstore/local_test.go
+56
-0
splitter.go
op-program/host/kvstore/splitter.go
+27
-0
splitter_test.go
op-program/host/kvstore/splitter_test.go
+38
-0
iface.go
op-program/preimage/iface.go
+3
-3
No files found.
op-program/host/host.go
View file @
cd863777
...
...
@@ -84,6 +84,9 @@ func FaultProofProgram(logger log.Logger, cfg *config.Config) error {
}
}
localPreimageSource
:=
kvstore
.
NewLocalPreimageSource
(
cfg
)
splitter
:=
kvstore
.
NewPreimageSourceSplitter
(
localPreimageSource
.
Get
,
getPreimage
)
// Setup pipe for preimage oracle interaction
pClientRW
,
pHostRW
:=
bidirectionalPipe
()
oracleServer
:=
preimage
.
NewOracleServer
(
pHostRW
)
...
...
@@ -93,7 +96,7 @@ func FaultProofProgram(logger log.Logger, cfg *config.Config) error {
defer
pHostRW
.
Close
()
defer
hHostRW
.
Close
()
routeHints
(
logger
,
hHost
,
hinter
)
launchOracleServer
(
logger
,
oracleServer
,
getPreimage
)
launchOracleServer
(
logger
,
oracleServer
,
splitter
.
Get
)
return
cl
.
ClientProgram
(
logger
,
...
...
op-program/host/kvstore/local.go
0 → 100644
View file @
cd863777
package
kvstore
import
(
"encoding/binary"
"encoding/json"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/preimage"
"github.com/ethereum/go-ethereum/common"
)
type
LocalPreimageSource
struct
{
config
*
config
.
Config
}
func
NewLocalPreimageSource
(
config
*
config
.
Config
)
*
LocalPreimageSource
{
return
&
LocalPreimageSource
{
config
}
}
func
localKey
(
num
int64
)
common
.
Hash
{
return
preimage
.
LocalIndexKey
(
num
)
.
PreimageKey
()
}
var
(
L1HeadKey
=
localKey
(
1
)
L2HeadKey
=
localKey
(
2
)
L2ClaimKey
=
localKey
(
3
)
L2ClaimBlockNumberKey
=
localKey
(
4
)
L2ChainConfigKey
=
localKey
(
5
)
RollupKey
=
localKey
(
6
)
)
func
(
s
*
LocalPreimageSource
)
Get
(
key
common
.
Hash
)
([]
byte
,
error
)
{
switch
key
{
case
L1HeadKey
:
return
s
.
config
.
L1Head
.
Bytes
(),
nil
case
L2HeadKey
:
return
s
.
config
.
L2Head
.
Bytes
(),
nil
case
L2ClaimKey
:
return
s
.
config
.
L2Claim
.
Bytes
(),
nil
case
L2ClaimBlockNumberKey
:
return
binary
.
BigEndian
.
AppendUint64
(
nil
,
s
.
config
.
L2ClaimBlockNumber
),
nil
case
L2ChainConfigKey
:
return
json
.
Marshal
(
s
.
config
.
L2ChainConfig
)
case
RollupKey
:
return
json
.
Marshal
(
s
.
config
.
Rollup
)
default
:
return
nil
,
ErrNotFound
}
}
op-program/host/kvstore/local_test.go
0 → 100644
View file @
cd863777
package
kvstore
import
(
"encoding/binary"
"encoding/json"
"testing"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/preimage"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)
func
TestLocalPreimageSource
(
t
*
testing
.
T
)
{
cfg
:=
&
config
.
Config
{
Rollup
:
&
chaincfg
.
Goerli
,
L1Head
:
common
.
HexToHash
(
"0x1111"
),
L2Head
:
common
.
HexToHash
(
"0x2222"
),
L2Claim
:
common
.
HexToHash
(
"0x3333"
),
L2ClaimBlockNumber
:
1234
,
L2ChainConfig
:
params
.
GoerliChainConfig
,
}
source
:=
NewLocalPreimageSource
(
cfg
)
tests
:=
[]
struct
{
name
string
key
common
.
Hash
expected
[]
byte
}{
{
"L1Head"
,
L1HeadKey
,
cfg
.
L1Head
.
Bytes
()},
{
"L2Head"
,
L2HeadKey
,
cfg
.
L2Head
.
Bytes
()},
{
"L2Claim"
,
L2ClaimKey
,
cfg
.
L2Claim
.
Bytes
()},
{
"L2ClaimBlockNumber"
,
L2ClaimBlockNumberKey
,
binary
.
BigEndian
.
AppendUint64
(
nil
,
cfg
.
L2ClaimBlockNumber
)},
{
"Rollup"
,
RollupKey
,
asJson
(
t
,
cfg
.
Rollup
)},
{
"ChainConfig"
,
L2ChainConfigKey
,
asJson
(
t
,
cfg
.
L2ChainConfig
)},
{
"Unknown"
,
preimage
.
LocalIndexKey
(
1000
)
.
PreimageKey
(),
nil
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
result
,
err
:=
source
.
Get
(
test
.
key
)
if
test
.
expected
==
nil
{
require
.
ErrorIs
(
t
,
err
,
ErrNotFound
)
}
else
{
require
.
NoError
(
t
,
err
)
}
require
.
Equal
(
t
,
test
.
expected
,
result
)
})
}
}
func
asJson
(
t
*
testing
.
T
,
v
any
)
[]
byte
{
d
,
err
:=
json
.
Marshal
(
v
)
require
.
NoError
(
t
,
err
)
return
d
}
op-program/host/kvstore/splitter.go
0 → 100644
View file @
cd863777
package
kvstore
import
(
"github.com/ethereum-optimism/optimism/op-program/preimage"
"github.com/ethereum/go-ethereum/common"
)
type
PreimageSource
func
(
key
common
.
Hash
)
([]
byte
,
error
)
type
PreimageSourceSplitter
struct
{
local
PreimageSource
global
PreimageSource
}
func
NewPreimageSourceSplitter
(
local
PreimageSource
,
global
PreimageSource
)
*
PreimageSourceSplitter
{
return
&
PreimageSourceSplitter
{
local
:
local
,
global
:
global
,
}
}
func
(
s
*
PreimageSourceSplitter
)
Get
(
key
common
.
Hash
)
([]
byte
,
error
)
{
if
key
[
0
]
==
byte
(
preimage
.
LocalKeyType
)
{
return
s
.
local
(
key
)
}
return
s
.
global
(
key
)
}
op-program/host/kvstore/splitter_test.go
0 → 100644
View file @
cd863777
package
kvstore
import
(
"testing"
"github.com/ethereum-optimism/optimism/op-program/preimage"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func
TestPreimageSourceSplitter
(
t
*
testing
.
T
)
{
localResult
:=
[]
byte
{
1
}
globalResult
:=
[]
byte
{
2
}
local
:=
func
(
key
common
.
Hash
)
([]
byte
,
error
)
{
return
localResult
,
nil
}
global
:=
func
(
key
common
.
Hash
)
([]
byte
,
error
)
{
return
globalResult
,
nil
}
splitter
:=
NewPreimageSourceSplitter
(
local
,
global
)
tests
:=
[]
struct
{
name
string
keyPrefix
byte
expected
[]
byte
}{
{
"Local"
,
byte
(
preimage
.
LocalKeyType
),
localResult
},
{
"Keccak"
,
byte
(
preimage
.
Keccak256KeyType
),
globalResult
},
{
"Generic"
,
byte
(
3
),
globalResult
},
{
"Reserved"
,
byte
(
4
),
globalResult
},
{
"Application"
,
byte
(
255
),
globalResult
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
key
:=
common
.
Hash
{
0xff
}
key
[
0
]
=
test
.
keyPrefix
res
,
err
:=
splitter
.
Get
(
key
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
test
.
expected
,
res
)
})
}
}
op-program/preimage/iface.go
View file @
cd863777
...
...
@@ -33,8 +33,8 @@ const (
_
KeyType
=
0
// LocalKeyType is for input-type pre-images, specific to the local program instance.
LocalKeyType
KeyType
=
1
// Keccak25
Key6
Type is for keccak256 pre-images, for any global shared pre-images.
Keccak25
Key6
Type
KeyType
=
2
// Keccak25
6Key
Type is for keccak256 pre-images, for any global shared pre-images.
Keccak25
6Key
Type
KeyType
=
2
)
// LocalIndexKey is a key local to the program, indexing a special program input.
...
...
@@ -51,7 +51,7 @@ type Keccak256Key common.Hash
func
(
k
Keccak256Key
)
PreimageKey
()
(
out
common
.
Hash
)
{
out
=
common
.
Hash
(
k
)
// copy the keccak hash
out
[
0
]
=
byte
(
Keccak25
Key6
Type
)
// apply prefix
out
[
0
]
=
byte
(
Keccak25
6Key
Type
)
// apply prefix
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment