compressor

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	METHOD_EXECUTE_1 uint = iota
	METHOD_EXECUTE_N
	METHOD_READ_ADDRESS
	METHOD_READ_BYTES32
	METHOD_READ_SIZES
	METHOD_READ_STORAGE_SLOTS
	METHOD_DECOMPRESS_1
	METHOD_DECOMPRESS_N
)
View Source
const (
	FLAG_READ_POWER_OF_10_MISC uint = iota
	FLAG_READ_BYTES32_1_BYTES
	FLAG_READ_BYTES32_2_BYTES
	FLAG_READ_BYTES32_3_BYTES
	FLAG_READ_BYTES32_4_BYTES
	FLAG_READ_BYTES32_5_BYTES
	FLAG_READ_BYTES32_6_BYTES
	FLAG_READ_BYTES32_7_BYTES
	FLAG_READ_BYTES32_8_BYTES
	FLAG_READ_BYTES32_9_BYTES
	FLAG_READ_BYTES32_10_BYTES
	FLAG_READ_BYTES32_11_BYTES
	FLAG_READ_BYTES32_12_BYTES
	FLAG_READ_BYTES32_13_BYTES
	FLAG_READ_BYTES32_14_BYTES
	FLAG_READ_BYTES32_15_BYTES
	FLAG_READ_BYTES32_16_BYTES
	FLAG_READ_BYTES32_17_BYTES
	FLAG_READ_BYTES32_18_BYTES
	FLAG_READ_BYTES32_19_BYTES
	FLAG_READ_BYTES32_20_BYTES
	FLAG_READ_BYTES32_21_BYTES
	FLAG_READ_BYTES32_22_BYTES
	FLAG_READ_BYTES32_23_BYTES
	FLAG_READ_BYTES32_24_BYTES
	FLAG_READ_BYTES32_25_BYTES
	FLAG_READ_BYTES32_26_BYTES
	FLAG_READ_BYTES32_27_BYTES
	FLAG_READ_BYTES32_28_BYTES
	FLAG_READ_BYTES32_29_BYTES
	FLAG_READ_BYTES32_30_BYTES
	FLAG_READ_BYTES32_31_BYTES
	FLAG_READ_BYTES32_32_BYTES
	FLAG_SAVE_ADDRESS
	FLAG_SAVE_BYTES32
	FLAG_READ_ADDRESS_2
	FLAG_READ_ADDRESS_3
	FLAG_READ_ADDRESS_4
	FLAG_READ_EXECUTE
	FLAG_READ_BYTES32_2
	FLAG_READ_BYTES32_3
	FLAG_READ_BYTES32_4
	FLAG_READ_POW_10_MANTISSA
	FLAG_READ_N_BYTES
	FLAG_READ_POWER_OF_2
	FLAG_ABI_0_PARAM
	FLAG_ABI_1_PARAM
	FLAG_ABI_2_PARAMS
	FLAG_ABI_3_PARAMS
	FLAG_ABI_4_PARAMS
	FLAG_ABI_5_PARAMS
	FLAG_ABI_6_PARAMS
	FLAG_NESTED_N_FLAGS_8
	FLAG_NESTED_N_FLAGS_16
	FLAG_SIGNATURE_W0
	FLAG_SIGNATURE_W1
	FLAG_SIGNATURE_W2
	FLAG_SIGNATURE_W3
	FLAG_SIGNATURE_W4
	FLAG_ADDRESS_W0
	FLAG_ADDRESS_W1
	FLAG_ADDRESS_W2
	FLAG_ADDRESS_W3
	FLAG_ADDRESS_W4
	FLAG_NODE
	FLAG_BRANCH
	FLAG_SUBDIGEST
	FLAG_NESTED
	FLAG_DYNAMIC_SIGNATURE
	FLAG_S_SIG_NO_CHAIN
	FLAG_S_SIG
	FLAG_S_L_SIG_NO_CHAIN
	FLAG_S_L_SIG
	FLAG_READ_CHAINED
	FLAG_READ_CHAINED_L
	FLAG_READ_DYNAMIC_ABI
	FLAG_NO_OP
	FLAG_MIRROR_FLAG
	FLAG_COPY_CALLDATA
	FLAG_READ_STORE_FLAG
)
View Source
const BYTES4_TABLE = "" /* 2048-byte string literal not displayed */
View Source
const LITERAL_ZERO = FLAG_READ_STORE_FLAG + 1
View Source
const MAX_LITERAL = 0xff - LITERAL_ZERO

