Skip to content

Commit

Permalink
Fix ciphertext index calculation in SSTORE
Browse files Browse the repository at this point in the history
  • Loading branch information
dartdart26 committed Dec 9, 2022
1 parent 0fff21c commit 3ba6ebd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func verifyIfCiphertextHandle(val common.Hash, interpreter *EVMInterpreter, cont
metadataInt := newInt(interpreter.evm.StateDB.GetState(protectedStorage, val).Bytes())
if !metadataInt.IsZero() {
metadata := newCiphertextMetadata(metadataInt.Bytes32())
ctBytes := make([]byte, metadata.length)
ctBytes := make([]byte, 0)
left := metadata.length
protectedSlotIdx := newInt(val.Bytes())
protectedSlotIdx.AddUint64(protectedSlotIdx, 1)
Expand Down Expand Up @@ -603,18 +603,20 @@ func persistIfVerifiedCiphertext(val common.Hash, protectedStorage common.Addres
metadata.length = uint64(len(verifiedCiphertext.ciphertext))
ciphertextSlot := newInt(val.Bytes())
ciphertextSlot.AddUint64(ciphertextSlot, 1)
ct := make([]byte, 32)
ctPart32 := make([]byte, 32)
partIdx := 0
for i, b := range verifiedCiphertext.ciphertext {
if i%32 == 0 && i != 0 {
interpreter.evm.StateDB.SetState(protectedStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ct))
interpreter.evm.StateDB.SetState(protectedStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
ciphertextSlot.AddUint64(ciphertextSlot, 1)
ct = make([]byte, 32)
} else {
ct = append(ct, b)
ctPart32 = make([]byte, 32)
partIdx = 0
}
ctPart32[partIdx] = b
partIdx++
}
if len(ct) != 0 {
interpreter.evm.StateDB.SetState(protectedStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ct))
if len(ctPart32) != 0 {
interpreter.evm.StateDB.SetState(protectedStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
}
} else {
// If metadata exists, bump the refcount by 1.
Expand Down

0 comments on commit 3ba6ebd

Please sign in to comment.