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
9f736b2a
Unverified
Commit
9f736b2a
authored
Sep 29, 2022
by
protolambda
Committed by
GitHub
Sep 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-chain-ops: alias functions without pointers, and geth uint256 type (#3617)
parent
aeb8125b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
21 deletions
+22
-21
alias.go
op-chain-ops/crossdomain/alias.go
+15
-15
alias_test.go
op-chain-ops/crossdomain/alias_test.go
+7
-6
No files found.
op-chain-ops/crossdomain/alias.go
View file @
9f736b2a
...
@@ -7,27 +7,27 @@ import (
...
@@ -7,27 +7,27 @@ import (
)
)
var
(
var
(
uint160Max
,
_
=
uint256
.
FromHex
(
"0xffffffffffffffffffffffffffffffffffffffff
"
)
offsetAddr
=
common
.
HexToAddress
(
"0x1111000000000000000000000000000000001111
"
)
offset
=
new
(
uint256
.
Int
)
.
SetBytes
(
common
.
HexToAddress
(
"0x1111000000000000000000000000000000001111"
)
.
Bytes
()
)
offset
U256
=
new
(
uint256
.
Int
)
.
SetBytes20
(
offsetAddr
[
:
]
)
)
)
// ApplyL1ToL2Alias will apply the alias applied to L1 to L2 messages when it
// ApplyL1ToL2Alias will apply the alias applied to L1 to L2 messages when it
// originates from a contract address
// originates from a contract address
func
ApplyL1ToL2Alias
(
address
*
common
.
Address
)
*
common
.
Address
{
func
ApplyL1ToL2Alias
(
address
common
.
Address
)
common
.
Address
{
input
:=
new
(
uint256
.
Int
)
.
SetBytes
(
address
.
Bytes
())
var
input
uint256
.
Int
output
:=
new
(
uint256
.
Int
)
.
AddMod
(
input
,
offset
,
uint160Max
)
input
.
SetBytes20
(
address
[
:
])
if
output
.
Cmp
(
input
)
<
0
{
input
.
Add
(
&
input
,
offsetU256
)
output
=
output
.
Sub
(
output
,
new
(
uint256
.
Int
)
.
SetUint64
(
1
))
// clipping to bytes20 is the same as modulo 160 here, since the modulo is a multiple of 8 bits
}
return
input
.
Bytes20
()
addr
:=
common
.
BigToAddress
(
output
.
ToBig
())
return
&
addr
}
}
// UndoL1ToL2Alias will remove the alias applied to L1 to L2 messages when it
// UndoL1ToL2Alias will remove the alias applied to L1 to L2 messages when it
// originates from a contract address
// originates from a contract address
func
UndoL1ToL2Alias
(
address
*
common
.
Address
)
*
common
.
Address
{
func
UndoL1ToL2Alias
(
address
common
.
Address
)
common
.
Address
{
input
:=
new
(
uint256
.
Int
)
.
SetBytes
(
address
.
Bytes
())
var
input
uint256
.
Int
output
:=
new
(
uint256
.
Int
)
.
Sub
(
input
,
offset
)
input
.
SetBytes20
(
address
[
:
])
addr
:=
common
.
BigToAddress
(
output
.
ToBig
())
input
.
Sub
(
&
input
,
offsetU256
)
return
&
addr
// clipping to bytes20 is the same as modulo 160 here, since the modulo is a multiple of 8 bits.
// and underflows are not affected either.
return
input
.
Bytes20
()
}
}
op-chain-ops/crossdomain/alias_test.go
View file @
9f736b2a
...
@@ -4,17 +4,18 @@ import (
...
@@ -4,17 +4,18 @@ import (
"fmt"
"fmt"
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
)
)
func
FuzzAliasing
(
f
*
testing
.
F
)
{
func
FuzzAliasing
(
f
*
testing
.
F
)
{
f
.
Fuzz
(
func
(
t
*
testing
.
T
,
address
[]
byte
)
{
f
.
Fuzz
(
func
(
t
*
testing
.
T
,
address
[]
byte
)
{
addr
:=
common
.
BytesToAddress
(
address
)
addr
:=
common
.
BytesToAddress
(
address
)
aliased
:=
crossdomain
.
ApplyL1ToL2Alias
(
&
addr
)
aliased
:=
crossdomain
.
ApplyL1ToL2Alias
(
addr
)
unaliased
:=
crossdomain
.
UndoL1ToL2Alias
(
aliased
)
unaliased
:=
crossdomain
.
UndoL1ToL2Alias
(
aliased
)
require
.
Equal
(
t
,
addr
,
*
unaliased
)
require
.
Equal
(
t
,
addr
,
unaliased
)
})
})
}
}
...
@@ -51,10 +52,10 @@ func TestAliasing(t *testing.T) {
...
@@ -51,10 +52,10 @@ func TestAliasing(t *testing.T) {
for
i
,
test
:=
range
cases
{
for
i
,
test
:=
range
cases
{
t
.
Run
(
fmt
.
Sprintf
(
"test%d"
,
i
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
fmt
.
Sprintf
(
"test%d"
,
i
),
func
(
t
*
testing
.
T
)
{
aliased
:=
crossdomain
.
ApplyL1ToL2Alias
(
&
test
.
Input
)
aliased
:=
crossdomain
.
ApplyL1ToL2Alias
(
test
.
Input
)
require
.
Equal
(
t
,
test
.
Output
,
*
aliased
)
require
.
Equal
(
t
,
test
.
Output
,
aliased
)
unaliased
:=
crossdomain
.
UndoL1ToL2Alias
(
aliased
)
unaliased
:=
crossdomain
.
UndoL1ToL2Alias
(
aliased
)
require
.
Equal
(
t
,
test
.
Input
,
*
unaliased
)
require
.
Equal
(
t
,
test
.
Input
,
unaliased
)
})
})
}
}
}
}
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