Variables

This section is empty.

Functions

func AddressIndex

func AddressIndex(i uint) []byte

func Bytes32Index

func Bytes32Index(i uint) []byte

func DecompressTransaction

func DecompressTransaction(ctx context.Context, provider *ethrpc.Provider, contract common.Address, compressed []byte) (common.Address, []byte, error)

func FindPastData

func FindPastData(pastData *CBuffer, data []byte) int

func GenBatch

func GenBatch(from uint, to uint, max uint, itemplate func(uint) []byte) []byte

func GetTotals

func GetTotals(ctx context.Context, provider *ethrpc.Provider, contract common.Address, skipBlocks uint) (uint, uint, error)

func LoadAddresses

func LoadAddresses(ctx context.Context, provider *ethrpc.Provider, contract common.Address, batchSize uint, skip uint, skipBlocks uint) (uint, map[string]uint, error)

func LoadBytes32

func LoadBytes32(ctx context.Context, provider *ethrpc.Provider, contract common.Address, batchSize uint, skip uint, skipBlocks uint) (uint, map[string]uint, error)

func LoadBytes4

func LoadBytes4() map[string]uint

func LoadIndexes

func LoadIndexes(ci *Compressor) error

func LoadState

func LoadState(ctx context.Context, provider *ethrpc.Provider, contract common.Address, batchSize uint, skipa uint, skipb uint, skipBlocks uint) (uint, map[string]uint, uint, map[string]uint, error)

func LoadStorage

func LoadStorage(ctx context.Context, provider *ethrpc.Provider, contract common.Address, batchSize uint, skip uint, total uint, itemplate func(uint) []byte) (uint, map[string]uint, error)

func NormalizeSignature

func NormalizeSignature(signature []byte) ([]byte, error)

func NormalizeTransactionSignature

func NormalizeTransactionSignature(
	transaction *sequence.Transaction,
) error

func ParseBatchResult

func ParseBatchResult(to map[string]uint, res []byte, offset uint) error

Types

type CBuffer

type CBuffer struct {
	SignatureLevel uint

	Commited []byte
	Pending  []byte

	Refs *References
}

func NewCBuffer

func NewCBuffer(useStorage bool) *CBuffer

func (*CBuffer) Data

func (cb *CBuffer) Data() []byte

func (*CBuffer) End

func (cb *CBuffer) End(uncompressed []byte, t EncodeType)

func (*CBuffer) Len

func (cb *CBuffer) Len() int

func (*CBuffer) Restore

func (cb *CBuffer) Restore(snap *Snapshot)

func (*CBuffer) Snapshot

func (cb *CBuffer) Snapshot() *Snapshot

func (*CBuffer) WriteByte

func (cb *CBuffer) WriteByte(b byte)

func (*CBuffer) WriteBytes

func (cb *CBuffer) WriteBytes(b []byte)

func (*CBuffer) WriteInt

func (cb *CBuffer) WriteInt(i uint)

type Compressor

type Compressor struct {
	Encoder   *Encoder
	CostModel *CostModel
	Contract  common.Address

	UseStorage bool

	UpdateInterval uint
	TrailBlocks    uint
	BatchSize      uint

	AddressesHeight uint
	Bytes32Height   uint

	LastIndexUpdate uint
	Provider        *ethrpc.Provider
	// contains filtered or unexported fields
}

func NewCompressor

func NewCompressor(
	ctx context.Context,
	provider *ethrpc.Provider,
	contract common.Address,
	costModel *CostModel,
	userStorage bool,
	updateInterval uint,
	trailBlocks uint,
	batchSize uint,
) (*Compressor, error)

