Skip to content

Commit

Permalink
Merge pull request ethereum#24 from OffchainLabs/stylus-header
Browse files Browse the repository at this point in the history
Update stylus header to 0xEFF000
  • Loading branch information
rachel-bousfield committed Aug 14, 2023
2 parents 187eff2 + 5185e75 commit a289b4c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions core/state/statedb_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,28 @@ var (
// with EVM contracts, but match against these prefix bytes when loading code
// to execute the WASMs through Stylus rather than the EVM.
stylusEOFMagic = byte(0xEF)
stylusEOFMagicSuffix = byte(0x00)
stylusEOFMagicSuffix = byte(0xF0)
stylusEOFVersion = byte(0x00)
stylusEOFSectionHeader = byte(0x00)

StylusPrefix = []byte{stylusEOFMagic, stylusEOFMagicSuffix, stylusEOFVersion, stylusEOFSectionHeader}
StylusPrefix = []byte{stylusEOFMagic, stylusEOFMagicSuffix, stylusEOFVersion}
)

// IsStylusProgram checks if a specified bytecode is a user-submitted WASM program.
// Stylus differentiates WASMs from EVM bytecode via the prefix 0xEF000000 which will safely fail
// Stylus differentiates WASMs from EVM bytecode via the prefix 0xEFF000 which will safely fail
// to pass through EVM-bytecode EOF validation rules.
func IsStylusProgram(b []byte) bool {
if len(b) < 4 {
if len(b) < 3 {
return false
}
return b[0] == stylusEOFMagic && b[1] == stylusEOFMagicSuffix && b[2] == stylusEOFVersion && b[3] == stylusEOFSectionHeader
return b[0] == stylusEOFMagic && b[1] == stylusEOFMagicSuffix && b[2] == stylusEOFVersion
}

// StripStylusPrefix if the specified input is a stylus program.
func StripStylusPrefix(b []byte) ([]byte, error) {
if !IsStylusProgram(b) {
return nil, errors.New("specified bytecode is not a Stylus program")
}
return b[4:], nil
return b[3:], nil
}

func (s *StateDB) GetCompiledWasmCode(addr common.Address, version uint32) []byte {
Expand Down

0 comments on commit a289b4c

Please sign in to comment.