Skip to content

Commit

Permalink
Merge pull request #3818 from haltman-at/no-mutate
Browse files Browse the repository at this point in the history
Prevent ABI objects from being mutated
  • Loading branch information
GregTheGreek authored Jan 5, 2021
2 parents 4469516 + fd717ba commit e02374e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,4 @@ Released with 1.0.0-beta.37 code base.
### Changed

- Remove `notImplemented` flag from ETH2 Beacon Chain package methods schema
- Fixed mutation of inputs to encoding and decoding functions (#3748)
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ABICoder.prototype.mapTypes = function (types) {
// recognize former type. Solidity docs say `Function` is a bytes24
// encoding the contract address followed by the function selector hash.
if (typeof type === 'object' && type.type === 'function'){
type.type = "bytes24";
type = Object.assign({}, type, { type: "bytes24" });
}
if (self.isSimplifiedStructFormat(type)) {
var structName = Object.keys(type)[0];
Expand Down
15 changes: 15 additions & 0 deletions test/abi.decodeParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,18 @@ describe('lib/solidity/coder', function () {
'737472696e670000000000000000000000000000000000000000000000000000'})
});
});

describe('/lib/solidity/coder', function() {
describe('decodeParam', function () {
it('should not alter inputs', function () {
const t = {
type: "function",
name: "f",
internalType: "function () external"
};
const copyOfT = Object.assign({}, t);
coder.decodeParameter(t, '063e4f349a9e91c6575aedab0e70087fab642ecac04062260000000000000000'); //must not alter t!
assert.deepEqual(t, copyOfT);
});
});
});

0 comments on commit e02374e

Please sign in to comment.