Skip to content

Commit 27abeb3

Browse files
authored
Merge pull request #2413 from CortexFoundation/dev
add GetStateAndCommittedState
2 parents 4391a64 + e699f5b commit 27abeb3

36 files changed

Lines changed: 528 additions & 218 deletions

core/state/statedb.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) commo
414414
return common.Hash{}
415415
}
416416

417+
// GetStateAndCommittedState returns the current value and the original value.
418+
func (s *StateDB) GetStateAndCommittedState(addr common.Address, hash common.Hash) (common.Hash, common.Hash) {
419+
stateObject := s.getStateObject(addr)
420+
if stateObject != nil {
421+
return stateObject.getState(hash)
422+
}
423+
return common.Hash{}, common.Hash{}
424+
}
425+
417426
// Database retrieves the low level database supporting the lower level trie ops.
418427
func (s *StateDB) Database() Database {
419428
return s.db

core/vm/gas_table.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func gasReturnDataCopy(gt params.GasTable, cvm *CVM, contract *Contract, stack *
163163

164164
func gasSStore(gt params.GasTable, cvm *CVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
165165
var (
166-
y, x = stack.Back(1), stack.Back(0)
167-
current = cvm.StateDB.GetState(contract.Address(), x.Bytes32())
166+
y, x = stack.Back(1), stack.Back(0)
167+
current, original = cvm.StateDB.GetStateAndCommittedState(contract.Address(), x.Bytes32())
168168
)
169169
// The legacy gas metering only takes into consideration the current state
170170
// Legacy rules should be applied if we are in Petersburg (removal of EIP-1283)
@@ -203,7 +203,6 @@ func gasSStore(gt params.GasTable, cvm *CVM, contract *Contract, stack *Stack, m
203203
if current == value { // noop (1)
204204
return params.NetSstoreNoopGas, nil
205205
}
206-
original := cvm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
207206
if original == current {
208207
if original == (common.Hash{}) { // create slot (2.1.1)
209208
return params.NetSstoreInitGas, nil
@@ -250,15 +249,14 @@ func gasSStoreEIP2200(gt params.GasTable, cvm *CVM, contract *Contract, stack *S
250249
}
251250
// Gas sentry honoured, do the actual gas calculation based on the stored value
252251
var (
253-
y, x = stack.Back(1), stack.Back(0)
254-
current = cvm.StateDB.GetState(contract.Address(), x.Bytes32())
252+
y, x = stack.Back(1), stack.Back(0)
253+
current, original = cvm.StateDB.GetStateAndCommittedState(contract.Address(), x.Bytes32())
255254
)
256255
value := common.Hash(y.Bytes32())
257256

258257
if current == value { // noop (1)
259258
return params.SloadGasEIP2200, nil
260259
}
261-
original := cvm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
262260
if original == current {
263261
if original == (common.Hash{}) { // create slot (2.1.1)
264262
return params.SstoreSetGasEIP2200, nil

core/vm/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type StateDB interface {
5656
GetRefund() uint64
5757

5858
GetCommittedState(common.Address, common.Hash) common.Hash
59+
GetStateAndCommittedState(addr common.Address, hash common.Hash) (common.Hash, common.Hash)
5960

6061
GetState(common.Address, common.Hash) common.Hash
6162
SetState(common.Address, common.Hash, common.Hash)

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/aws/aws-sdk-go-v2 v1.36.5
1313
github.com/aws/aws-sdk-go-v2/config v1.29.17
1414
github.com/aws/aws-sdk-go-v2/credentials v1.17.70
15-
github.com/aws/aws-sdk-go-v2/service/route53 v1.52.2
15+
github.com/aws/aws-sdk-go-v2/service/route53 v1.53.0
1616
github.com/cespare/cp v1.1.1
1717
github.com/charmbracelet/bubbletea v1.3.5
1818
github.com/cloudflare/cloudflare-go v0.115.0
@@ -22,9 +22,9 @@ require (
2222
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
2323
github.com/deckarep/golang-set/v2 v2.8.0
2424
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
25-
github.com/dop251/goja v0.0.0-20250624190929-4d26883d182a
25+
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994
2626
github.com/ethereum/c-kzg-4844 v1.0.3
27-
github.com/ethereum/go-ethereum v1.16.0
27+
github.com/ethereum/go-ethereum v1.16.1
2828
github.com/ethereum/go-verkle v0.2.2
2929
github.com/ferranbt/fastssz v0.1.4
3030
github.com/fjl/gencodec v0.1.0
@@ -162,7 +162,7 @@ require (
162162
github.com/google/btree v1.1.3 // indirect
163163
github.com/google/flatbuffers v25.2.10+incompatible // indirect
164164
github.com/google/go-querystring v1.1.0 // indirect
165-
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // indirect
165+
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
166166
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
167167
github.com/huandu/xstrings v1.5.0 // indirect
168168
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect
@@ -199,21 +199,21 @@ require (
199199
github.com/pion/mdns/v2 v2.0.7 // indirect
200200
github.com/pion/randutil v0.1.0 // indirect
201201
github.com/pion/rtcp v1.2.15 // indirect
202-
github.com/pion/rtp v1.8.19 // indirect
202+
github.com/pion/rtp v1.8.20 // indirect
203203
github.com/pion/sctp v1.8.39 // indirect
204204
github.com/pion/sdp/v3 v3.0.14 // indirect
205205
github.com/pion/srtp/v3 v3.0.6 // indirect
206206
github.com/pion/stun/v3 v3.0.0 // indirect
207207
github.com/pion/transport/v2 v2.2.10 // indirect
208208
github.com/pion/transport/v3 v3.0.7 // indirect
209209
github.com/pion/turn/v4 v4.0.2 // indirect
210-
github.com/pion/webrtc/v4 v4.1.2 // indirect
210+
github.com/pion/webrtc/v4 v4.1.3 // indirect
211211
github.com/pkg/errors v0.9.1 // indirect
212212
github.com/pmezard/go-difflib v1.0.0 // indirect
213213
github.com/prometheus/client_golang v1.22.0 // indirect
214214
github.com/prometheus/client_model v0.6.2 // indirect
215215
github.com/prometheus/common v0.65.0 // indirect
216-
github.com/prometheus/procfs v0.16.1 // indirect
216+
github.com/prometheus/procfs v0.17.0 // indirect
217217
github.com/protolambda/ctxlock v0.1.0 // indirect
218218
github.com/rakyll/statik v0.1.7 // indirect
219219
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 h1:CXV68E2
280280
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4/go.mod h1:/xFi9KtvBXP97ppCz1TAEvU1Uf66qvid89rbem3wCzQ=
281281
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.17 h1:t0E6FzREdtCsiLIoLCWsYliNsRBgyGD/MCK571qk4MI=
282282
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.17/go.mod h1:ygpklyoaypuyDvOM5ujWGrYWpAK3h7ugnmKCU/76Ys4=
283-
github.com/aws/aws-sdk-go-v2/service/route53 v1.52.2 h1:dXHWVVPx2W2fq2PTugj8QXpJ0YTRAGx0KLPKhMBmcsY=
284-
github.com/aws/aws-sdk-go-v2/service/route53 v1.52.2/go.mod h1:wi1naoiPnCQG3cyjsivwPON1ZmQt/EJGxFqXzubBTAw=
283+
github.com/aws/aws-sdk-go-v2/service/route53 v1.53.0 h1:UglIEyurCqfzZkjNdYAuXUGFu/FNWMKP5eorzggvXe8=
284+
github.com/aws/aws-sdk-go-v2/service/route53 v1.53.0/go.mod h1:wi1naoiPnCQG3cyjsivwPON1ZmQt/EJGxFqXzubBTAw=
285285
github.com/aws/aws-sdk-go-v2/service/sso v1.25.5 h1:AIRJ3lfb2w/1/8wOOSqYb9fUKGwQbtysJ2H1MofRUPg=
286286
github.com/aws/aws-sdk-go-v2/service/sso v1.25.5/go.mod h1:b7SiVprpU+iGazDUqvRSLf5XmCdn+JtT1on7uNL6Ipc=
287287
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.3 h1:BpOxT3yhLwSJ77qIY3DoHAQjZsc4HEGfMCE4NGy3uFg=
@@ -424,8 +424,8 @@ github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn
424424
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
425425
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
426426
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
427-
github.com/dop251/goja v0.0.0-20250624190929-4d26883d182a h1:QIWJoaD2+zxUjN28l8zixmbuvtYqqcxj49Iwzw7mDpk=
428-
github.com/dop251/goja v0.0.0-20250624190929-4d26883d182a/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
427+
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994 h1:aQYWswi+hRL2zJqGacdCZx32XjKYV8ApXFGntw79XAM=
428+
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
429429
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
430430
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
431431
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
@@ -457,8 +457,8 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97
457457
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
458458
github.com/ethereum/c-kzg-4844 v1.0.3 h1:IEnbOHwjixW2cTvKRUlAAUOeleV7nNM/umJR+qy4WDs=
459459
github.com/ethereum/c-kzg-4844 v1.0.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
460-
github.com/ethereum/go-ethereum v1.16.0 h1:Acf8FlRmcSWEJm3lGjlnKTdNgFvF9/l28oQ8Q6HDj1o=
461-
github.com/ethereum/go-ethereum v1.16.0/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
460+
github.com/ethereum/go-ethereum v1.16.1 h1:7684NfKCb1+IChudzdKyZJ12l1Tq4ybPZOITiCDXqCk=
461+
github.com/ethereum/go-ethereum v1.16.1/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
462462
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
463463
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
464464
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@@ -616,8 +616,8 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI
616616
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
617617
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
618618
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
619-
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a h1://KbezygeMJZCSHH+HgUZiTeSoiuFspbMg1ge+eFj18=
620-
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a/go.mod h1:5hDyRhoBCxViHszMt12TnOpEI4VVi+U8Gm9iphldiMA=
619+
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 h1:xhMrHhTJ6zxu3gA4enFM9MLn9AY7613teCdFnlUVbSQ=
620+
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5/go.mod h1:5hDyRhoBCxViHszMt12TnOpEI4VVi+U8Gm9iphldiMA=
621621
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
622622
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
623623
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -984,8 +984,8 @@ github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo=
984984
github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0=
985985
github.com/pion/rtp v1.3.2/go.mod h1:q9wPnA96pu2urCcW/sK/RiDn597bhGoAQQ+y2fDwHuY=
986986
github.com/pion/rtp v1.4.0/go.mod h1:/l4cvcKd0D3u9JLs2xSVI95YkfXW87a3br3nqmVtSlE=
987-
github.com/pion/rtp v1.8.19 h1:jhdO/3XhL/aKm/wARFVmvTfq0lC/CvN1xwYKmduly3c=
988-
github.com/pion/rtp v1.8.19/go.mod h1:bAu2UFKScgzyFqvUKmbvzSdPr+NGbZtv6UB2hesqXBk=
987+
github.com/pion/rtp v1.8.20 h1:8zcyqohadZE8FCBeGdyEvHiclPIezcwRQH9zfapFyYI=
988+
github.com/pion/rtp v1.8.20/go.mod h1:bAu2UFKScgzyFqvUKmbvzSdPr+NGbZtv6UB2hesqXBk=
989989
github.com/pion/sctp v1.7.6/go.mod h1:ichkYQ5tlgCQwEwvgfdcAolqx1nHbYCxo4D7zK/K0X8=
990990
github.com/pion/sctp v1.8.39 h1:PJma40vRHa3UTO3C4MyeJDQ+KIobVYRZQZ0Nt7SjQnE=
991991
github.com/pion/sctp v1.8.39/go.mod h1:cNiLdchXra8fHQwmIoqw0MbLLMs+f7uQ+dGMG2gWebE=
@@ -1016,8 +1016,8 @@ github.com/pion/turn/v4 v4.0.2 h1:ZqgQ3+MjP32ug30xAbD6Mn+/K4Sxi3SdNOTFf+7mpps=
10161016
github.com/pion/turn/v4 v4.0.2/go.mod h1:pMMKP/ieNAG/fN5cZiN4SDuyKsXtNTr0ccN7IToA1zs=
10171017
github.com/pion/webrtc/v2 v2.2.7/go.mod h1:EfCuvKjzMgX4F/aSryRUC7L9o3u2N8WNUgnzd6wOO+8=
10181018
github.com/pion/webrtc/v2 v2.2.9/go.mod h1:TcArPDphZIBtZ+mh8J/qOREyY3ca7ihQrenulOIvfPQ=
1019-
github.com/pion/webrtc/v4 v4.1.2 h1:mpuUo/EJ1zMNKGE79fAdYNFZBX790KE7kQQpLMjjR54=
1020-
github.com/pion/webrtc/v4 v4.1.2/go.mod h1:xsCXiNAmMEjIdFxAYU0MbB3RwRieJsegSB2JZsGN+8U=
1019+
github.com/pion/webrtc/v4 v4.1.3 h1:YZ67Boj9X/hk190jJZ8+HFGQ6DqSZ/fYP3sLAZv7c3c=
1020+
github.com/pion/webrtc/v4 v4.1.3/go.mod h1:rsq+zQ82ryfR9vbb0L1umPJ6Ogq7zm8mcn9fcGnxomM=
10211021
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
10221022
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
10231023
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -1070,8 +1070,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
10701070
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
10711071
github.com/prometheus/procfs v0.0.10/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
10721072
github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
1073-
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
1074-
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
1073+
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
1074+
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
10751075
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
10761076
github.com/protolambda/ctxlock v0.1.0 h1:rCUY3+vRdcdZXqT07iXgyr744J2DU2LCBIXowYAjBCE=
10771077
github.com/protolambda/ctxlock v0.1.0/go.mod h1:vefhX6rIZH8rsg5ZpOJfEDYQOppZi19SfPiGOFrNnwM=

vendor/github.com/aws/aws-sdk-go-v2/service/route53/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go-v2/service/route53/endpoints.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go-v2/service/route53/go_module_metadata.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go-v2/service/route53/types/enums.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/dop251/goja/func.go

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)