-
Notifications
You must be signed in to change notification settings - Fork 2
support sstoragePisa.RemoveKVData #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: tm_w3q
Are you sure you want to change the base?
Changes from 4 commits
e892f70
747a081
f79694b
6a27daa
1fcdebe
7ee929f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import ( | |
"github.com/ethereum/go-ethereum/crypto/bls12381" | ||
"github.com/ethereum/go-ethereum/crypto/bn256" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/sstorage" | ||
|
||
//lint:ignore SA1019 Needed for precompile | ||
"golang.org/x/crypto/ripemd160" | ||
|
@@ -298,9 +299,10 @@ var ( | |
// modexpMultComplexity implements bigModexp multComplexity formula, as defined in EIP-198 | ||
// | ||
// def mult_complexity(x): | ||
// if x <= 64: return x ** 2 | ||
// elif x <= 1024: return x ** 2 // 4 + 96 * x - 3072 | ||
// else: return x ** 2 // 16 + 480 * x - 199680 | ||
// | ||
// if x <= 64: return x ** 2 | ||
// elif x <= 1024: return x ** 2 // 4 + 96 * x - 3072 | ||
// else: return x ** 2 // 16 + 480 * x - 199680 | ||
// | ||
// where is x is max(length_of_MODULUS, length_of_BASE) | ||
func modexpMultComplexity(x *big.Int) *big.Int { | ||
|
@@ -715,8 +717,9 @@ func (l *sstoragePisa) RequiredGas(input []byte) uint64 { | |
return params.SstoreResetGasEIP2200 | ||
} else if bytes.Equal(input[0:4], getRawMethodId) { | ||
return params.SloadGasEIP2200 | ||
} else if bytes.Equal(input[0:4], getRawMethodId) { | ||
return params.SstoreResetGasEIP2200 | ||
} else { | ||
// TODO: remove is not supported yet | ||
return 0 | ||
} | ||
} | ||
|
@@ -774,8 +777,35 @@ func (l *sstoragePisa) RunWith(env *PrecompiledContractCallEnv, input []byte) ([ | |
binary.BigEndian.PutUint64(pb[32-8:32], 32) | ||
binary.BigEndian.PutUint64(pb[64-8:64], uint64(len(b))) | ||
return append(pb, b...), nil | ||
} else if bytes.Equal(input[0:4], removeRawMethodId) { | ||
if evm.interpreter.readOnly { | ||
return nil, ErrWriteProtection | ||
} | ||
|
||
// The execution of remove should not affect the result when validator running without data node. | ||
|
||
// The remove operation consists of two steps. | ||
// First, replace the data corresponding to removeKvIdx selected by the operator with data of lastKvIdx | ||
// Second, set the data space of the original lastKvIdx to 0 | ||
lastKvIdx := new(big.Int).SetBytes(getData(input, 4, 32)) | ||
updateKvIdx := new(big.Int).SetBytes(getData(input, 4+32, 32)) | ||
|
||
if lastKvIdx.Cmp(updateKvIdx) == 0 { | ||
// Delete the data corresponding to lastKvIdx | ||
evm.StateDB.SstorageWrite(caller, lastKvIdx.Uint64(), make([]byte, sstorage.ShardInfos[0].KVSize)) | ||
} else { | ||
// Read the data corresponding to lastKvIdx | ||
replaceData, _, _ := evm.StateDB.SstorageRead(caller, lastKvIdx.Uint64(), int(sstorage.ShardInfos[0].KVSize), common.Hash{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the replaceData does not exist locally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TWP Section 5.3 has a discussion on this https://galileo.web3q.io/file.w3q/0x67d0481cc9c2e9dad2987e58a365aae977dcb8da/dynamic_data_sharding_0_1_6.pdf There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took an approach that only allows deletion of KV entries in the last shard There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen in this case: the shard is still synchronizing, so the |
||
|
||
// Delete the data corresponding to lastKvIdx | ||
evm.StateDB.SstorageWrite(caller, lastKvIdx.Uint64(), make([]byte, sstorage.ShardInfos[0].KVSize)) | ||
|
||
// Replace the data corresponding to kvIdx with the data corresponding to lastKvIdx | ||
evm.StateDB.SstorageWrite(caller, updateKvIdx.Uint64(), replaceData) | ||
} | ||
|
||
return nil, nil | ||
} | ||
// TODO: remove is not supported yet | ||
return nil, errors.New("unsupported method") | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.