Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Update extracting swarm hash #1270

Merged
merged 3 commits into from
Aug 28, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion remix-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/preset-es2015": "latest",
"@babel/preset-es2017": "latest",
"@babel/preset-stage-0": "^7.0.0",
"babel-eslint": "^10.0.0",
"babel-eslint": "^7.1.1",
"babelify": "^10.0.0",
"notify-error": "^1.2.0",
"solc": "^0.5.0",
Expand Down
2 changes: 1 addition & 1 deletion remix-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/preset-es2015": "latest",
"@babel/preset-es2017": "latest",
"@babel/preset-stage-0": "^7.0.0",
"babel-eslint": "^10.0.0",
"babel-eslint": "^7.1.1",
"babelify": "^10.0.0",
"standard": "^7.0.1",
"tape": "^4.6.0"
Expand Down
19 changes: 17 additions & 2 deletions remix-lib/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ module.exports = {
return /a165627a7a72305820([0-9a-f]{64})0029$/
},

/**
* return a regex which extract the swarmhash from the bytecode, from POC 0.3
*
* @return {RegEx}
*/
swarmHashExtractionPOC3: function () {
return /a265627a7a72315820([0-9a-f]{64})64736f6c6343([0-9a-f]{6})0032$/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't here 32 instead of 64?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no you are right, the problem was 31 instead of 30 , the hex of 0
/a265627a7a72305820([0-9a-f]{64})64736f6c6343([0-9a-f]{6})0032$/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore this the docs where outdated

},

extractSwarmHash: function (value) {
value = value.replace(this.swarmHashExtraction(), '')
value = value.replace(this.swarmHashExtractionPOC3(), '')
return value
},

/**
* Compare bytecode. return true if the code is equal (handle swarm hash and library references)
* @param {String} code1 - the bytecode that is actually deployed (contains resolved library reference and a potentially different swarmhash)
Expand All @@ -198,8 +213,8 @@ module.exports = {
code2 = replaceLibReference(code2, pos)
code1 = replaceLibReference(code1, pos)
}
code1 = code1.replace(this.swarmHashExtraction(), '')
code2 = code2.replace(this.swarmHashExtraction(), '')
code1 = this.extractSwarmHash(code1)
code2 = this.extractSwarmHash(code2)
if (code1 && code2 && code1.indexOf(code2) === 0) {
return true
}
Expand Down