func (*Compressor) IsSaneCompression

func (cm *Compressor) IsSaneCompression(
	input []byte,
	entrypoint common.Address,
	transaction *sequence.Transaction,
	decompressedEntrypoint common.Address,
	decompressed []byte,
) error

func (*Compressor) SetOnLoadedIndexes

func (cm *Compressor) SetOnLoadedIndexes(f func(uint, uint))

func (*Compressor) StartIndexUpdater

func (cm *Compressor) StartIndexUpdater()

func (*Compressor) TryCompress

func (cm *Compressor) TryCompress(
	input []byte,
	entrypoint common.Address,
	transaction *sequence.Transaction,
) (common.Address, []byte, EncodeType, error)

We return two errors, the first one is the inner compression error, we returns it for traceability but the real error is the second one, which should only appear on a non-recoverable situation

type CostModel

type CostModel struct {
	ZeroByteCost int
	OneByteCost  int

	FixedCost          int
	OverHeadPersentage int // 0 - 1000
}

func GetCostModel

func GetCostModel(network string) *CostModel

func NewCostModel

func NewCostModel(zeroByteCost, oneByteCost, fixedCost, overHeadPersentage int) *CostModel

func (*CostModel) Cost

func (cm *CostModel) Cost(data []byte) int

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(calldata []byte) *Decoder

func (*Decoder) Buffer

func (d *Decoder) Buffer() []byte

func (*Decoder) FlagNode

func (d *Decoder) FlagNode() error

func (*Decoder) FlagSubdigest

func (d *Decoder) FlagSubdigest() error

func (*Decoder) LogFlag

func (d *Decoder) LogFlag(flag string)

func (*Decoder) ReadAbi4Bytes

func (d *Decoder) ReadAbi4Bytes() error

func (*Decoder) ReadAbiDynamic

func (d *Decoder) ReadAbiDynamic() error

func (*Decoder) ReadAbiStatic

func (d *Decoder) ReadAbiStatic(flag uint) error

func (*Decoder) ReadAddress

func (d *Decoder) ReadAddress(flag uint) error

func (*Decoder) ReadAddressStorage

func (d *Decoder) ReadAddressStorage(flag uint) error

func (*Decoder) ReadAndLoad32Bytes

func (d *Decoder) ReadAndLoad32Bytes() ([]byte, error)

func (*Decoder) ReadBranch

func (d *Decoder) ReadBranch() error

func (*Decoder) ReadBytes32

func (d *Decoder) ReadBytes32(flag uint) error

func (*Decoder) ReadBytes32Storage

func (d *Decoder) ReadBytes32Storage(flag uint) error

func (*Decoder) ReadCopyCalldata

func (d *Decoder) ReadCopyCalldata() error

func (*Decoder) ReadDynamicSignature

func (d *Decoder) ReadDynamicSignature() error

func (*Decoder) ReadExecute

func (d *Decoder) ReadExecute() error

func (*Decoder) ReadFlag

func (d *Decoder) ReadFlag() error

func (*Decoder) ReadLiteral

func (d *Decoder) ReadLiteral(flag uint) error

func (*Decoder) ReadMirrorFlag

func (d *Decoder) ReadMirrorFlag() error

func (*Decoder) ReadNBytes

func (d *Decoder) ReadNBytes(flag uint) error

func (*Decoder) ReadNFlags

func (d *Decoder) ReadNFlags(n uint) error

func (*Decoder) ReadNested

func (d *Decoder) ReadNested() error

func (*Decoder) ReadNestedFlags

func (d *Decoder) ReadNestedFlags(flag uint) error

func (*Decoder) ReadNonce

func (d *Decoder) ReadNonce() error

func (*Decoder) ReadPow10Misc

func (d *Decoder) ReadPow10Misc() error

func (*Decoder) ReadPow2

func (d *Decoder) ReadPow2() error

func (*Decoder) ReadSaveAddress

func (d *Decoder) ReadSaveAddress() error

func (*Decoder) ReadSaveBytes32

func (d *Decoder) ReadSaveBytes32() error

