Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ABI objects from being mutated #3818

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});
});