Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4746 from trufflesuite/yul-immutables
Browse files Browse the repository at this point in the history
Allow non-numeric immutable keys in contract-schema and add test of Yul immutable recognition
  • Loading branch information
haltman-at authored Feb 17, 2022
2 parents 7b6017f + 5c49c1c commit d4c47a2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
33 changes: 15 additions & 18 deletions packages/contract-schema/spec/contract-object.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,23 @@
},
"ImmutableReferences": {
"type": "object",
"patternProperties": {
"[1-9][0-9]*": {
"type": "array",
"items": {
"type": "object",
"properties": {
"start": {
"type": "integer",
"minimum": 0
},
"length": {
"type": "integer",
"minimum": 0
}
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"start": {
"type": "integer",
"minimum": 0
},
"additionalProperties": false
}
"length": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"GeneratedSources": {
"type": "array",
Expand Down
51 changes: 50 additions & 1 deletion packages/debugger/test/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,37 @@ contract Created {
}
`;

const __YUL_IMMUTABLE = `
object "YulImmutableTest" {
code {
let size := datasize("runtime")
let offset := dataoffset("runtime")
setimmutable(offset, "secret", 1)
datacopy(0, offset, size)
return(0, size)
}
object "runtime" {
code {
mstore(
0,
xor(
loadimmutable("secret"),
linkersymbol("project:/contracts/ImmutableTest.sol:TestLibrary")
)
)
return(0, 0x20)
}
}
}
`;

const __MIGRATION = `
let OuterContract = artifacts.require("OuterContract");
let InnerContract = artifacts.require("InnerContract");
let ImmutableTest = artifacts.require("ImmutableTest");
let TestLibrary = artifacts.require("TestLibrary");
let CreationTest = artifacts.require("CreationTest");
let YulImmutableTest = artifacts.require("YulImmutableTest");
module.exports = async function(deployer) {
await deployer.deploy(InnerContract);
Expand All @@ -94,6 +119,8 @@ module.exports = async function(deployer) {
await deployer.link(TestLibrary, ImmutableTest);
await deployer.deploy(ImmutableTest);
await deployer.deploy(CreationTest);
await deployer.link(TestLibrary, YulImmutableTest);
await deployer.deploy(YulImmutableTest);
};
`;

Expand All @@ -105,7 +132,8 @@ let sources = {
"OuterLibrary.sol": __OUTER,
"InnerContract.sol": __INNER,
"ImmutableTest.sol": __IMMUTABLE,
"CreationTest.sol": __CREATION
"CreationTest.sol": __CREATION,
"YulImmutableTest.yul": __YUL_IMMUTABLE
};

describe("Contexts", function () {
Expand Down Expand Up @@ -199,6 +227,27 @@ describe("Contexts", function () {
assert.equal(affectedInstances[libraryAddress].contractName, "TestLibrary");
});

it("correctly identifies context in presence of linkersymbols and immutables (Yul)", async function () {
let ImmutableTest = await abstractions.YulImmutableTest.deployed();
let address = ImmutableTest.address;

let result = await ImmutableTest.sendTransaction({ data: "0x" });
let txHash = result.tx;

let bugger = await Debugger.forTx(txHash, {
provider,
compilations,
lightMode: true
});
debug("debugger ready");

let affectedInstances = bugger.view(sessionSelector.info.affectedInstances);
debug("affectedInstances: %o", affectedInstances);

assert.property(affectedInstances, address);
assert.equal(affectedInstances[address].contractName, "YulImmutableTest");
});

it("determines encoded constructor arguments for creations", async function () {
let CreationTest = await abstractions.CreationTest.deployed();
let address = CreationTest.address;
Expand Down
2 changes: 1 addition & 1 deletion packages/debugger/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function prepareContracts(provider, sources = {}, migrations) {

config.compilers = {
solc: {
version: "0.8.9",
version: "0.8.12",
settings: {
optimizer: { enabled: false, runs: 200 },
evmVersion: "london"
Expand Down

0 comments on commit d4c47a2

Please sign in to comment.