func (*Decoder) ReadSequenceSignatureV2

func (d *Decoder) ReadSequenceSignatureV2(flag uint) error

func (*Decoder) ReadSignature

func (d *Decoder) ReadSignature(flag uint) error

func (*Decoder) ReadTransaction

func (d *Decoder) ReadTransaction() error

func (*Decoder) ReadTransactions

func (d *Decoder) ReadTransactions() error

type EncodeType

type EncodeType int
const (
	Stateless EncodeType = iota
	Mirror
	ReadStorage
	WriteStorage
)

func HighestPriority

func HighestPriority(a EncodeType, b EncodeType) EncodeType

type Encoder

type Encoder struct {
	AddressIndexes map[string]uint
	Bytes32Indexes map[string]uint
	Bytes4Indexes  map[string]uint
}

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Encode4Bytes

func (c *Encoder) Encode4Bytes(bytes []byte) []byte

func (*Encoder) EncodeWordBytes32

func (c *Encoder) EncodeWordBytes32(word []byte) ([]byte, EncodeType, error)

Encodes a 32 word, without any optimizations

func (*Encoder) EncodeWordOptimized

func (c *Encoder) EncodeWordOptimized(pastData *CBuffer, word []byte, saveWord bool) ([]byte, EncodeType, error)

Encodes a 32 bytes word, trying to optimize it as much as possible

func (*Encoder) WriteBranchSignaturePart

func (c *Encoder) WriteBranchSignaturePart(dest *CBuffer, branch []byte) (EncodeType, error)

func (*Encoder) WriteBytesOptimized

func (c *Encoder) WriteBytesOptimized(dest *CBuffer, bytes []byte, saveWord bool) (EncodeType, error)

Encode N bytes, as optimized as possible

func (*Encoder) WriteChainedSignature

func (c *Encoder) WriteChainedSignature(dest *CBuffer, signature []byte) (EncodeType, error)

func (*Encoder) WriteDynamicSignaturePart

func (c *Encoder) WriteDynamicSignaturePart(dest *CBuffer, address []byte, weight uint, signature []byte) (EncodeType, error)

func (*Encoder) WriteExecute

func (c *Encoder) WriteExecute(dest *CBuffer, wallet []byte, transaction *sequence.Transaction) (EncodeType, error)

func (*Encoder) WriteNBytesRaw

func (c *Encoder) WriteNBytesRaw(dest *CBuffer, bytes []byte) (EncodeType, error)

Encodes N bytes, without any optimizations

func (*Encoder) WriteNestedSignaturePart

func (c *Encoder) WriteNestedSignaturePart(dest *CBuffer, weight uint, threshold uint, branch []byte) (EncodeType, error)

func (*Encoder) WriteNonce

func (c *Encoder) WriteNonce(dest *CBuffer, nonce *big.Int, randomNonce bool) (EncodeType, error)

func (*Encoder) WriteSignature

func (c *Encoder) WriteSignature(dest *CBuffer, signature []byte, mayUseBytes bool) (EncodeType, error)

func (*Encoder) WriteSignatureBody

func (c *Encoder) WriteSignatureBody(dest *CBuffer, noChain bool, body []byte) (EncodeType, error)

func (*Encoder) WriteSignatureTree

func (c *Encoder) WriteSignatureTree(dest *CBuffer, tree []byte) (EncodeType, error)

func (*Encoder) WriteTransaction

func (c *Encoder) WriteTransaction(dest *CBuffer, transaction *sequence.Transaction) (EncodeType, error)

func (*Encoder) WriteTransactions

func (c *Encoder) WriteTransactions(dest *CBuffer, transactions sequence.Transactions) (EncodeType, error)

func (*Encoder) WriteWord

func (c *Encoder) WriteWord(word []byte, dest *CBuffer, useStorage bool) (EncodeType, error)

type References

type References struct {
	// contains filtered or unexported fields
}

func (*References) Copy

func (r *References) Copy() *References

type Snapshot

type Snapshot struct {
	Commited []byte

	SignatureLevel uint

	Refs *References
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL