Skip to content

Commit

Permalink
Skip signature compression unless storage is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Feb 9, 2024
1 parent 272f87b commit bcbe6b9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions compressor/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,16 @@ func (c *Encoder) WriteBytesOptimized(dest *CBuffer, bytes []byte, saveWord bool
// we generate a snapshot of the dest buffer and try to encode it as a signature, if it fails
// or if the result is bigger than the original bytes, we restore the snapshot and continue.
// Notice: pass `false` to `mayUseBytes` or else this will be an infinite loop
snapshot := dest.Snapshot()
t, err := c.WriteSignature(dest, bytes, false)
if err == nil && dest.Len() < len(bytes)+3+len(snapshot.Commited) {
return t, nil
// DO NOT use this method if storage is set to false
// it is never worth it if we need to use calldata
if dest.Refs.useContractStorage {
snapshot := dest.Snapshot()
t, err := c.WriteSignature(dest, bytes, false)
if err == nil && dest.Len() < len(bytes)+3+len(snapshot.Commited) {
return t, nil
}
dest.Restore(snapshot)
}
dest.Restore(snapshot)

// If the bytes are a multiple of 32 + 4 bytes (max 6 * 32 + 4) then it
// can be encoded as an ABI call with 0 to 6 parameters
Expand Down Expand Up @@ -637,7 +641,7 @@ func (c *Encoder) WriteSignature(dest *CBuffer, signature []byte, mayUseBytes bo
}()

// First byte determines the signature type
if mayUseBytes && (len(signature) == 0) {
if mayUseBytes && (len(signature) == 0 || !dest.Refs.useContractStorage) {
// Guestmodule signatures are empty
return c.WriteBytesOptimized(dest, signature, false)
}
Expand Down

0 comments on commit bcbe6b9

Please sign in to comment.