Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/features/gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var StaticInstructionLimit = FeatureGate{Name: "StaticInstructionLimit", Address
var PoseidonEnforcePadding = FeatureGate{Name: "PoseidonEnforcePadding", Address: base58.MustDecodeFromString("poUdAqRXXsNmfqAZ6UqpjbeYgwBygbfQLEvWSqVhSnb")}
var FixAltBn128PairingLengthCheck = FeatureGate{Name: "FixAltBn128PairingLengthCheck", Address: base58.MustDecodeFromString("bnYzodLwmybj7e1HAe98yZrdJTd7we69eMMLgCXqKZm")}
var DeprecateRentExemptionThreshold = FeatureGate{Name: "DeprecateRentExemptionThreshold", Address: base58.MustDecodeFromString("rent6iVy6PDoViPBeJ6k5EJQrkj62h7DPyLbWGHwjrC")}
var ProvideInstructionDataOffsetInVmR2 = FeatureGate{Name: "ProvideInstructionDataOffsetInVmR2", Address: base58.MustDecodeFromString("5xXZc66h4UdB6Yq7FzdBxBiRAFMMScMLwHxk2QZDaNZL")}

var AllFeatureGates = []FeatureGate{StopTruncatingStringsInSyscalls, EnablePartitionedEpochReward, EnablePartitionedEpochRewardsSuperfeature,
LastRestartSlotSysvar, Libsecp256k1FailOnBadCount, Libsecp256k1FailOnBadCount2, EnableBpfLoaderSetAuthorityCheckedIx,
Expand All @@ -79,4 +80,5 @@ var AllFeatureGates = []FeatureGate{StopTruncatingStringsInSyscalls, EnableParti
ReserveMinimalCUsForBuiltinInstructions, MaskOutRentEpochInVmSerialization, RemoveAccountsExecutableFlagChecks,
AccountsLtHash, RemoveAccountsDeltaHash, EnableLoaderV4, EnableSbpfV1DeploymentAndExecution, EnableSbpfV2DeploymentAndExecution,
EnableSbpfV3DeploymentAndExecution, DisableSbpfV0Execution, ReenableSbpfV0Execution, FormalizeLoadedTransactionDataSize, IncreaseCpiAccountInfoLimit,
StaticInstructionLimit, PoseidonEnforcePadding, FixAltBn128PairingLengthCheck, DeprecateRentExemptionThreshold}
StaticInstructionLimit, PoseidonEnforcePadding, FixAltBn128PairingLengthCheck, DeprecateRentExemptionThreshold,
ProvideInstructionDataOffsetInVmR2}
5 changes: 4 additions & 1 deletion pkg/sbpf/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type Interpreter struct {
ro []byte
stack Stack
heap []byte
input []byte
input []byte
inputDataVaddr uint64

entry uint64
heapSize uint64
Expand Down Expand Up @@ -85,6 +86,7 @@ func NewInterpreter(p *Program, opts *VMOpts) *Interpreter {
stack: NewStack(p.SbpfVersion),
heap: heap,
input: opts.Input,
inputDataVaddr: opts.InputDataVaddr,
entry: p.Entrypoint,
syscalls: opts.Syscalls,
funcs: p.Funcs,
Expand Down Expand Up @@ -113,6 +115,7 @@ func (ip *Interpreter) Finish() {
func (ip *Interpreter) Run() (ret uint64, cuConsumed uint64, err error) {
var r [11]uint64
r[1] = VaddrInput
r[2] = ip.inputDataVaddr

// initialise fp
var sz uint64
Expand Down
3 changes: 2 additions & 1 deletion pkg/sbpf/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type VMOpts struct {
Context any // passed to syscalls
MaxCU int
ComputeMeter *cu.ComputeMeter
Input []byte // mapped at VaddrInput
Input []byte // mapped at VaddrInput
InputDataVaddr uint64 // VM address of instruction data within Input (SIMD-0321)

// Debug
ProgramId solana.PublicKey
Expand Down
57 changes: 33 additions & 24 deletions pkg/sealevel/bpf_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,21 @@ type serializedAcctMetadata struct {
vmOwnerAddr uint64
}

func serializeParametersAligned(execCtx *ExecutionCtx) ([]byte, []uint64, error) {
func serializeParametersAligned(execCtx *ExecutionCtx) ([]byte, []uint64, uint64, error) {
txCtx := execCtx.TransactionContext
instrCtx, err := txCtx.CurrentInstructionCtx()
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}

numIxAccts := instrCtx.NumberOfInstructionAccounts()
if numIxAccts > MaxInstructionAccounts {
return nil, nil, InstrErrMaxAccountsExceeded
return nil, nil, 0, InstrErrMaxAccountsExceeded
}

programAcct, err := instrCtx.BorrowLastProgramAccount(txCtx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}
programId := programAcct.Key()
programAcct.Drop()
Expand All @@ -495,14 +495,14 @@ func serializeParametersAligned(execCtx *ExecutionCtx) ([]byte, []uint64, error)
for instrAcctIdx := uint64(0); instrAcctIdx < instrCtx.NumberOfInstructionAccounts(); instrAcctIdx++ {
isDupe, idxInCallee, err := instrCtx.IsInstructionAccountDuplicate(instrAcctIdx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}
if isDupe {
accts[int(instrAcctIdx)] = serializeAcct{isDuplicate: true, indexOfAcct: idxInCallee}
} else {
acct, err := instrCtx.BorrowInstructionAccount(txCtx, instrAcctIdx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}

accts[int(instrAcctIdx)] = serializeAcct{indexOfAcct: instrAcctIdx, acct: acct}
Expand Down Expand Up @@ -623,6 +623,7 @@ func serializeParametersAligned(execCtx *ExecutionCtx) ([]byte, []uint64, error)
}

l := len(serializedData)
instructionDataOffset := uint64(l) + 8 // offset of actual instruction data bytes (past length prefix)
serializedData = serializedData[:len(serializedData)+
8+ /*instr data len*/
len(instrData)+ /*instr data*/
Expand All @@ -637,7 +638,7 @@ func serializeParametersAligned(execCtx *ExecutionCtx) ([]byte, []uint64, error)
panic(fmt.Sprintf("mismatch between serialized data and expected length: len(serializedData) = %d, expected size = %d", uint64(len(serializedData)), size))
}

return serializedData, preLens, nil
return serializedData, preLens, instructionDataOffset, nil
}

func deserializeParametersAligned(execCtx *ExecutionCtx, parameterBytes []byte, preLens []uint64) error {
Expand Down Expand Up @@ -747,21 +748,21 @@ func deserializeParametersAligned(execCtx *ExecutionCtx, parameterBytes []byte,
return nil
}

func serializeParametersUnaligned(execCtx *ExecutionCtx) ([]byte, []uint64, error) {
func serializeParametersUnaligned(execCtx *ExecutionCtx) ([]byte, []uint64, uint64, error) {
txCtx := execCtx.TransactionContext
instrCtx, err := txCtx.CurrentInstructionCtx()
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}

numIxAccts := instrCtx.NumberOfInstructionAccounts()
if numIxAccts > MaxInstructionAccounts {
return nil, nil, InstrErrMaxAccountsExceeded
return nil, nil, 0, InstrErrMaxAccountsExceeded
}

programAcct, err := instrCtx.BorrowLastProgramAccount(txCtx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}
programId := programAcct.Key()
programAcct.Drop()
Expand All @@ -773,15 +774,15 @@ func serializeParametersUnaligned(execCtx *ExecutionCtx) ([]byte, []uint64, erro
for instrAcctIdx := uint64(0); instrAcctIdx < instrCtx.NumberOfInstructionAccounts(); instrAcctIdx++ {
isDupe, idxInCallee, err := instrCtx.IsInstructionAccountDuplicate(instrAcctIdx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}
if isDupe {
sa := serializeAcct{isDuplicate: true, indexOfAcct: idxInCallee}
accts = append(accts, sa)
} else {
acct, err := instrCtx.BorrowInstructionAccount(txCtx, instrAcctIdx)
if err != nil {
return nil, nil, err
return nil, nil, 0, err
}
defer acct.Drop()

Expand Down Expand Up @@ -882,6 +883,7 @@ func serializeParametersUnaligned(execCtx *ExecutionCtx) ([]byte, []uint64, erro
}

// instr data len
instructionDataOffset := uint64(len(serializedData)) + 8 // offset of actual instruction data bytes (past length prefix)
serializedData = binary.LittleEndian.AppendUint64(serializedData, uint64(len(instrData)))

// instr data
Expand All @@ -896,7 +898,7 @@ func serializeParametersUnaligned(execCtx *ExecutionCtx) ([]byte, []uint64, erro
panic("mismatch between serialized data and expected length")
}

return serializedData, preLens, nil
return serializedData, preLens, instructionDataOffset, nil
}

func deserializeParametersUnaligned(execCtx *ExecutionCtx, parameterBytes []byte, preLens []uint64) error {
Expand Down Expand Up @@ -1001,28 +1003,35 @@ func executeLoadedProgram(execCtx *ExecutionCtx, program *sbpf.Program, syscallR

var parameterBytes []byte
var preLens []uint64
var instrDataOffset uint64

if isLoaderDeprecated {
parameterBytes, preLens, err = serializeParametersUnaligned(execCtx)
parameterBytes, preLens, instrDataOffset, err = serializeParametersUnaligned(execCtx)
if err != nil {
return err
}
} else {
parameterBytes, preLens, err = serializeParametersAligned(execCtx)
parameterBytes, preLens, instrDataOffset, err = serializeParametersAligned(execCtx)
if err != nil {
return err
}
}

var inputDataVaddr uint64
if execCtx.Features.IsActive(features.ProvideInstructionDataOffsetInVmR2) {
inputDataVaddr = sbpf.VaddrInput + instrDataOffset
}

opts := &sbpf.VMOpts{
HeapMax: int(heapSize),
Input: parameterBytes,
Syscalls: syscallRegistry,
MaxCU: int(execCtx.ComputeMeter.Remaining()),
ComputeMeter: &execCtx.ComputeMeter,
Context: execCtx,
TxSignature: execCtx.TransactionContext.Signature,
ProgramId: programId,
HeapMax: int(heapSize),
Input: parameterBytes,
InputDataVaddr: inputDataVaddr,
Syscalls: syscallRegistry,
MaxCU: int(execCtx.ComputeMeter.Remaining()),
ComputeMeter: &execCtx.ComputeMeter,
Context: execCtx,
TxSignature: execCtx.TransactionContext.Signature,
ProgramId: programId,
}

start := time.Now()
Expand Down