From 85c9ecac51819b1d91453e89f3bce2828e8641e9 Mon Sep 17 00:00:00 2001 From: Harry Altman Date: Wed, 16 Dec 2020 13:43:15 -0500 Subject: [PATCH 1/3] Prevent ABI objects from being mutated --- packages/web3-eth-abi/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-eth-abi/src/index.js b/packages/web3-eth-abi/src/index.js index 31248bc7b0f..34801939265 100644 --- a/packages/web3-eth-abi/src/index.js +++ b/packages/web3-eth-abi/src/index.js @@ -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]; From 9019ebe8ff7cf6bf7d410ceb0c7fc5ea0b10a1a5 Mon Sep 17 00:00:00 2001 From: Harry Altman Date: Wed, 16 Dec 2020 14:05:39 -0500 Subject: [PATCH 2/3] Add test of ABI non-mutation --- test/abi.decodeParameter.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/abi.decodeParameter.js b/test/abi.decodeParameter.js index c98930b3191..e79fab2c927 100644 --- a/test/abi.decodeParameter.js +++ b/test/abi.decodeParameter.js @@ -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); + }); + }); +}); From 54f56b905b4ffe1cc723068867adfd18c2525704 Mon Sep 17 00:00:00 2001 From: Harry Altman Date: Wed, 16 Dec 2020 14:19:42 -0500 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f350308696..1f1d0fc68ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -310,3 +310,4 @@ Released with 1.0.0-beta.37 code base. - Fixed decoding bytes and string parameters for logs emitted with solc 0.4.x (#3724, #3738) - Grammar changes to inputAddressFormatter error message - Fixed vulnerable dependencies +- Fixed mutation of inputs to encoding and decoding functions (#3748)