Skip to content
Business logic Audit finding Intermediate

Missing Validation for Fixed-Size bytes Types in ABI Parsing

The ABI type parser in Erigon did not enforce the Solidity specification limit that fixed-size bytes types must be between 1 and 32 bytes. An attacker could supply an invalid type such as bytes64, which the parser would accept, potentially causing incorrect ABI handling.

CertiK Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#37186 [BC-Insight] Missing Validation for Fixed-Size bytes Types in ABI Parsing

Submitted on Nov 27th 2024 at 22:43:54 UTC by @CertiK for Attackathon | Ethereum Protocol

  • Report ID: #37186
  • Report Type: Blockchain/DLT
  • Report severity: Insight
  • Target: https://github.com/ledgerwatch/erigon
  • Impacts:
    • (Specifications) A bug in specifications with no direct impact on client implementations

Description

Brief/Intro

In the NewType function within type.go, there is a lack of validation for the size of fixed-length bytes types.

Vulnerability Details

According to the argument encoding for the solidity, the bytes should limited to 32 bytes:
https://docs.soliditylang.org/en/v0.8.23/abi-spec.html

| bytes: binary type of M bytes, 0 < M <= 32.

However, such limitation is missing in the accounts/abi/type.go:

   case "bytes":
       if varSize == 0 {
           typ.T = BytesTy
       } else {
           typ.T = FixedBytesTy
           typ.Size = varSize
       }

Also, it should be noted the validation has been added in Geth: https://github.com/ethereum/go-ethereum/pull/26075

Impact Details

Without validation, the code might accept invalid bytes types with sizes outside the allowed range and break the spec.

References

Proof of Concept

Proof of Concept

func TestNewFixedBytesOver32(t *testing.T) {
   _, err := NewType("bytes64", "", nil)
   if err == nil {
       t.Errorf("fixed bytes with size over 32 is mistakenly allowed")
   }
}
--- FAIL: TestNewFixedBytesOver32 (0.00s)
   /Users/xxx/erigon/accounts/abi/type_test.go:376: fixed bytes with size over 32 is mistakenly allowed
FAIL
FAIL    github.com/erigontech/erigon/accounts/abi   0.321s
FAIL

The original report as published on Immunefi, by CertiK. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, the NewType function in accounts/abi/type.go lacked a check that the size of a fixed-size bytes type is between 1 and 32, as required by the Solidity ABI specification.

What the attacker needed

Ability to supply ABI type definitions to Erigon

The fix

The parser should reject fixed-size bytes types whose size is not between 1 and 32, as was done in Geth.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Solidity, the language for Ethereum smart contracts, defines a fixed-size byte type that can only be 1 to 32 bytes long. The Erigon client's code that reads these type definitions did not check the size limit, so it would accept a type like bytes64 even though that is not allowed. This could lead to unexpected behaviour when processing contract data.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by CertiK

View all

20 more disclosed reports, best first.

More from Ethereum Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.