Skip to content

Commit cb4fc77

Browse files
Merge pull request #302 from OffchainLabs/merge-v1.13.5
Merge v1.13.5
2 parents e11e488 + daccadb commit cb4fc77

File tree

155 files changed

+3527
-1404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3527
-1404
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
- stage: build
9797
if: type = push
9898
os: osx
99+
osx_image: xcode14.2
99100
go: 1.21.x
100101
env:
101102
- azure-osx
@@ -104,6 +105,8 @@ jobs:
104105
script:
105106
- go run build/ci.go install -dlgo
106107
- go run build/ci.go archive -type tar -signer OSX_SIGNING_KEY -signify SIGNIFY_KEY -upload gethstore/builds
108+
- go run build/ci.go install -dlgo -arch arm64
109+
- go run build/ci.go archive -arch arm64 -type tar -signer OSX_SIGNING_KEY -signify SIGNIFY_KEY -upload gethstore/builds
107110

108111
# These builders run the tests
109112
- stage: build

accounts/abi/bind/backend.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ var (
3636
// on a backend that doesn't implement PendingContractCaller.
3737
ErrNoPendingState = errors.New("backend does not support pending state")
3838

39+
// ErrNoBlockHashState is raised when attempting to perform a block hash action
40+
// on a backend that doesn't implement BlockHashContractCaller.
41+
ErrNoBlockHashState = errors.New("backend does not support block hash state")
42+
3943
// ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves
4044
// an empty contract behind.
4145
ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
@@ -64,6 +68,17 @@ type PendingContractCaller interface {
6468
PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
6569
}
6670

71+
// BlockHashContractCaller defines methods to perform contract calls on a specific block hash.
72+
// Call will try to discover this interface when access to a block by hash is requested.
73+
// If the backend does not support the block hash state, Call returns ErrNoBlockHashState.
74+
type BlockHashContractCaller interface {
75+
// CodeAtHash returns the code of the given account in the state at the specified block hash.
76+
CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error)
77+
78+
// CallContractAtHash executes an Ethereum contract all against the state at the specified block hash.
79+
CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
80+
}
81+
6782
// ContractTransactor defines the methods needed to allow operating with a contract
6883
// on a write only basis. Besides the transacting method, the remainder are helpers
6984
// used when the user does not provide some needed values, but rather leaves it up

accounts/abi/bind/backends/simulated.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var _ bind.ContractBackend = (*SimulatedBackend)(nil)
5050

5151
var (
5252
errBlockNumberUnsupported = errors.New("simulatedBackend cannot access blocks other than the latest block")
53+
errBlockHashUnsupported = errors.New("simulatedBackend cannot access blocks by hash other than the latest block")
5354
errBlockDoesNotExist = errors.New("block does not exist in blockchain")
5455
errTransactionDoesNotExist = errors.New("transaction does not exist")
5556
)
@@ -202,6 +203,24 @@ func (b *SimulatedBackend) CodeAt(ctx context.Context, contract common.Address,
202203
return stateDB.GetCode(contract), nil
203204
}
204205

