Skip to content

Commit

Permalink
[EVM] Reject blob txs (#1498)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders authored and udpatil committed Apr 19, 2024
1 parent 66019cb commit 3a3d77a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 55 deletions.
30 changes: 15 additions & 15 deletions contracts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@openzeppelin/hardhat-upgrades": "^3.0.2",
"@openzeppelin/test-helpers": "^0.5.16",
"dotenv": "^16.3.1",
"ethers": "^6.9.0",
"ethers": "^6.11.1",
"hardhat": "^2.20.1"
},
"dependencies": {
Expand Down
24 changes: 24 additions & 0 deletions contracts/test/EVMCompatabilityTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function sendTx(sender, txn, responses) {
responses.push({nonce: txn.nonce, response: txResponse})
}


describe("EVM Test", function () {

describe("EVMCompatibilityTester", function () {
Expand Down Expand Up @@ -234,6 +235,29 @@ describe("EVM Test", function () {
expect(await evmTester.uint256Var()).to.equal(12345);
});

// this uses a newer version of ethers to attempt a blob transaction (different signer wallet)
it("should return an error for blobs", async function(){
const key = "0x57acb95d82739866a5c29e40b0aa2590742ae50425b7dd5b5d279a986370189e"
const signer = new ethers.Wallet(key, ethers.provider);
const blobData = "BLOB";
const blobDataBytes = ethers.toUtf8Bytes(blobData);
const blobHash = ethers.keccak256(blobDataBytes);

const tx = {
type: 3,
to: owner.address,
value: ethers.parseEther("0.1"),
data: '0x',
maxFeePerGas: ethers.parseUnits('100', 'gwei'),
maxPriorityFeePerGas: ethers.parseUnits('1', 'gwei'),
gasLimit: 100000,
maxFeePerBlobGas: ethers.parseUnits('10', 'gwei'),
blobVersionedHashes: [blobHash],
}

await expect(signer.sendTransaction(tx)).to.be.rejectedWith("unsupported transaction type");
})

it("Should trace a call with timestamp", async function () {
await delay()
const txResponse = await evmTester.setTimestamp();
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ require (
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
Expand Down Expand Up @@ -173,7 +172,6 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc=
github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -766,8 +765,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/guptarohit/asciigraph v0.5.5/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
Expand Down
39 changes: 22 additions & 17 deletions x/evm/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,31 @@ func (gl BasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, n
return ctx, sdkerrors.ErrOutOfGas
}

// Ensure blob transactions have valid commitments
if etx.Type() == ethtypes.BlobTxType {
sidecar := etx.BlobTxSidecar()
if sidecar == nil {
return ctx, fmt.Errorf("missing sidecar in blob transaction")
}
// Ensure the number of items in the blob transaction and various side
// data match up before doing any expensive validations
hashes := etx.BlobHashes()
if len(hashes) == 0 {
return ctx, fmt.Errorf("blobless blob transaction")
}
if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob {
return ctx, fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
}
if err := validateBlobSidecar(hashes, sidecar); err != nil {
return ctx, err
}
return ctx, sdkerrors.ErrUnsupportedTxType
}

//TODO: support blobs (leaving this commented out)
// Ensure blob transactions have valid commitments
//if etx.Type() == ethtypes.BlobTxType {
// sidecar := etx.BlobTxSidecar()
// if sidecar == nil {
// return ctx, fmt.Errorf("missing sidecar in blob transaction")
// }
// // Ensure the number of items in the blob transaction and various side
// // data match up before doing any expensive validations
// hashes := etx.BlobHashes()
// if len(hashes) == 0 {
// return ctx, fmt.Errorf("blobless blob transaction")
// }
// if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob {
// return ctx, fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
// }
// if err := validateBlobSidecar(hashes, sidecar); err != nil {
// return ctx, err
// }
//}

return next(ctx, tx, simulate)
}

Expand Down
18 changes: 1 addition & 17 deletions x/evm/ante/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,5 @@ func TestBasicDecorator(t *testing.T) {
return ctx, nil
})
require.NotNil(t, err)
require.Contains(t, err.Error(), "missing sidecar in blob transaction")

msg, _ = types.NewMsgEVMTransaction(&ethtx.BlobTx{GasLimit: 21000, Sidecar: &ethtx.BlobTxSidecar{}})
ctx, err = a.AnteHandle(ctx, &mockTx{msgs: []sdk.Msg{msg}}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
return ctx, nil
})
require.NotNil(t, err)
require.Contains(t, err.Error(), "blobless blob transaction")

msg, _ = types.NewMsgEVMTransaction(&ethtx.BlobTx{GasLimit: 21000, Sidecar: &ethtx.BlobTxSidecar{}, BlobHashes: [][]byte{
{}, {}, {}, {}, {}, {}, {},
}})
ctx, err = a.AnteHandle(ctx, &mockTx{msgs: []sdk.Msg{msg}}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
return ctx, nil
})
require.NotNil(t, err)
require.Contains(t, err.Error(), "too many blobs in transaction")
require.Error(t, err, sdkerrors.ErrUnsupportedTxType)
}

0 comments on commit 3a3d77a

Please sign in to comment.