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
172181cf
Unverified
Commit
172181cf
authored
Apr 28, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example: add program with pre-image oracle usage
parent
d1e3c28e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
8 deletions
+91
-8
test.yml
.github/workflows/test.yml
+1
-1
Makefile
example/Makefile
+16
-7
go.mod
example/claim/go.mod
+12
-0
go.sum
example/claim/go.sum
+8
-0
main.go
example/claim/main.go
+54
-0
No files found.
.github/workflows/test.yml
View file @
172181cf
...
@@ -45,7 +45,7 @@ jobs:
...
@@ -45,7 +45,7 @@ jobs:
${{ runner.os }}-go-${{ matrix.go-version }}-
${{ runner.os }}-go-${{ matrix.go-version }}-
-
name
:
Build examples
-
name
:
Build examples
working-directory
:
./example
working-directory
:
./example
run
:
make
bin/minimal.elf
run
:
make
-
name
:
build contracts
-
name
:
build contracts
working-directory
:
./contracts
working-directory
:
./contracts
run
:
forge build
run
:
forge build
...
...
example/Makefile
View file @
172181cf
all
:
elf dump
.PHONY
:
elf
elf
:
$(patsubst %/go.mod
,
bin/%.elf
,
$(wildcard */go.mod))
.PHONY
:
dump
dump
:
$(patsubst %/go.mod
,
bin/%.dump
,
$(wildcard */go.mod))
bin
:
bin
:
mkdir
bin
mkdir
bin
bin/hello.elf
:
bin
# take any directory with a go mod, and build an ELF
cd
hello
&&
GOOS
=
linux
GOARCH
=
mips
GOMIPS
=
softfloat go build
-o
../bin/hello.elf .
# verify output with: readelf -h bin/<name>.elf
# verify output with: readelf -h bin/hello.elf
# result is mips32, big endian, R3000
# result is mips32, big endian, R3000
bin/%.elf
:
bin
cd
$
(
@:bin/%.elf
=
%
)
&&
GOOS
=
linux
GOARCH
=
mips
GOMIPS
=
softfloat go build
-o
../
$@
.
bin/hello.dump
:
bin/hello.elf
# take any ELF and dump it
# TODO: currently have the little-endian toolchain, but should use the big-endian one. The -EB compat flag works though.
# TODO: currently have the little-endian toolchain, but should use the big-endian one. The -EB compat flag works though.
mipsel-linux-gnu-objdump
-D
--disassembler-options
=
no-aliases
--wide
--source
-m
mips:3000
-EB
bin/hello.elf
>
bin/hello.dump
bin/%.dump
:
bin/%.elf
mipsel-linux-gnu-objdump
-D
--disassembler-options
=
no-aliases
--wide
--source
-m
mips:3000
-EB
$
(
@:%.dump
=
%.elf
)
>
$@
example/claim/go.mod
0 → 100644
View file @
172181cf
module claim
go 1.20
require github.com/ethereum-optimism/cannon/preimage v0.0.0
require (
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/sys v0.7.0 // indirect
)
replace github.com/ethereum-optimism/cannon/preimage v0.0.0 => ../../preimage
example/claim/go.sum
0 → 100644
View file @
172181cf
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
example/claim/main.go
0 → 100644
View file @
172181cf
package
main
import
(
"encoding/binary"
"fmt"
"os"
"github.com/ethereum-optimism/cannon/preimage"
)
type
rawHint
string
func
(
rh
rawHint
)
Hint
()
string
{
return
string
(
rh
)
}
func
main
()
{
_
,
_
=
os
.
Stdout
.
Write
([]
byte
(
"started!"
))
po
:=
preimage
.
NewOracleClient
(
preimage
.
ClientPreimageChannel
())
hinter
:=
preimage
.
NewHintWriter
(
preimage
.
ClientHinterChannel
())
preHash
:=
po
.
Get
(
preimage
.
LocalIndexKey
(
0
))
diffHash
:=
po
.
Get
(
preimage
.
LocalIndexKey
(
1
))
claimData
:=
po
.
Get
(
preimage
.
LocalIndexKey
(
2
))
// Hints are used to indicate which things the program will access,
// so the server can be prepared to serve the corresponding pre-images.
hinter
.
Hint
(
rawHint
(
fmt
.
Sprintf
(
"fetch-state %x"
,
preHash
)))
pre
:=
po
.
Get
(
preimage
.
Keccak256Key
(
preHash
))
// Multiple pre-images may be fetched based on a hint.
// E.g. when we need all values of a merkle-tree.
hinter
.
Hint
(
rawHint
(
fmt
.
Sprintf
(
"fetch-diff %x"
,
diffHash
)))
diff
:=
po
.
Get
(
preimage
.
Keccak256Key
(
diffHash
))
diffPartA
:=
po
.
Get
(
preimage
.
Keccak256Key
(
*
(
*
[
32
]
byte
)(
diff
[
:
32
])))
diffPartB
:=
po
.
Get
(
preimage
.
Keccak256Key
(
*
(
*
[
32
]
byte
)(
diff
[
32
:
])))
// Example state-transition function: s' = s*a + b
s
:=
binary
.
BigEndian
.
Uint64
(
pre
)
a
:=
binary
.
BigEndian
.
Uint64
(
diffPartA
)
b
:=
binary
.
BigEndian
.
Uint64
(
diffPartB
)
fmt
.
Printf
(
"computing %d * %d + %d
\n
"
,
s
,
a
,
b
)
sOut
:=
s
*
a
+
b
sClaim
:=
binary
.
BigEndian
.
Uint64
(
claimData
)
if
sOut
!=
sClaim
{
fmt
.
Printf
(
"claim %d is bad! Correct result is %d
\n
"
,
sOut
,
sClaim
)
os
.
Exit
(
1
)
}
else
{
fmt
.
Printf
(
"claim %d is good!
\n
"
,
sOut
)
os
.
Exit
(
0
)
}
}
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