206+
// CodeAtHash returns the code associated with a certain account in the blockchain.
207+
func (b *SimulatedBackend) CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error) {
208+
b.mu.Lock()
209+
defer b.mu.Unlock()
210+
211+
header, err := b.headerByHash(blockHash)
212+
if err != nil {
213+
return nil, err
214+
}
215+
216+
stateDB, err := b.blockchain.StateAt(header.Root)
217+
if err != nil {
218+
return nil, err
219+
}
220+
221+
return stateDB.GetCode(contract), nil
222+
}
223+
205224
// BalanceAt returns the wei balance of a certain account in the blockchain.
206225
func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract common.Address, blockNumber *big.Int) (*big.Int, error) {
207226
b.mu.Lock()
@@ -320,7 +339,11 @@ func (b *SimulatedBackend) blockByNumber(ctx context.Context, number *big.Int) (
320339
func (b *SimulatedBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
321340
b.mu.Lock()
322341
defer b.mu.Unlock()
342+
return b.headerByHash(hash)
343+
}
323344

345+
// headerByHash retrieves a header from the database by hash without Lock.
346+
func (b *SimulatedBackend) headerByHash(hash common.Hash) (*types.Header, error) {
324347
if hash == b.pendingBlock.Hash() {
325348
return b.pendingBlock.Header(), nil
326349
}
@@ -436,6 +459,22 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM
436459
if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number) != 0 {
437460
return nil, errBlockNumberUnsupported
438461
}
462+
return b.callContractAtHead(ctx, call)
463+
}
464+
465+
// CallContractAtHash executes a contract call on a specific block hash.
466+
func (b *SimulatedBackend) CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
467+
b.mu.Lock()
468+
defer b.mu.Unlock()
469+
470+
if blockHash != b.blockchain.CurrentBlock().Hash() {
471+
return nil, errBlockHashUnsupported
472+
}
473+
return b.callContractAtHead(ctx, call)
474+
}
475+
476+
// callContractAtHead executes a contract call against the latest block state.
477+
func (b *SimulatedBackend) callContractAtHead(ctx context.Context, call ethereum.CallMsg) ([]byte, error) {
439478
stateDB, err := b.blockchain.State()
440479
if err != nil {
441480
return nil, err
@@ -586,7 +625,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
586625
return 0, err
587626
}
588627
if failed {
589-
if result != nil && result.Err != vm.ErrOutOfGas {
628+
if result != nil && !errors.Is(result.Err, vm.ErrOutOfGas) {
590629
if len(result.Revert()) > 0 {
591630
return 0, newRevertError(result)
592631
}

accounts/abi/bind/backends/simulated_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,43 @@ func TestCodeAt(t *testing.T) {
996996
}
997997
}
998998

999+
func TestCodeAtHash(t *testing.T) {
1000+
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
1001+
sim := simTestBackend(testAddr)
1002+
defer sim.Close()
1003+
bgCtx := context.Background()
1004+
code, err := sim.CodeAtHash(bgCtx, testAddr, sim.Blockchain().CurrentHeader().Hash())
1005+
if err != nil {
1006+
t.Errorf("could not get code at test addr: %v", err)
1007+
}
1008+
if len(code) != 0 {
1009+
t.Errorf("got code for account that does not have contract code")
1010+
}
1011+
1012+
parsed, err := abi.JSON(strings.NewReader(abiJSON))
1013+
if err != nil {
1014+
t.Errorf("could not get code at test addr: %v", err)
1015+
}
1016+
auth, _ := bind.NewKeyedTransactorWithChainID(testKey, big.NewInt(1337))
1017+
contractAddr, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(abiBin), sim)
1018+
if err != nil {
1019+
t.Errorf("could not deploy contract: %v tx: %v contract: %v", err, tx, contract)
1020+
}
1021+
1022+
blockHash := sim.Commit()
1023+
code, err = sim.CodeAtHash(bgCtx, contractAddr, blockHash)
1024+
if err != nil {
1025+
t.Errorf("could not get code at test addr: %v", err)
1026+
}
1027+
if len(code) == 0 {
1028+
t.Errorf("did not get code for account that has contract code")
1029+
}
1030+
// ensure code received equals code deployed
1031+
if !bytes.Equal(code, common.FromHex(deployedCode)) {
1032+
t.Errorf("code received did not match expected deployed code:\n expected %v\n actual %v", common.FromHex(deployedCode), code)
1033+
}
1034+
}
1035+
9991036
// When receive("X") is called with sender 0x00... and value 1, it produces this tx receipt:
10001037
//
10011038
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
@@ -1038,7 +1075,7 @@ func TestPendingAndCallContract(t *testing.T) {
10381075
t.Errorf("response from calling contract was expected to be 'hello world' instead received %v", string(res))
10391076
}
10401077

1041-
sim.Commit()
1078+
blockHash := sim.Commit()
10421079

10431080
// make sure you can call the contract
10441081
res, err = sim.CallContract(bgCtx, ethereum.CallMsg{
@@ -1056,6 +1093,23 @@ func TestPendingAndCallContract(t *testing.T) {
10561093
if !bytes.Equal(res, expectedReturn) || !strings.Contains(string(res), "hello world") {
10571094
t.Errorf("response from calling contract was expected to be 'hello world' instead received %v", string(res))
10581095
}
1096+
1097+
// make sure you can call the contract by hash
1098+
res, err = sim.CallContractAtHash(bgCtx, ethereum.CallMsg{
1099+
From: testAddr,
1100+
To: &addr,
1101+
Data: input,
1102+
}, blockHash)
1103+
if err != nil {
1104+
t.Errorf("could not call receive method on contract: %v", err)
1105+
}
1106+
if len(res) == 0 {
1107+
t.Errorf("result of contract call was empty: %v", res)
1108+
}
1109+
1110+
if !bytes.Equal(res, expectedReturn) || !strings.Contains(string(res), "hello world") {
1111+
t.Errorf("response from calling contract was expected to be 'hello world' instead received %v", string(res))
1112+
}
10591113
}
10601114

10611115
// This test is based on the following contract:

accounts/abi/bind/base.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type CallOpts struct {
4949
Pending bool // Whether to operate on the pending state or the last known one
5050
From common.Address // Optional the sender address, otherwise the first account is used
5151
BlockNumber *big.Int // Optional the block number on which the call should be performed
52+
BlockHash common.Hash // Optional the block hash on which the call should be performed
5253
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
5354
}
5455

@@ -233,6 +234,23 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
233234
return ErrNoCode
234235
}
235236
}
237+
} else if opts.BlockHash != (common.Hash{}) {
238+
bh, ok := c.caller.(BlockHashContractCaller)
239+
if !ok {
240+
return ErrNoBlockHashState
241+
}
242+
output, err = bh.CallContractAtHash(ctx, msg, opts.BlockHash)
243+
if err != nil {
244+
return err
245+
}
246+
if len(output) == 0 {
247+
// Make sure we have a contract to operate on, and bail out otherwise.
248+
if code, err = bh.CodeAtHash(ctx, c.address, opts.BlockHash); err != nil {
249+
return err
250+
} else if len(code) == 0 {
251+
return ErrNoCode
252+
}
253+
}
236254
} else {
237255
output, err = c.caller.CallContract(ctx, msg, opts.BlockNumber)
238256
if err != nil {

accounts/abi/bind/base_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ func (mc *mockPendingCaller) PendingCallContract(ctx context.Context, call ether
114114
return mc.pendingCallContractBytes, mc.pendingCallContractErr
115115
}
116116

117+
type mockBlockHashCaller struct {
118+
*mockCaller
119+
codeAtHashBytes []byte
120+
codeAtHashErr error
121+
codeAtHashCalled bool
122+
callContractAtHashCalled bool
123+
callContractAtHashBytes []byte
124+
callContractAtHashErr error
125+
}
126+
127+
func (mc *mockBlockHashCaller) CodeAtHash(ctx context.Context, contract common.Address, hash common.Hash) ([]byte, error) {
128+
mc.codeAtHashCalled = true
129+
return mc.codeAtHashBytes, mc.codeAtHashErr
130+
}
131+
132+
func (mc *mockBlockHashCaller) CallContractAtHash(ctx context.Context, call ethereum.CallMsg, hash common.Hash) ([]byte, error) {
133+
mc.callContractAtHashCalled = true
134+
return mc.callContractAtHashBytes, mc.callContractAtHashErr
135+
}
136+
117137
func TestPassingBlockNumber(t *testing.T) {
118138
mc := &mockPendingCaller{
119139
mockCaller: &mockCaller{
@@ -400,6 +420,15 @@ func TestCall(t *testing.T) {
400420
Pending: true,
401421
},
402422
method: method,
423+
}, {
424+
name: "ok hash",
425+
mc: &mockBlockHashCaller{
426+
codeAtHashBytes: []byte{0},
427+
},
428+
opts: &bind.CallOpts{
429+
BlockHash: common.Hash{0xaa},
430+
},
431+
method: method,
403432
}, {
404433
name: "pack error, no method",
405434
mc: new(mockCaller),
@@ -413,6 +442,14 @@ func TestCall(t *testing.T) {
413442
},
414443
method: method,
415444
wantErrExact: bind.ErrNoPendingState,
445+
}, {
446+
name: "interface error, blockHash but not a BlockHashContractCaller",
447+
mc: new(mockCaller),
448+
opts: &bind.CallOpts{
449+
BlockHash: common.Hash{0xaa},
450+
},
451+
method: method,
452+
wantErrExact: bind.ErrNoBlockHashState,
416453
}, {
417454
name: "pending call canceled",
418455
mc: &mockPendingCaller{
@@ -460,6 +497,34 @@ func TestCall(t *testing.T) {
460497
mc: new(mockCaller),
461498
method: method,
462499
wantErrExact: bind.ErrNoCode,
500+
}, {
501+
name: "call contract at hash error",
502+
mc: &mockBlockHashCaller{
503+
callContractAtHashErr: context.DeadlineExceeded,
504+
},
505+
opts: &bind.CallOpts{
506+
BlockHash: common.Hash{0xaa},
507+
},
508+
method: method,
509+
wantErrExact: context.DeadlineExceeded,
510+
}, {
511+
name: "code at error",
512+
mc: &mockBlockHashCaller{
513+
codeAtHashErr: errors.New(""),
514+
},
515+
opts: &bind.CallOpts{
516+
BlockHash: common.Hash{0xaa},
517+
},
518+
method: method,
519+
wantErr: true,
520+
}, {
521+
name: "no code at hash",
522+
mc: new(mockBlockHashCaller),
523+
opts: &bind.CallOpts{
524+
BlockHash: common.Hash{0xaa},
525+
},
526+
method: method,
527+
wantErrExact: bind.ErrNoCode,
463528
}, {
464529
name: "unpack error missing arg",
465530
mc: &mockCaller{

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ for:
5454
- go run build/ci.go archive -arch %GETH_ARCH% -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
5555
- go run build/ci.go nsis -arch %GETH_ARCH% -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
5656
test_script:
57-
- go run build/ci.go test -dlgo -arch %GETH_ARCH% -cc %GETH_CC%
57+
- go run build/ci.go test -dlgo -arch %GETH_ARCH% -cc %GETH_CC% -short

build/checksums.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
# https://github.com/ethereum/execution-spec-tests/releases/download/v1.0.6/
66
485af7b66cf41eb3a8c1bd46632913b8eb95995df867cf665617bbc9b4beedd1 fixtures_develop.tar.gz
77

8-
# version:golang 1.21.3
8+
# version:golang 1.21.4
99
# https://go.dev/dl/
10-
186f2b6f8c8b704e696821b09ab2041a5c1ee13dcbc3156a13adcf75931ee488 go1.21.3.src.tar.gz
11-
27014fc69e301d7588a169ca239b3cc609f0aa1abf38528bf0d20d3b259211eb go1.21.3.darwin-amd64.tar.gz
12-
65302a7a9f7a4834932b3a7a14cb8be51beddda757b567a2f9e0cbd0d7b5a6ab go1.21.3.darwin-arm64.tar.gz
13-
8e0cd2f66cf1bde9d07b4aee01e3d7c3cfdd14e20650488e1683da4b8492594a go1.21.3.freebsd-386.tar.gz
14-
6e74f65f586e93d1f3947894766f69e9b2ebda488592a09df61f36f06bfe58a8 go1.21.3.freebsd-amd64.tar.gz
15-
fb209fd070db500a84291c5a95251cceeb1723e8f6142de9baca5af70a927c0e go1.21.3.linux-386.tar.gz
16-
1241381b2843fae5a9707eec1f8fb2ef94d827990582c7c7c32f5bdfbfd420c8 go1.21.3.linux-amd64.tar.gz
17-
fc90fa48ae97ba6368eecb914343590bbb61b388089510d0c56c2dde52987ef3 go1.21.3.linux-arm64.tar.gz
18-
a1ddcaaf0821a12a800884c14cb4268ce1c1f5a0301e9060646f1e15e611c6c7 go1.21.3.linux-armv6l.tar.gz
19-
3b0e10a3704f164a6e85e0377728ec5fd21524fabe4c925610e34076586d5826 go1.21.3.linux-ppc64le.tar.gz
20-
4c78e2e6f4c684a3d5a9bdc97202729053f44eb7be188206f0627ef3e18716b6 go1.21.3.linux-s390x.tar.gz
21-
e36737f4f2fadb4d2f919ec4ce517133a56e06064cca6e82fc883bb000c4d56c go1.21.3.windows-386.zip
22-
27c8daf157493f288d42a6f38debc6a2cb391f6543139eba9152fceca0be2a10 go1.21.3.windows-amd64.zip
23-
bfb7a5c56f9ded07d8ae0e0b3702ac07b65e68fa8f33da24ed6df4ce01fe2c5c go1.21.3.windows-arm64.zip
10+
47b26a83d2b65a3c1c1bcace273b69bee49a7a7b5168a7604ded3d26a37bd787 go1.21.4.src.tar.gz
11+
cd3bdcc802b759b70e8418bc7afbc4a65ca73a3fe576060af9fc8a2a5e71c3b8 go1.21.4.darwin-amd64.tar.gz
12+
8b7caf2ac60bdff457dba7d4ff2a01def889592b834453431ae3caecf884f6a5 go1.21.4.darwin-arm64.tar.gz
13+
f1e685d086eb36f4be5b8b953b52baf7752bc6235400d84bb7d87e500b65f03e go1.21.4.freebsd-386.tar.gz
14+
59f9b32187efb98d344a3818a631d3815ebb5c7bbefc367bab6515caaca544e9 go1.21.4.freebsd-amd64.tar.gz
15+
64d3e5d295806e137c9e39d1e1f10b00a30fcd5c2f230d72b3298f579bb3c89a go1.21.4.linux-386.tar.gz
16+
73cac0215254d0c7d1241fa40837851f3b9a8a742d0b54714cbdfb3feaf8f0af go1.21.4.linux-amd64.tar.gz
17+
ce1983a7289856c3a918e1fd26d41e072cc39f928adfb11ba1896440849b95da go1.21.4.linux-arm64.tar.gz
18+
6c62e89113750cc77c498194d13a03fadfda22bd2c7d44e8a826fd354db60252 go1.21.4.linux-armv6l.tar.gz
19+
2c63b36d2adcfb22013102a2ee730f058ec2f93b9f27479793c80b2e3641783f go1.21.4.linux-ppc64le.tar.gz
20+
7a75ba4afc7a96058ca65903d994cd862381825d7dca12b2183f087c757c26c0 go1.21.4.linux-s390x.tar.gz
21+
870a0e462b94671dc2d6cac707e9e19f7524fdc3c90711e6cd4450c3713a8ce0 go1.21.4.windows-386.zip
22+
79e5428e068c912d9cfa6cd115c13549856ec689c1332eac17f5d6122e19d595 go1.21.4.windows-amd64.zip
23+
58bc7c6f4d4c72da2df4d2650c8222fe03c9978070eb3c66be8bbaa2a4757ac1 go1.21.4.windows-arm64.zip
2424

2525
# version:golangci 1.51.1
2626
# https://github.com/golangci/golangci-lint/releases/

build/ci.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ func doTest(cmdline []string) {
285285
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
286286
verbose = flag.Bool("v", false, "Whether to log verbosely")
287287
race = flag.Bool("race", false, "Execute the race detector")
288+
short = flag.Bool("short", false, "Pass the 'short'-flag to go test")
288289
cachedir = flag.String("cachedir", "./build/cache", "directory for caching downloads")
289290
)
290291
flag.CommandLine.Parse(cmdline)
@@ -306,6 +307,9 @@ func doTest(cmdline []string) {
306307
// Enable CKZG backend in CI.
307308
gotest.Args = append(gotest.Args, "-tags=ckzg")
308309

310+
// Enable integration-tests
311+
gotest.Args = append(gotest.Args, "-tags=integrationtests")
312+
309313
// Test a single package at a time. CI builders are slow
310314
// and some tests run into timeouts under load.
311315
gotest.Args = append(gotest.Args, "-p", "1")
@@ -318,6 +322,9 @@ func doTest(cmdline []string) {
318322
if *race {
319323
gotest.Args = append(gotest.Args, "-race")
320324
}
325+
if *short {
326+
gotest.Args = append(gotest.Args, "-short")
327+
}
321328

322329
packages := []string{"./..."}
323330
if len(flag.CommandLine.Args()) > 0 {

0 commit comments

Comments
 (0)